2005-03-26 21:01:59 +00:00
/*
2005-09-14 20:46:50 +00:00
* Asterisk - - An open source telephony toolkit .
1999-12-04 20:45:45 +00:00
*
2008-01-28 14:27:28 +00:00
* Copyright ( C ) 1999 - 2008 , Digium , Inc .
1999-12-04 20:45:45 +00:00
*
2004-07-17 02:25:53 +00:00
* Mark Spencer < markster @ digium . com >
1999-12-04 20:45:45 +00:00
*
2005-09-14 20:46:50 +00:00
* See http : //www.asterisk.org for more information about
* the Asterisk project . Please do not directly contact
* any of the maintainers of this project for assistance ;
* the project provides a web site , mailing lists and IRC
* channels for your use .
*
1999-12-04 20:45:45 +00:00
* This program is free software , distributed under the terms of
2011-07-08 01:26:01 +00:00
* the GNU General Public License Version 2. See the LICENSE file
2005-09-14 20:46:50 +00:00
* at the top of the source tree .
*/
2005-10-24 20:12:06 +00:00
/*! \file
2005-09-14 20:46:50 +00:00
*
2005-10-24 20:12:06 +00:00
* \ brief Core PBX routines .
2005-12-30 21:18:06 +00:00
*
2006-05-09 08:03:52 +00:00
* \ author Mark Spencer < markster @ digium . com >
1999-12-04 20:45:45 +00:00
*/
2012-06-15 16:20:16 +00:00
/*** MODULEINFO
< support_level > core < / support_level >
* * */
2006-06-07 18:54:56 +00:00
# include "asterisk.h"
2007-11-20 22:18:21 +00:00
# include "asterisk/_private.h"
2007-11-20 23:16:15 +00:00
# include "asterisk/paths.h" /* use ast_config_AST_SYSTEM_NAME */
2005-04-22 13:11:34 +00:00
# include <ctype.h>
# include <time.h>
# include <sys/time.h>
2007-08-01 19:37:59 +00:00
# if defined(HAVE_SYSINFO)
2007-04-11 19:11:32 +00:00
# include <sys/sysinfo.h>
2007-04-11 20:59:08 +00:00
# endif
2007-09-12 16:24:45 +00:00
# if defined(SOLARIS)
# include <sys/loadavg.h>
# endif
2005-04-22 13:11:34 +00:00
2005-04-21 06:02:45 +00:00
# include "asterisk/lock.h"
# include "asterisk/cli.h"
# include "asterisk/pbx.h"
# include "asterisk/channel.h"
# include "asterisk/file.h"
# include "asterisk/callerid.h"
# include "asterisk/cdr.h"
# include "asterisk/config.h"
# include "asterisk/term.h"
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
# include "asterisk/time.h"
2005-04-21 06:02:45 +00:00
# include "asterisk/manager.h"
# include "asterisk/ast_expr.h"
# include "asterisk/linkedlists.h"
2006-03-23 14:28:16 +00:00
# define SAY_STUBS /* generate declarations and stubs for say methods */
2005-04-21 06:02:45 +00:00
# include "asterisk/say.h"
# include "asterisk/utils.h"
# include "asterisk/causes.h"
# include "asterisk/musiconhold.h"
# include "asterisk/app.h"
2005-07-08 21:14:34 +00:00
# include "asterisk/devicestate.h"
2012-06-04 20:26:12 +00:00
# include "asterisk/presencestate.h"
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
# include "asterisk/hashtab.h"
2007-07-16 14:39:29 +00:00
# include "asterisk/module.h"
2007-11-01 23:26:35 +00:00
# include "asterisk/indications.h"
2008-05-03 04:12:54 +00:00
# include "asterisk/taskprocessor.h"
2008-11-10 13:53:23 +00:00
# include "asterisk/xmldoc.h"
2010-11-30 09:49:25 +00:00
# include "asterisk/astobj2.h"
2013-04-08 14:26:37 +00:00
# include "asterisk/stasis_channels.h"
2013-05-18 19:47:24 +00:00
# include "asterisk/dial.h"
2015-04-29 19:49:23 +00:00
# include "asterisk/vector.h"
2015-12-29 01:18:01 +00:00
# include "pbx_private.h"
1999-12-04 20:45:45 +00:00
2005-10-26 13:03:17 +00:00
/*!
* \ note I M P O R T A N T :
1999-12-04 20:45:45 +00:00
*
* The speed of extension handling will likely be among the most important
* aspects of this PBX . The switching scheme as it exists right now isn ' t
* terribly bad ( it ' s O ( N + M ) , where N is the # of extensions and M is the avg #
2006-05-09 08:03:52 +00:00
* of priorities , but a constant search time here would be great ; - )
1999-12-04 20:45:45 +00:00
*
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* 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
2009-03-11 00:28:28 +00:00
* 10000 patterns .
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
*
* Also , using a hash table for context / priority name lookup can help prevent
2009-03-11 00:28:28 +00:00
* 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
2008-04-01 20:02:19 +00:00
* speed in small dialplans , they are worth the trouble in large dialplans .
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
*
1999-12-04 20:45:45 +00:00
*/
2008-11-01 21:10:07 +00:00
/*** DOCUMENTATION
< function name = " EXCEPTION " language = " en_US " >
< synopsis >
Retrieve the details of the current dialplan exception .
< / synopsis >
< syntax >
< parameter name = " field " required = " true " >
< para > The following fields are available for retrieval : < / para >
< enumlist >
< enum name = " reason " >
< para > INVALID , ERROR , RESPONSETIMEOUT , ABSOLUTETIMEOUT , or custom
value set by the RaiseException ( ) application < / para >
< / enum >
< enum name = " context " >
< para > The context executing when the exception occurred . < / para >
< / enum >
< enum name = " exten " >
< para > The extension executing when the exception occurred . < / para >
< / enum >
< enum name = " priority " >
< para > The numeric priority executing when the exception occurred . < / para >
< / enum >
< / enumlist >
< / parameter >
< / syntax >
< description >
< para > Retrieve the details ( specified < replaceable > field < / replaceable > ) of the current dialplan exception . < / para >
< / description >
2008-11-05 14:37:07 +00:00
< see - also >
< ref type = " application " > RaiseException < / ref >
< / see - also >
2008-11-01 21:10:07 +00:00
< / function >
2010-01-13 21:27:34 +00:00
< function name = " TESTTIME " language = " en_US " >
< synopsis >
Sets a time to be used with the channel to test logical conditions .
2010-01-13 23:22:56 +00:00
< / synopsis >
2010-01-13 21:27:34 +00:00
< syntax >
< parameter name = " date " required = " true " argsep = " " >
< para > Date in ISO 8601 format < / para >
< / parameter >
< parameter name = " time " required = " true " argsep = " " >
< para > Time in HH : MM : SS format ( 24 - hour time ) < / para >
< / parameter >
< parameter name = " zone " required = " false " >
< para > Timezone name < / para >
< / parameter >
< / syntax >
< description >
< para > To test dialplan timing conditions at times other than the current time , use
this function to set an alternate date and time . For example , you may wish to evaluate
whether a location will correctly identify to callers that the area is closed on Christmas
Day , when Christmas would otherwise fall on a day when the office is normally open . < / para >
2010-01-13 23:21:46 +00:00
< / description >
2010-01-13 21:27:34 +00:00
< see - also >
< ref type = " application " > GotoIfTime < / ref >
< / see - also >
< / function >
2009-05-22 17:52:35 +00:00
< manager name = " ShowDialPlan " language = " en_US " >
< synopsis >
2010-07-06 06:01:37 +00:00
Show dialplan contexts and extensions
2009-05-22 17:52:35 +00:00
< / synopsis >
< syntax >
< xi : include xpointer = " xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID']) " / >
< parameter name = " Extension " >
< para > Show a specific extension . < / para >
< / parameter >
< parameter name = " Context " >
< para > Show a specific context . < / para >
< / parameter >
< / syntax >
< description >
< para > Show dialplan contexts and extensions . Be aware that showing the full dialplan
may take a lot of capacity . < / para >
< / description >
< / manager >
2014-07-30 18:32:25 +00:00
< manager name = " ExtensionStateList " language = " en_US " >
< synopsis >
List the current known extension states .
< / synopsis >
< syntax >
< xi : include xpointer = " xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID']) " / >
< / syntax >
< description >
< para > This will list out all known extension states in a
sequence of < replaceable > ExtensionStatus < / replaceable > events .
When finished , a < replaceable > ExtensionStateListComplete < / replaceable > event
will be emitted . < / para >
< / description >
< see - also >
< ref type = " manager " > ExtensionState < / ref >
< ref type = " function " > HINT < / ref >
< ref type = " function " > EXTENSION_STATE < / ref >
< / see - also >
< responses >
< list - elements >
< xi : include xpointer = " xpointer(/docs/managerEvent[@name='ExtensionStatus']) " / >
< / list - elements >
< managerEvent name = " ExtensionStateListComplete " language = " en_US " >
< managerEventInstance class = " EVENT_FLAG_COMMAND " >
< synopsis >
Indicates the end of the list the current known extension states .
< / synopsis >
< syntax >
< parameter name = " EventList " >
< para > Conveys the status of the event list . < / para >
< / parameter >
< parameter name = " ListItems " >
< para > Conveys the number of statuses reported . < / para >
< / parameter >
< / syntax >
< / managerEventInstance >
< / managerEvent >
< / responses >
< / manager >
2008-11-01 21:10:07 +00:00
* * */
2004-06-12 14:34:15 +00:00
# ifdef LOW_MEMORY
# define EXT_DATA_SIZE 256
# else
# define EXT_DATA_SIZE 8192
# endif
1999-12-04 20:45:45 +00:00
2005-01-13 05:14:56 +00:00
# define SWITCH_DATA_LENGTH 256
2004-11-01 02:23:28 +00:00
# define VAR_NORMAL 1
# define VAR_SOFTTRAN 2
# define VAR_HARDTRAN 3
1999-12-04 20:45:45 +00:00
struct ast_context ;
2006-09-28 22:49:55 +00:00
struct ast_app ;
1999-12-04 20:45:45 +00:00
2008-03-10 21:48:20 +00:00
AST_THREADSTORAGE ( switch_data ) ;
2008-11-25 17:44:30 +00:00
AST_THREADSTORAGE ( extensionstate_buf ) ;
2008-03-10 21:48:20 +00:00
2005-12-24 06:23:36 +00:00
/*!
2006-05-09 08:03:52 +00:00
\ brief ast_exten : An extension
2005-11-14 19:00:38 +00:00
The dialplan is saved as a linked list with each context
having it ' s own linked list of extensions - one item per
priority .
*/
1999-12-04 20:45:45 +00:00
struct ast_exten {
2016-07-28 19:10:04 +00:00
char * exten ; /*!< Clean Extension id */
char * name ; /*!< Extension name (may include '-' eye candy) */
2005-12-24 06:23:36 +00:00
int matchcid ; /*!< Match caller id ? */
2006-01-21 23:05:19 +00:00
const char * cidmatch ; /*!< Caller id to match for this extension */
2016-07-28 19:10:04 +00:00
const char * cidmatch_display ; /*!< Caller id to match (display version) */
2005-12-24 06:23:36 +00:00
int priority ; /*!< Priority */
2006-01-21 23:05:19 +00:00
const char * label ; /*!< Label */
2005-12-24 06:23:36 +00:00
struct ast_context * parent ; /*!< The context this extension belongs to */
2009-03-11 00:28:28 +00:00
const char * app ; /*!< Application to execute */
2006-09-28 22:49:55 +00:00
struct ast_app * cached_app ; /*!< Cached location of application */
2005-12-24 06:23:36 +00:00
void * data ; /*!< Data to use (arguments) */
void ( * datad ) ( void * ) ; /*!< Data destructor */
struct ast_exten * peer ; /*!< Next higher priority with our extension */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
struct ast_hashtab * peer_table ; /*!< Priorities list in hashtab form -- only on the head of the peer list */
struct ast_hashtab * peer_label_table ; /*!< labeled priorities in the peers -- only on the head of the peer list */
2005-12-24 06:23:36 +00:00
const char * registrar ; /*!< Registrar */
2016-12-19 21:03:52 +00:00
const char * registrar_file ; /*!< File name used to register extension */
int registrar_line ; /*!< Line number the extension was registered in text */
2005-12-24 06:23:36 +00:00
struct ast_exten * next ; /*!< Extension with a greater ID */
2004-10-03 04:19:59 +00:00
char stuff [ 0 ] ;
1999-12-04 20:45:45 +00:00
} ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
/*! \brief match_char: forms a syntax tree for quick matching of extension patterns */
struct match_char
{
int is_pattern ; /* the pattern started with '_' */
int deleted ; /* if this is set, then... don't return it */
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 ;
struct ast_exten * exten ; /* attached to last char of a pattern for exten */
2009-04-17 13:29:33 +00:00
char x [ 1 ] ; /* the pattern itself-- matches a single char */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} ;
struct scoreboard /* make sure all fields are 0 before calling new_find_extension */
{
int total_specificity ;
int total_length ;
char last_char ; /* set to ! or . if they are the end of the pattern */
int canmatch ; /* if the string to match was just too short */
2007-11-19 22:55:38 +00:00
struct match_char * node ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
struct ast_exten * canmatch_exten ;
struct ast_exten * exten ;
} ;
2016-03-28 16:31:29 +00:00
/*! \brief ast_context: An extension context - must remain in sync with fake_context */
1999-12-04 20:45:45 +00:00
struct ast_context {
2009-03-11 00:28:28 +00:00
ast_rwlock_t lock ; /*!< A lock to prevent multiple threads from clobbering the context */
2005-11-14 19:00:38 +00:00
struct ast_exten * root ; /*!< The root of the list of extensions */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
struct ast_hashtab * root_table ; /*!< For exact matches on the extensions in the pattern tree, and for traversals of the pattern_tree */
2009-03-11 00:28:28 +00:00
struct match_char * pattern_tree ; /*!< A tree to speed up extension pattern matching */
2005-11-14 19:00:38 +00:00
struct ast_context * next ; /*!< Link them together */
2016-07-14 18:51:42 +00:00
struct ast_includes includes ; /*!< Include other contexts */
2016-07-15 07:59:48 +00:00
struct ast_ignorepats ignorepats ; /*!< Patterns for which to continue playing dialtone */
2016-07-16 00:28:16 +00:00
struct ast_sws alts ; /*!< Alternative switches */
2008-07-11 22:03:19 +00:00
char * registrar ; /*!< Registrar -- make sure you malloc this, as the registrar may have to survive module unloads */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
int refcount ; /*!< each module that would have created this context should inc/dec this as appropriate */
2016-03-28 16:31:29 +00:00
int autohints ; /*!< Whether autohints support is enabled or not */
2006-08-14 03:24:06 +00:00
ast_mutex_t macrolock ; /*!< A lock to implement "exclusive" macros - held whilst a call is executing in the macro */
2005-11-14 19:00:38 +00:00
char name [ 0 ] ; /*!< Name of the context */
1999-12-04 20:45:45 +00:00
} ;
2005-11-14 19:00:38 +00:00
/*! \brief ast_state_cb: An extension state notify register item */
2003-04-06 18:19:51 +00:00
struct ast_state_cb {
2011-12-23 02:35:13 +00:00
/*! Watcher ID returned when registered. */
2005-03-26 21:01:59 +00:00
int id ;
2011-12-23 02:35:13 +00:00
/*! Arbitrary data passed for callbacks. */
2005-03-26 21:01:59 +00:00
void * data ;
2012-08-09 14:52:16 +00:00
/*! Flag if this callback is an extended callback containing detailed device status */
int extended ;
2011-12-23 02:35:13 +00:00
/*! Callback when state changes. */
ast_state_cb_type change_cb ;
/*! Callback when destroyed so any resources given by the registerer can be freed. */
ast_state_cb_destroy_type destroy_cb ;
2011-07-08 01:26:01 +00:00
/*! \note Only used by ast_merge_contexts_and_delete */
2008-03-19 04:32:13 +00:00
AST_LIST_ENTRY ( ast_state_cb ) entry ;
2003-03-30 22:55:42 +00:00
} ;
2006-05-09 08:03:52 +00:00
2011-07-08 01:26:01 +00:00
/*!
* \ brief Structure for dial plan hints
*
* \ note Hints are pointers from an extension in the dialplan to
* one or more devices ( tech / name )
*
* See \ ref AstExtState
*/
2003-04-06 18:19:51 +00:00
struct ast_hint {
2011-07-22 20:46:36 +00:00
/*!
* \ brief Hint extension
*
* \ note
* Will never be NULL while the hint is in the hints container .
*/
struct ast_exten * exten ;
2012-06-04 20:26:12 +00:00
struct ao2_container * callbacks ; /*!< Device state callback container for this extension */
/*! Dev state variables */
int laststate ; /*!< Last known device state */
/*! Presence state variables */
int last_presence_state ; /*!< Last known presence state */
char * last_presence_subtype ; /*!< Last known presence subtype string */
char * last_presence_message ; /*!< Last known presence message string */
2011-07-22 20:46:36 +00:00
char context_name [ AST_MAX_CONTEXT ] ; /*!< Context of destroyed hint extension. */
char exten_name [ AST_MAX_EXTENSION ] ; /*!< Extension of destroyed hint extension. */
2003-03-30 22:55:42 +00:00
2015-04-29 19:49:23 +00:00
AST_VECTOR ( , char * ) devices ; /*!< Devices associated with the hint */
} ;
2010-11-30 09:49:25 +00:00
2016-01-08 22:59:44 +00:00
STASIS_MESSAGE_TYPE_DEFN_LOCAL ( hint_change_message_type ) ;
2010-11-30 09:49:25 +00:00
# define HINTDEVICE_DATA_LENGTH 16
AST_THREADSTORAGE ( hintdevice_data ) ;
/* --- Hash tables of various objects --------*/
# ifdef LOW_MEMORY
2011-12-23 02:35:13 +00:00
# define HASH_EXTENHINT_SIZE 17
2010-11-30 09:49:25 +00:00
# else
2011-12-23 02:35:13 +00:00
# define HASH_EXTENHINT_SIZE 563
2010-11-30 09:49:25 +00:00
# endif
2011-07-22 20:46:36 +00:00
/*! \brief Container for hint devices */
2010-11-30 09:49:25 +00:00
static struct ao2_container * hintdevices ;
2011-07-22 20:46:36 +00:00
/*!
* \ brief Structure for dial plan hint devices
* \ note hintdevice is one device pointing to a hint .
*/
2010-11-30 09:49:25 +00:00
struct ast_hintdevice {
2011-07-22 20:46:36 +00:00
/*!
* \ brief Hint this hintdevice belongs to .
* \ note Holds a reference to the hint object .
*/
2010-11-30 09:49:25 +00:00
struct ast_hint * hint ;
2011-07-22 20:46:36 +00:00
/*! Name of the hint device. */
2010-11-30 09:49:25 +00:00
char hintdevice [ 1 ] ;
} ;
2016-03-28 16:31:29 +00:00
/*! \brief Container for autohint contexts */
static struct ao2_container * autohints ;
/*!
* \ brief Structure for dial plan autohints
*/
struct ast_autohint {
/*! \brief Name of the registrar */
char * registrar ;
/*! \brief Name of the context */
char context [ 1 ] ;
} ;
2010-11-30 09:49:25 +00:00
/*!
* \ note Using the device for hash
*/
static int hintdevice_hash_cb ( const void * obj , const int flags )
{
2015-04-29 19:49:23 +00:00
const struct ast_hintdevice * ext ;
const char * key ;
2010-11-30 09:49:25 +00:00
2015-04-29 19:49:23 +00:00
switch ( flags & OBJ_SEARCH_MASK ) {
case OBJ_SEARCH_KEY :
key = obj ;
break ;
case OBJ_SEARCH_OBJECT :
ext = obj ;
key = ext - > hintdevice ;
break ;
default :
ast_assert ( 0 ) ;
return 0 ;
}
return ast_str_case_hash ( key ) ;
2010-11-30 09:49:25 +00:00
}
2016-03-28 16:31:29 +00:00
2010-11-30 09:49:25 +00:00
/*!
* \ note Devices on hints are not unique so no CMP_STOP is returned
2011-07-22 20:46:36 +00:00
* Dont use ao2_find against hintdevices container cause there always
2010-11-30 09:49:25 +00:00
* could be more than one result .
*/
static int hintdevice_cmp_multiple ( void * obj , void * arg , int flags )
{
2015-04-29 19:49:23 +00:00
struct ast_hintdevice * left = obj ;
struct ast_hintdevice * right = arg ;
const char * right_key = arg ;
int cmp ;
2010-11-30 09:49:25 +00:00
2015-04-29 19:49:23 +00:00
switch ( flags & OBJ_SEARCH_MASK ) {
case OBJ_SEARCH_OBJECT :
right_key = right - > hintdevice ;
/* Fall through */
case OBJ_SEARCH_KEY :
2015-06-27 01:38:58 +00:00
cmp = strcasecmp ( left - > hintdevice , right_key ) ;
2015-04-29 19:49:23 +00:00
break ;
case OBJ_SEARCH_PARTIAL_KEY :
/*
* We could also use a partial key struct containing a length
* so strlen ( ) does not get called for every comparison instead .
*/
cmp = strncmp ( left - > hintdevice , right_key , strlen ( right_key ) ) ;
break ;
default :
ast_assert ( 0 ) ;
cmp = 0 ;
break ;
}
return cmp ? 0 : CMP_MATCH ;
2010-11-30 09:49:25 +00:00
}
2016-03-28 16:31:29 +00:00
/*!
* \ note Using the context name for hash
*/
static int autohint_hash_cb ( const void * obj , const int flags )
{
const struct ast_autohint * autohint ;
const char * key ;
switch ( flags & OBJ_SEARCH_MASK ) {
case OBJ_SEARCH_KEY :
key = obj ;
break ;
case OBJ_SEARCH_OBJECT :
autohint = obj ;
key = autohint - > context ;
break ;
default :
ast_assert ( 0 ) ;
return 0 ;
}
return ast_str_case_hash ( key ) ;
}
static int autohint_cmp ( void * obj , void * arg , int flags )
{
struct ast_autohint * left = obj ;
struct ast_autohint * right = arg ;
const char * right_key = arg ;
int cmp ;
switch ( flags & OBJ_SEARCH_MASK ) {
case OBJ_SEARCH_OBJECT :
right_key = right - > context ;
/* Fall through */
case OBJ_SEARCH_KEY :
cmp = strcasecmp ( left - > context , right_key ) ;
break ;
case OBJ_SEARCH_PARTIAL_KEY :
/*
* We could also use a partial key struct containing a length
* so strlen ( ) does not get called for every comparison instead .
*/
cmp = strncmp ( left - > context , right_key , strlen ( right_key ) ) ;
break ;
default :
ast_assert ( 0 ) ;
cmp = 0 ;
break ;
}
return cmp ? 0 : CMP_MATCH | CMP_STOP ;
}
2015-04-29 19:49:23 +00:00
/*! \internal \brief \c ao2_callback function to remove hintdevices */
static int hintdevice_remove_cb ( void * obj , void * arg , void * data , int flags )
2010-11-30 09:49:25 +00:00
{
2015-04-29 19:49:23 +00:00
struct ast_hintdevice * candidate = obj ;
char * device = arg ;
struct ast_hint * hint = data ;
2010-11-30 09:49:25 +00:00
2015-06-27 01:38:58 +00:00
if ( ! strcasecmp ( candidate - > hintdevice , device )
2015-04-29 19:49:23 +00:00
& & candidate - > hint = = hint ) {
return CMP_MATCH ;
}
return 0 ;
2010-11-30 09:49:25 +00:00
}
static int remove_hintdevice ( struct ast_hint * hint )
{
2015-04-29 19:49:23 +00:00
while ( AST_VECTOR_SIZE ( & hint - > devices ) > 0 ) {
char * device = AST_VECTOR_GET ( & hint - > devices , 0 ) ;
ao2_t_callback_data ( hintdevices , OBJ_SEARCH_KEY | OBJ_UNLINK | OBJ_NODATA ,
hintdevice_remove_cb , device , hint , " Remove device from container " ) ;
AST_VECTOR_REMOVE_UNORDERED ( & hint - > devices , 0 ) ;
ast_free ( device ) ;
}
2010-11-30 09:49:25 +00:00
return 0 ;
}
2012-06-04 20:26:12 +00:00
static char * parse_hint_device ( struct ast_str * hint_args ) ;
2011-07-22 20:46:36 +00:00
/*!
* \ internal
* \ brief Destroy the given hintdevice object .
*
* \ param obj Hint device to destroy .
*
* \ return Nothing
*/
static void hintdevice_destroy ( void * obj )
{
struct ast_hintdevice * doomed = obj ;
if ( doomed - > hint ) {
ao2_ref ( doomed - > hint , - 1 ) ;
doomed - > hint = NULL ;
}
}
2010-11-30 09:49:25 +00:00
/*! \brief add hintdevice structure and link it into the container.
*/
static int add_hintdevice ( struct ast_hint * hint , const char * devicelist )
{
struct ast_str * str ;
2011-07-22 20:46:36 +00:00
char * parse ;
char * cur ;
2010-11-30 09:49:25 +00:00
struct ast_hintdevice * device ;
2011-07-22 20:46:36 +00:00
int devicelength ;
2010-11-30 09:49:25 +00:00
2011-07-22 20:46:36 +00:00
if ( ! hint | | ! devicelist ) {
/* Trying to add garbage? Don't bother. */
return 0 ;
}
2010-11-30 09:49:25 +00:00
if ( ! ( str = ast_str_thread_get ( & hintdevice_data , 16 ) ) ) {
return - 1 ;
}
ast_str_set ( & str , 0 , " %s " , devicelist ) ;
2014-12-22 14:33:24 +00:00
parse = ast_str_buffer ( str ) ;
2010-11-30 09:49:25 +00:00
2014-12-22 14:33:24 +00:00
/* Spit on '&' and ',' to handle presence hints as well */
while ( ( cur = strsep ( & parse , " &, " ) ) ) {
2015-04-29 19:49:23 +00:00
char * device_name ;
2010-11-30 09:49:25 +00:00
devicelength = strlen ( cur ) ;
2014-12-22 14:33:24 +00:00
if ( ! devicelength ) {
continue ;
}
2015-04-29 19:49:23 +00:00
device_name = ast_strdup ( cur ) ;
if ( ! device_name ) {
return - 1 ;
}
2011-07-22 20:46:36 +00:00
device = ao2_t_alloc ( sizeof ( * device ) + devicelength , hintdevice_destroy ,
" allocating a hintdevice structure " ) ;
if ( ! device ) {
2015-04-29 19:49:23 +00:00
ast_free ( device_name ) ;
2010-11-30 09:49:25 +00:00
return - 1 ;
}
strcpy ( device - > hintdevice , cur ) ;
2011-07-22 20:46:36 +00:00
ao2_ref ( hint , + 1 ) ;
2010-11-30 09:49:25 +00:00
device - > hint = hint ;
2015-04-29 19:49:23 +00:00
if ( AST_VECTOR_APPEND ( & hint - > devices , device_name ) ) {
ast_free ( device_name ) ;
ao2_ref ( device , - 1 ) ;
return - 1 ;
}
2010-11-30 09:49:25 +00:00
ao2_t_link ( hintdevices , device , " Linking device into hintdevice container. " ) ;
ao2_t_ref ( device , - 1 , " hintdevice is linked so we can unref " ) ;
}
return 0 ;
}
2006-03-17 21:39:36 +00:00
static const struct cfextension_states {
int extension_state ;
const char * const text ;
} extension_states [ ] = {
{ AST_EXTENSION_NOT_INUSE , " Idle " } ,
{ AST_EXTENSION_INUSE , " InUse " } ,
{ AST_EXTENSION_BUSY , " Busy " } ,
{ AST_EXTENSION_UNAVAILABLE , " Unavailable " } ,
{ AST_EXTENSION_RINGING , " Ringing " } ,
2006-07-08 02:24:07 +00:00
{ AST_EXTENSION_INUSE | AST_EXTENSION_RINGING , " InUse&Ringing " } ,
{ AST_EXTENSION_ONHOLD , " Hold " } ,
{ AST_EXTENSION_INUSE | AST_EXTENSION_ONHOLD , " InUse&Hold " }
2006-03-17 21:39:36 +00:00
} ;
2007-10-03 22:14:09 +00:00
struct pbx_exception {
AST_DECLARE_STRING_FIELDS (
AST_STRING_FIELD ( context ) ; /*!< Context associated with this exception */
AST_STRING_FIELD ( exten ) ; /*!< Exten associated with this exception */
2007-11-01 00:04:43 +00:00
AST_STRING_FIELD ( reason ) ; /*!< The exception reason */
2007-10-03 22:14:09 +00:00
) ;
int priority ; /*!< Priority associated with this exception */
} ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
static int matchcid ( const char * cidpattern , const char * callerid ) ;
2009-05-22 16:10:33 +00:00
# ifdef NEED_DEBUG
2009-05-22 13:34:01 +00:00
static void log_match_char_tree ( struct match_char * node , char * prefix ) ; /* for use anywhere */
2009-05-22 16:10:33 +00:00
# endif
2009-03-11 00:28:28 +00:00
static void new_find_extension ( const char * str , struct scoreboard * score ,
struct match_char * tree , int length , int spec , const char * callerid ,
2008-11-26 22:01:34 +00:00
const char * label , enum ext_match_t action ) ;
2009-04-17 13:29:33 +00:00
static struct match_char * already_in_tree ( struct match_char * current , char * pat , int is_pattern ) ;
2009-03-11 00:28:28 +00:00
static struct match_char * add_exten_to_pattern_tree ( struct ast_context * con ,
2008-11-26 22:11:55 +00:00
struct ast_exten * e1 , int findonly ) ;
2007-11-21 15:29:39 +00:00
static void create_match_char_tree ( struct ast_context * con ) ;
static struct ast_exten * get_canmatch_exten ( struct match_char * node ) ;
static void destroy_pattern_tree ( struct match_char * pattern_tree ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
static int hashtab_compare_extens ( const void * ha_a , const void * ah_b ) ;
static int hashtab_compare_exten_numbers ( const void * ah_a , const void * ah_b ) ;
static int hashtab_compare_exten_labels ( const void * ah_a , const void * ah_b ) ;
static unsigned int hashtab_hash_extens ( const void * obj ) ;
static unsigned int hashtab_hash_priority ( const void * obj ) ;
static unsigned int hashtab_hash_labels ( const void * obj ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
static void __ast_internal_context_destroy ( struct ast_context * con ) ;
2009-02-18 15:35:26 +00:00
static int ast_add_extension_nolock ( const char * context , int replace , const char * extension ,
int priority , const char * label , const char * callerid ,
const char * application , void * data , void ( * datad ) ( void * ) , const char * registrar ) ;
static int ast_add_extension2_lockopt ( struct ast_context * con ,
int replace , const char * extension , int priority , const char * label , const char * callerid ,
const char * application , void * data , void ( * datad ) ( void * ) ,
2016-12-19 21:03:52 +00:00
const char * registrar , const char * registrar_file , int registrar_line ,
int lock_context ) ;
2011-07-08 01:26:01 +00:00
static struct ast_context * find_context_locked ( const char * context ) ;
static struct ast_context * find_context ( const char * context ) ;
2012-08-09 14:52:16 +00:00
static void get_device_state_causing_channels ( struct ao2_container * c ) ;
2017-03-14 21:16:23 +00:00
static unsigned int ext_strncpy ( char * dst , const char * src , size_t dst_size , int nofluff ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
2011-12-09 01:33:29 +00:00
/*!
* \ internal
* \ brief Character array comparison function for qsort .
*
* \ param a Left side object .
* \ param b Right side object .
*
* \ retval < 0 if a < b
* \ retval = 0 if a = b
* \ retval > 0 if a > b
*/
2008-04-01 20:02:19 +00:00
static int compare_char ( const void * a , const void * b )
{
2011-12-09 01:33:29 +00:00
const unsigned char * ac = a ;
const unsigned char * bc = b ;
return * ac - * bc ;
2008-04-01 20:02:19 +00:00
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
/* labels, contexts are case sensitive priority numbers are ints */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
int ast_hashtab_compare_contexts ( const void * ah_a , const void * ah_b )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
const struct ast_context * ac = ah_a ;
const struct ast_context * bc = ah_b ;
2008-07-23 22:03:48 +00:00
if ( ! ac | | ! bc ) /* safety valve, but it might prevent a crash you'd rather have happen */
return 1 ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
/* assume context names are registered in a string table! */
return strcmp ( ac - > name , bc - > name ) ;
}
static int hashtab_compare_extens ( const void * ah_a , const void * ah_b )
{
const struct ast_exten * ac = ah_a ;
const struct ast_exten * bc = ah_b ;
int x = strcmp ( ac - > exten , bc - > exten ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( x ) { /* if exten names are diff, then return */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return x ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
2009-03-11 00:28:28 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
/* but if they are the same, do the cidmatch values match? */
2013-10-25 20:51:13 +00:00
/* not sure which side may be using ast_ext_matchcid_types, so check both */
if ( ac - > matchcid = = AST_EXT_MATCHCID_ANY | | bc - > matchcid = = AST_EXT_MATCHCID_ANY ) {
return 0 ;
}
if ( ac - > matchcid = = AST_EXT_MATCHCID_OFF & & bc - > matchcid = = AST_EXT_MATCHCID_OFF ) {
return 0 ;
}
if ( ac - > matchcid ! = bc - > matchcid ) {
return 1 ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2013-10-25 20:51:13 +00:00
/* all other cases already disposed of, match now required on callerid string (cidmatch) */
/* although ast_add_extension2_lockopt() enforces non-zero ptr, caller may not have */
if ( ast_strlen_zero ( ac - > cidmatch ) & & ast_strlen_zero ( bc - > cidmatch ) ) {
return 0 ;
}
return strcmp ( ac - > cidmatch , bc - > cidmatch ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
static int hashtab_compare_exten_numbers ( const void * ah_a , const void * ah_b )
{
const struct ast_exten * ac = ah_a ;
const struct ast_exten * bc = ah_b ;
return ac - > priority ! = bc - > priority ;
}
static int hashtab_compare_exten_labels ( const void * ah_a , const void * ah_b )
{
const struct ast_exten * ac = ah_a ;
const struct ast_exten * bc = ah_b ;
2009-04-23 20:42:11 +00:00
return strcmp ( S_OR ( ac - > label , " " ) , S_OR ( bc - > label , " " ) ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
unsigned int ast_hashtab_hash_contexts ( const void * obj )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
const struct ast_context * ac = obj ;
return ast_hashtab_hash_string ( ac - > name ) ;
}
static unsigned int hashtab_hash_extens ( const void * obj )
{
const struct ast_exten * ac = obj ;
unsigned int x = ast_hashtab_hash_string ( ac - > exten ) ;
unsigned int y = 0 ;
2013-10-25 20:51:13 +00:00
if ( ac - > matchcid = = AST_EXT_MATCHCID_ON )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
y = ast_hashtab_hash_string ( ac - > cidmatch ) ;
return x + y ;
}
static unsigned int hashtab_hash_priority ( const void * obj )
{
const struct ast_exten * ac = obj ;
return ast_hashtab_hash_int ( ac - > priority ) ;
}
static unsigned int hashtab_hash_labels ( const void * obj )
{
const struct ast_exten * ac = obj ;
2009-04-23 20:42:11 +00:00
return ast_hashtab_hash_string ( S_OR ( ac - > label , " " ) ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2006-08-30 21:44:05 +00:00
static int autofallthrough = 1 ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
static int extenpatternmatchnew = 0 ;
2008-03-10 21:48:20 +00:00
static char * overrideswitch = NULL ;
2004-10-16 19:46:02 +00:00
Merge major changes to the way device state is passed around Asterisk. The two
places that cared about device states were app_queue and the hint code in pbx.c.
The changes include converting it to use the Asterisk event system, as well as
other efficiency improvements.
* app_queue: This module used to register a callback into devicestate.c to
monitor device state changes. Now, it is just a subscriber to Asterisk
events with the type, device state.
* pbx.c hints: Previously, the device state processing thread in devicestate.c
would call ast_hint_state_changed() each time the state of a device changed.
Then, that code would go looking for all the hints that monitor that device,
and call their callbacks. All of this blocked the device state processing
thread. Now, the hint code is a subscriber of Asterisk events with the
type, device state. Furthermore, when this code receives a device state
change event, it queues it up to be processed by another thread so that it
doesn't block one of the event processing threads.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@66958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-01 23:34:43 +00:00
/*! \brief Subscription for device state change events */
2013-04-16 15:33:59 +00:00
static struct stasis_subscription * device_state_sub ;
2012-06-04 20:26:12 +00:00
/*! \brief Subscription for presence state change events */
2013-04-16 15:48:16 +00:00
static struct stasis_subscription * presence_state_sub ;
Merge major changes to the way device state is passed around Asterisk. The two
places that cared about device states were app_queue and the hint code in pbx.c.
The changes include converting it to use the Asterisk event system, as well as
other efficiency improvements.
* app_queue: This module used to register a callback into devicestate.c to
monitor device state changes. Now, it is just a subscriber to Asterisk
events with the type, device state.
* pbx.c hints: Previously, the device state processing thread in devicestate.c
would call ast_hint_state_changed() each time the state of a device changed.
Then, that code would go looking for all the hints that monitor that device,
and call their callbacks. All of this blocked the device state processing
thread. Now, the hint code is a subscriber of Asterisk events with the
type, device state. Furthermore, when this code receives a device state
change event, it queues it up to be processed by another thread so that it
doesn't block one of the event processing threads.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@66958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-01 23:34:43 +00:00
2005-05-18 01:49:13 +00:00
AST_MUTEX_DEFINE_STATIC ( maxcalllock ) ;
2006-12-27 22:14:33 +00:00
static int countcalls ;
2007-12-07 16:11:05 +00:00
static int totalcalls ;
2005-05-18 01:49:13 +00:00
2006-12-27 22:14:33 +00:00
static struct ast_context * contexts ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
static struct ast_hashtab * contexts_table = NULL ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
2011-07-08 01:26:01 +00:00
/*!
* \ brief Lock for the ast_context list
* \ note
2010-08-05 07:47:30 +00:00
* This lock MUST be recursive , or a deadlock on reload may result . See
* https : //issues.asterisk.org/view.php?id=17643
*/
AST_MUTEX_DEFINE_STATIC ( conlock ) ;
2006-05-01 03:14:21 +00:00
2011-07-22 20:46:36 +00:00
/*!
* \ brief Lock to hold off restructuring of hints by ast_merge_contexts_and_delete .
*/
AST_MUTEX_DEFINE_STATIC ( context_merge_lock ) ;
2003-04-06 18:19:51 +00:00
static int stateid = 1 ;
2011-07-08 01:26:01 +00:00
/*!
* \ note When holding this container ' s lock , do _not_ do
* anything that will cause conlock to be taken , unless you
* _already_ hold it . The ast_merge_contexts_and_delete function
* will take the locks in conlock / hints order , so any other
* paths that require both locks must also take them in that
* order .
2010-11-30 09:49:25 +00:00
*/
static struct ao2_container * hints ;
2008-03-19 04:32:13 +00:00
2011-01-18 20:40:59 +00:00
static struct ao2_container * statecbs ;
2003-03-30 22:55:42 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
# ifdef CONTEXT_DEBUG
/* these routines are provided for doing run-time checks
on the extension structures , in case you are having
problems , this routine might help you localize where
the problem is occurring . It ' s kinda like a debug memory
allocator ' s arena checker . . . It ' ll eat up your cpu cycles !
but you ' ll see , if you call it in the right places ,
right where your problems began . . .
*/
/* you can break on the check_contexts_trouble()
routine in your debugger to stop at the moment
there ' s a problem */
void check_contexts_trouble ( void ) ;
void check_contexts_trouble ( void )
{
int x = 1 ;
x = 2 ;
}
int check_contexts ( char * , int ) ;
int check_contexts ( char * file , int line )
{
struct ast_hashtab_iter * t1 ;
struct ast_context * c1 , * c2 ;
int found = 0 ;
struct ast_exten * e1 , * e2 , * e3 ;
struct ast_exten ex ;
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
/* try to find inconsistencies */
/* is every context in the context table in the context list and vice-versa ? */
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( ! contexts_table ) {
ast_log ( LOG_NOTICE , " Called from: %s:%d: No contexts_table! \n " , file , line ) ;
usleep ( 500000 ) ;
}
t1 = ast_hashtab_start_traversal ( contexts_table ) ;
while ( ( c1 = ast_hashtab_next ( t1 ) ) ) {
for ( c2 = contexts ; c2 ; c2 = c2 - > next ) {
if ( ! strcmp ( c1 - > name , c2 - > name ) ) {
found = 1 ;
break ;
}
}
if ( ! found ) {
ast_log ( LOG_NOTICE , " Called from: %s:%d: Could not find the %s context in the linked list \n " , file , line , c1 - > name ) ;
check_contexts_trouble ( ) ;
}
}
ast_hashtab_end_traversal ( t1 ) ;
for ( c2 = contexts ; c2 ; c2 = c2 - > next ) {
c1 = find_context_locked ( c2 - > name ) ;
if ( ! c1 ) {
2008-07-23 22:03:48 +00:00
ast_log ( LOG_NOTICE , " Called from: %s:%d: Could not find the %s context in the hashtab \n " , file , line , c2 - > name ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
check_contexts_trouble ( ) ;
} else
ast_unlock_contexts ( ) ;
}
2012-03-22 19:51:16 +00:00
/* loop thru all contexts, and verify the exten structure compares to the
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
hashtab structure */
for ( c2 = contexts ; c2 ; c2 = c2 - > next ) {
c1 = find_context_locked ( c2 - > name ) ;
2011-07-08 01:26:01 +00:00
if ( c1 ) {
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
ast_unlock_contexts ( ) ;
/* is every entry in the root list also in the root_table? */
for ( e1 = c1 - > root ; e1 ; e1 = e1 - > next )
{
char dummy_name [ 1024 ] ;
ex . exten = dummy_name ;
ex . matchcid = e1 - > matchcid ;
ex . cidmatch = e1 - > cidmatch ;
ast_copy_string ( dummy_name , e1 - > exten , sizeof ( dummy_name ) ) ;
e2 = ast_hashtab_lookup ( c1 - > root_table , & ex ) ;
if ( ! e2 ) {
2013-10-25 20:51:13 +00:00
if ( e1 - > matchcid = = AST_EXT_MATCHCID_ON ) {
2016-07-28 19:10:04 +00:00
ast_log ( LOG_NOTICE , " Called from: %s:%d: The %s context records "
" the exten %s (CID match: %s) but it is not in its root_table \n " ,
file , line , c2 - > name , dummy_name , e1 - > cidmatch_display ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
} else {
2016-07-28 19:10:04 +00:00
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 , dummy_name ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
check_contexts_trouble ( ) ;
}
}
2009-03-11 00:28:28 +00:00
2012-03-22 19:51:16 +00:00
/* is every entry in the root_table also in the root list? */
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( ! c2 - > root_table ) {
if ( c2 - > root ) {
ast_log ( LOG_NOTICE , " Called from: %s:%d: No c2->root_table for context %s! \n " , file , line , c2 - > name ) ;
usleep ( 500000 ) ;
}
} else {
t1 = ast_hashtab_start_traversal ( c2 - > root_table ) ;
while ( ( e2 = ast_hashtab_next ( t1 ) ) ) {
for ( e1 = c2 - > root ; e1 ; e1 = e1 - > next ) {
if ( ! strcmp ( e1 - > exten , e2 - > exten ) ) {
found = 1 ;
break ;
}
}
if ( ! found ) {
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 ( ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
ast_hashtab_end_traversal ( t1 ) ;
}
}
/* is every priority reflected in the peer_table at the head of the list? */
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
/* 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 ) {
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
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 ( ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
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 ( ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
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 ( ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
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 ( ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
e3 = ast_hashtab_lookup ( e1 - > peer_table , & ex ) ;
if ( ! e3 ) {
ast_log ( LOG_NOTICE , " Called from: %s:%d: The %s context, %s exten, %d priority is not reflected in the peer_table \n " , file , line , c2 - > name , e1 - > exten , e2 - > priority ) ;
check_contexts_trouble ( ) ;
}
}
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( ! e1 - > peer_table ) {
ast_log ( LOG_NOTICE , " Called from: %s:%d: No e1->peer_table! \n " , file , line ) ;
usleep ( 500000 ) ;
}
2009-03-11 00:28:28 +00:00
/* is every entry in the peer_table also in the peer list? */
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
t1 = ast_hashtab_start_traversal ( e1 - > peer_table ) ;
while ( ( e2 = ast_hashtab_next ( t1 ) ) ) {
for ( e3 = e1 ; e3 ; e3 = e3 - > peer ) {
if ( e3 - > priority = = e2 - > priority ) {
found = 1 ;
break ;
}
}
if ( ! found ) {
ast_log ( LOG_NOTICE , " Called from: %s:%d: The %s context, %s exten, %d priority is not reflected in the peer list \n " , file , line , c2 - > name , e1 - > exten , e2 - > priority ) ;
check_contexts_trouble ( ) ;
}
}
ast_hashtab_end_traversal ( t1 ) ;
}
}
return 0 ;
}
# endif
1999-12-04 20:45:45 +00:00
static void pbx_destroy ( struct ast_pbx * p )
{
2007-06-06 21:20:11 +00:00
ast_free ( p ) ;
1999-12-04 20:45:45 +00:00
}
2009-03-11 00:28:28 +00:00
/* form a tree that fully describes all the patterns in a context's extensions
2008-04-01 20:02:19 +00:00
* in this tree , a " node " represents an individual character or character set
2009-03-11 00:28:28 +00:00
* meant to match the corresponding character in a dial string . The tree
2008-04-01 20:02:19 +00:00
* consists of a series of match_char structs linked in a chain
2009-03-11 00:28:28 +00:00
* 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 .
2008-04-01 20:02:19 +00:00
* 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
2009-03-11 00:28:28 +00:00
* the " best " match because it has fewer X ' s , and is therefore more specific ,
2008-04-01 20:02:19 +00:00
* but this is not how the old algorithm works . It sorts matching patterns
2009-03-11 00:28:28 +00:00
* in a similar collating sequence as sorting alphabetic strings , from left to
2008-04-01 20:02:19 +00:00
* 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
2009-03-11 00:28:28 +00:00
* as we encounter our first complete match , we automatically have the " best "
2008-04-01 20:02:19 +00:00
* 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 :
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* ( a ) NXXNXXXXXX
2009-03-11 00:28:28 +00:00
* ( b ) 307754 XXXX
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* ( c ) fax
* ( d ) NXXXXXXXXX
*
* In the above , between ( a ) and ( d ) , ( a ) is a more specific pattern than ( d ) , and would win over
* most numbers . For all numbers beginning with 307754 , ( b ) should always win .
*
2008-04-01 20:02:19 +00:00
* These pattern should form a ( sorted ) tree that looks like this :
* { " 3 " } - - next - - > { " 0 " } - - next - - > { " 7 " } - - next - - > { " 7 " } - - next - - > { " 5 " } . . . blah . . . - - > { " X " exten_match : ( b ) }
* |
* | alt
* |
* { " f " } - - next - - > { " a " } - - next - - > { " x " exten_match : ( c ) }
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* { " N " } - - next - - > { " X " } - - next - - > { " X " } - - next - - > { " N " } - - next - - > { " X " } . . . blah . . . - - > { " X " exten_match : ( a ) }
* | |
* | | alt
* | alt |
* | { " X " } - - next - - > { " X " } . . . blah . . . - - > { " X " exten_match : ( d ) }
* |
2008-04-01 20:02:19 +00:00
* NULL
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
*
* In the above , I could easily turn " N " into " 23456789 " , but I think that a quick " if( *z >= '2' && *z <= '9' ) " might take
2008-09-25 22:21:28 +00:00
* fewer CPU cycles than a call to strchr ( " 23456789 " , * z ) , where * z is the char to match . . .
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
*
2008-04-01 20:02:19 +00:00
* traversal is pretty simple : one routine merely traverses the alt list , and for each matching char in the pattern , it calls itself
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* on the corresponding next pointer , incrementing also the pointer of the string to be matched , and passing the total specificity and length .
* We pass a pointer to a scoreboard down through , also .
2008-04-01 20:02:19 +00:00
* The scoreboard isn ' t as necessary to the revised algorithm , but I kept it as a handy way to return the matched extension .
* The first complete match ends the traversal , which should make this version of the pattern matcher faster
* 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 .
2009-03-11 00:28:28 +00:00
* Hope the limit on stack depth won ' t be a problem . . . this routine should
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* be pretty lean as far a stack usage goes . Any non - match terminates the recursion down a branch .
*
2008-04-01 20:02:19 +00:00
* In the above example , with the number " 3077549999 " as the pattern , the traversor could match extensions a , b and d . All are
* of length 10 ; they have total specificities of 24580 , 10246 , and 25090 , respectively , not that this matters
* at all . ( b ) wins purely because the first character " 3 " is much more specific ( lower specificity ) than " N " . I have
* left the specificity totals in the code as an artifact ; at some point , I will strip it out .
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
*
2008-04-01 20:02:19 +00:00
* Just how much time this algorithm might save over a plain linear traversal over all possible patterns is unknown ,
* because it ' s a function of how many extensions are stored in a context . With thousands of extensions , the speedup
* can be very noticeable . The new matching algorithm can run several hundreds of times faster , if not a thousand or
* more times faster in extreme cases .
*
* MatchCID patterns are also supported , and stored in the tree just as the extension pattern is . Thus , you
* can have patterns in your CID field as well .
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
*
* */
2007-11-19 22:55:38 +00:00
static void update_scoreboard ( struct scoreboard * board , int length , int spec , struct ast_exten * exten , char last , const char * callerid , int deleted , struct match_char * node )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
2007-11-16 23:33:32 +00:00
/* if this extension is marked as deleted, then skip this -- if it never shows
2008-04-01 20:02:19 +00:00
on the scoreboard , it will never be found , nor will halt the traversal . */
2007-11-16 23:33:32 +00:00
if ( deleted )
return ;
2008-04-01 20:02:19 +00:00
board - > total_specificity = spec ;
board - > total_length = length ;
board - > exten = exten ;
board - > last_char = last ;
board - > node = node ;
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " Scoreboarding (LONGER) %s, len=%d, score=%d \n " , exten - > exten , length , spec ) ;
# endif
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2009-05-22 16:10:33 +00:00
# ifdef NEED_DEBUG
2009-05-22 13:34:01 +00:00
static void log_match_char_tree ( struct match_char * node , char * prefix )
2007-11-21 20:38:00 +00:00
{
char extenstr [ 40 ] ;
2009-03-11 00:28:28 +00:00
struct ast_str * my_prefix = ast_str_alloca ( 1024 ) ;
2008-01-28 14:27:28 +00:00
extenstr [ 0 ] = ' \0 ' ;
2009-04-17 13:29:33 +00:00
if ( node & & node - > exten )
2008-01-28 14:27:28 +00:00
snprintf ( extenstr , sizeof ( extenstr ) , " (%p) " , node - > exten ) ;
2009-03-11 00:28:28 +00:00
2008-01-28 14:27:28 +00:00
if ( strlen ( node - > x ) > 1 ) {
2009-03-11 00:28:28 +00:00
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: " : " " ,
2008-01-28 14:27:28 +00:00
node - > exten ? node - > exten - > exten : " " , extenstr ) ;
} else {
2009-03-11 00:28:28 +00:00
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: " : " " ,
2008-01-28 14:27:28 +00:00
node - > exten ? node - > exten - > exten : " " , extenstr ) ;
}
ast_str_set ( & my_prefix , 0 , " %s+ " , prefix ) ;
2007-11-21 20:38:00 +00:00
if ( node - > next_char )
2008-12-13 08:36:35 +00:00
log_match_char_tree ( node - > next_char , ast_str_buffer ( my_prefix ) ) ;
2008-01-28 14:27:28 +00:00
2007-11-21 20:38:00 +00:00
if ( node - > alt_char )
log_match_char_tree ( node - > alt_char , prefix ) ;
}
2009-05-22 16:10:33 +00:00
# endif
2007-11-21 20:38:00 +00:00
static void cli_match_char_tree ( struct match_char * node , char * prefix , int fd )
{
char extenstr [ 40 ] ;
2008-01-28 14:27:28 +00:00
struct ast_str * my_prefix = ast_str_alloca ( 1024 ) ;
2009-03-11 00:28:28 +00:00
2008-01-28 14:27:28 +00:00
extenstr [ 0 ] = ' \0 ' ;
Resolve FORWARD_NULL static analysis warnings
This resolves core findings from ASTERISK-19650 numbers 0-2, 6, 7, 9-11, 14-20,
22-24, 28, 30-32, 34-36, 42-56, 82-84, 87, 89-90, 93-102, 104, 105, 109-111,
and 115. Finding numbers 26, 33, and 29 were already resolved. Those skipped
were either extended/deprecated or in areas of code that shouldn't be
disturbed.
(Closes issue ASTERISK-19650)
........
Merged revisions 366167 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 366168 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-05-10 20:56:09 +00:00
if ( node - > exten ) {
2008-01-28 14:27:28 +00:00
snprintf ( extenstr , sizeof ( extenstr ) , " (%p) " , node - > exten ) ;
Resolve FORWARD_NULL static analysis warnings
This resolves core findings from ASTERISK-19650 numbers 0-2, 6, 7, 9-11, 14-20,
22-24, 28, 30-32, 34-36, 42-56, 82-84, 87, 89-90, 93-102, 104, 105, 109-111,
and 115. Finding numbers 26, 33, and 29 were already resolved. Those skipped
were either extended/deprecated or in areas of code that shouldn't be
disturbed.
(Closes issue ASTERISK-19650)
........
Merged revisions 366167 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 366168 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-05-10 20:56:09 +00:00
}
2009-03-11 00:28:28 +00:00
2008-01-28 14:27:28 +00:00
if ( strlen ( node - > x ) > 1 ) {
2009-03-11 00:28:28 +00:00
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: " : " " ,
2016-07-28 19:10:04 +00:00
node - > exten ? node - > exten - > name : " " , extenstr ) ;
2008-01-28 14:27:28 +00:00
} else {
2009-03-11 00:28:28 +00:00
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: " : " " ,
2016-07-28 19:10:04 +00:00
node - > exten ? node - > exten - > name : " " , extenstr ) ;
2008-01-28 14:27:28 +00:00
}
ast_str_set ( & my_prefix , 0 , " %s+ " , prefix ) ;
2007-11-21 20:38:00 +00:00
if ( node - > next_char )
2008-12-13 08:36:35 +00:00
cli_match_char_tree ( node - > next_char , ast_str_buffer ( my_prefix ) , fd ) ;
2008-01-28 14:27:28 +00:00
2007-11-21 20:38:00 +00:00
if ( node - > alt_char )
cli_match_char_tree ( node - > alt_char , prefix , fd ) ;
}
2007-11-21 15:29:39 +00:00
static struct ast_exten * get_canmatch_exten ( struct match_char * node )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
/* find the exten at the end of the rope */
struct match_char * node2 = node ;
2008-01-28 14:27:28 +00:00
for ( node2 = node ; node2 ; node2 = node2 - > next_char ) {
2008-04-01 20:02:19 +00:00
if ( node2 - > exten ) {
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " CanMatch_exten returns exten %s(%p) \n " , node2 - > exten - > exten , node2 - > exten ) ;
# endif
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return node2 - > exten ;
2008-04-01 20:02:19 +00:00
}
2008-01-28 14:27:28 +00:00
}
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " CanMatch_exten returns NULL, match_char=%s \n " , node - > x ) ;
# endif
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return 0 ;
}
2007-11-19 22:55:38 +00:00
static struct ast_exten * trie_find_next_match ( struct match_char * node )
{
struct match_char * m3 ;
struct match_char * m4 ;
struct ast_exten * e3 ;
2009-03-11 00:28:28 +00:00
if ( node & & node - > x [ 0 ] = = ' . ' & & ! node - > x [ 1 ] ) { /* dot and ! will ALWAYS be next match in a matchmore */
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
return node - > exten ;
2009-03-11 00:28:28 +00:00
}
if ( node & & node - > x [ 0 ] = = ' ! ' & & ! node - > x [ 1 ] ) {
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
return node - > exten ;
2009-03-11 00:28:28 +00:00
}
if ( ! node | | ! node - > next_char ) {
2007-11-19 22:55:38 +00:00
return NULL ;
2009-03-11 00:28:28 +00:00
}
2007-11-19 22:55:38 +00:00
m3 = node - > next_char ;
2009-03-11 00:28:28 +00:00
if ( m3 - > exten ) {
2007-11-19 22:55:38 +00:00
return m3 - > exten ;
2009-03-11 00:28:28 +00:00
}
for ( m4 = m3 - > alt_char ; m4 ; m4 = m4 - > alt_char ) {
if ( m4 - > exten ) {
2007-11-19 22:55:38 +00:00
return m4 - > exten ;
2009-03-11 00:28:28 +00:00
}
2007-11-19 22:55:38 +00:00
}
2009-03-11 00:28:28 +00:00
for ( m4 = m3 ; m4 ; m4 = m4 - > alt_char ) {
2007-11-19 22:55:38 +00:00
e3 = trie_find_next_match ( m3 ) ;
2009-03-11 00:28:28 +00:00
if ( e3 ) {
2007-11-19 22:55:38 +00:00
return e3 ;
2009-03-11 00:28:28 +00:00
}
2007-11-19 22:55:38 +00:00
}
2009-04-17 13:29:33 +00:00
2007-11-19 22:55:38 +00:00
return NULL ;
}
2008-04-15 19:59:50 +00:00
# ifdef DEBUG_THIS
static char * action2str ( enum ext_match_t action )
{
2009-03-11 00:28:28 +00:00
switch ( action ) {
2008-04-15 19:59:50 +00:00
case E_MATCH :
return " MATCH " ;
case E_CANMATCH :
return " CANMATCH " ;
case E_MATCHMORE :
return " MATCHMORE " ;
case E_FINDLABEL :
return " FINDLABEL " ;
case E_SPAWN :
return " SPAWN " ;
default :
return " ?ACTION? " ;
}
}
# endif
2009-06-10 20:00:45 +00:00
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 )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
struct match_char * p ; /* note minimal stack storage requirements */
2008-06-09 16:35:06 +00:00
struct ast_exten pattern = { . label = label } ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
# ifdef DEBUG_THIS
if ( tree )
2008-04-15 19:59:50 +00:00
ast_log ( LOG_NOTICE , " new_find_extension called with %s on (sub)tree %s action=%s \n " , str , tree - > x , action2str ( action ) ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
else
2008-04-15 19:59:50 +00:00
ast_log ( LOG_NOTICE , " new_find_extension called with %s on (sub)tree NULL action=%s \n " , str , action2str ( action ) ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
# endif
2009-03-11 00:28:28 +00:00
for ( p = tree ; p ; p = p - > alt_char ) {
2009-04-17 13:29:33 +00:00
if ( p - > is_pattern ) {
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 ( 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 ) ; \
if ( ! p - > deleted ) { \
if ( action = = E_FINDLABEL ) { \
if ( ast_hashtab_lookup ( score - > exten - > peer_label_table , & pattern ) ) { \
ast_debug ( 4 , " Found label in preferred extension \n " ) ; \
return ; \
} \
} else { \
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " returning an exact match-- first found-- %s \n " , p - > exten - > name ) ; \
2009-04-17 13:29:33 +00:00
return ; /* the first match, by definition, will be the best, because of the sorted tree */ \
} \
} \
} \
}
2011-02-04 16:55:39 +00:00
2009-04-17 13:29:33 +00:00
# define NEW_MATCHER_RECURSE \
if ( p - > next_char & & ( * ( str + 1 ) | | ( p - > next_char - > x [ 0 ] = = ' / ' & & p - > next_char - > x [ 1 ] = = 0 ) \
2011-02-04 16:55:39 +00:00
| | p - > next_char - > x [ 0 ] = = ' ! ' ) ) { \
2009-04-17 13:29:33 +00:00
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 ) { \
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " returning an exact match-- %s \n " , score - > exten - > name ) ; \
2009-04-17 13:29:33 +00:00
return ; /* the first match is all we need */ \
} \
} else { \
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 ) ) { \
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " returning a (can/more) match--- %s \n " , score - > exten ? score - > exten - > name : \
2011-02-04 16:55:39 +00:00
" NULL " ) ; \
2009-04-17 13:29:33 +00:00
return ; /* the first match is all we need */ \
} \
} \
2011-09-20 21:05:42 +00:00
} else if ( ( p - > next_char | | action = = E_CANMATCH ) & & ! * ( str + 1 ) ) { \
2009-04-17 13:29:33 +00:00
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 ) ; \
return ; \
} \
}
2011-02-04 16:55:39 +00:00
2009-04-17 13:29:33 +00:00
NEW_MATCHER_CHK_MATCH ;
NEW_MATCHER_RECURSE ;
2008-04-01 20:02:19 +00:00
}
2009-04-17 13:29:33 +00:00
} else if ( p - > x [ 0 ] = = ' Z ' ) {
if ( p - > x [ 1 ] = = 0 & & * str > = ' 1 ' & & * str < = ' 9 ' ) {
NEW_MATCHER_CHK_MATCH ;
NEW_MATCHER_RECURSE ;
2008-04-01 20:02:19 +00:00
}
2011-02-04 16:55:39 +00:00
} else if ( p - > x [ 0 ] = = ' X ' ) {
2009-04-17 13:29:33 +00:00
if ( p - > x [ 1 ] = = 0 & & * str > = ' 0 ' & & * str < = ' 9 ' ) {
NEW_MATCHER_CHK_MATCH ;
NEW_MATCHER_RECURSE ;
2008-04-15 19:59:50 +00:00
}
2009-04-17 13:29:33 +00:00
} else if ( p - > x [ 0 ] = = ' . ' & & p - > x [ 1 ] = = 0 ) {
/* how many chars will the . match against? */
int i = 0 ;
const char * str2 = str ;
while ( * str2 & & * str2 ! = ' / ' ) {
str2 + + ;
i + + ;
2008-04-15 19:59:50 +00:00
}
2009-04-17 13:29:33 +00:00
if ( p - > exten & & * str2 ! = ' / ' ) {
update_scoreboard ( score , length + i , spec + ( i * p - > specificity ) , p - > exten , ' . ' , callerid , p - > deleted , p ) ;
if ( score - > exten ) {
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " return because scoreboard has a match with '/'--- %s \n " ,
score - > exten - > name ) ;
2009-04-17 13:29:33 +00:00
return ; /* the first match is all we need */
}
2008-04-15 19:59:50 +00:00
}
2009-04-17 13:29:33 +00:00
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 ) ) {
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " return because scoreboard has exact match OR "
" CANMATCH/MATCHMORE & canmatch set--- %s \n " ,
score - > exten ? score - > exten - > name : " NULL " ) ;
2009-04-17 13:29:33 +00:00
return ; /* the first match is all we need */
}
2008-04-15 19:59:50 +00:00
}
2009-04-17 13:29:33 +00:00
} else if ( p - > x [ 0 ] = = ' ! ' & & p - > x [ 1 ] = = 0 ) {
/* how many chars will the . match against? */
int i = 1 ;
const char * str2 = str ;
while ( * str2 & & * str2 ! = ' / ' ) {
str2 + + ;
i + + ;
}
if ( p - > exten & & * str2 ! = ' / ' ) {
update_scoreboard ( score , length + 1 , spec + ( p - > specificity * i ) , p - > exten , ' ! ' , callerid , p - > deleted , p ) ;
if ( score - > exten ) {
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " return because scoreboard has a '!' match--- %s \n " ,
score - > exten - > name ) ;
2009-04-17 13:29:33 +00:00
return ; /* the first match is all we need */
}
2008-04-15 19:59:50 +00:00
}
2009-04-17 13:29:33 +00:00
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 ) ) {
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " return because scoreboard has exact match OR "
" CANMATCH/MATCHMORE & canmatch set with '/' and '!'--- %s \n " ,
score - > exten ? score - > exten - > name : " NULL " ) ;
2009-04-17 13:29:33 +00:00
return ; /* the first match is all we need */
}
}
} else if ( p - > x [ 0 ] = = ' / ' & & p - > x [ 1 ] = = 0 ) {
/* the pattern in the tree includes the cid match! */
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 ) ) {
2016-07-28 19:10:04 +00:00
ast_debug ( 4 , " return because scoreboard has exact match OR "
" CANMATCH/MATCHMORE & canmatch set with '/'--- %s \n " ,
score - > exten ? score - > exten - > name : " NULL " ) ;
2009-04-17 13:29:33 +00:00
return ; /* the first match is all we need */
}
}
} else if ( strchr ( p - > x , * str ) ) {
ast_debug ( 4 , " Nothing strange about this match \n " ) ;
NEW_MATCHER_CHK_MATCH ;
NEW_MATCHER_RECURSE ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2008-09-25 22:21:28 +00:00
} else if ( strchr ( p - > x , * str ) ) {
2008-06-09 16:35:06 +00:00
ast_debug ( 4 , " Nothing strange about this match \n " ) ;
2008-04-01 20:02:19 +00:00
NEW_MATCHER_CHK_MATCH ;
NEW_MATCHER_RECURSE ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
}
2009-03-11 00:28:28 +00:00
ast_debug ( 4 , " return at end of func \n " ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2009-03-11 00:28:28 +00:00
/* the algorithm for forming the extension pattern tree is also a bit simple; you
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* 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
2008-04-01 20:02:19 +00:00
* spot . What more can I say ? At the end of each exten , you cap it off by adding the
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* address of the extension involved . Duplicate patterns will be complained about .
*
2009-03-11 00:28:28 +00:00
* Ideally , this would be done for each context after it is created and fully
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* 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 .
*
2008-04-01 20:02:19 +00:00
* I guess forming this pattern tree would be analogous to compiling a regex . Except
* that a regex only handles 1 pattern , really . This trie holds any number
2008-04-15 19:59:50 +00:00
* of patterns . Well , really , it * * could * * be considered a single pattern ,
* where the " | " ( or ) operator is allowed , I guess , in a way , sort of . . .
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
*/
2009-04-17 13:29:33 +00:00
static struct match_char * already_in_tree ( struct match_char * current , char * pat , int is_pattern )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
struct match_char * t ;
2008-03-19 04:14:12 +00:00
2009-03-11 00:28:28 +00:00
if ( ! current ) {
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return 0 ;
2009-03-11 00:28:28 +00:00
}
2008-03-19 04:14:12 +00:00
for ( t = current ; t ; t = t - > alt_char ) {
2009-04-17 13:29:33 +00:00
if ( is_pattern = = t - > is_pattern & & ! strcmp ( pat , t - > x ) ) { /* uh, we may want to sort exploded [] contents to make matching easy */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return t ;
2009-03-11 00:28:28 +00:00
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2008-03-19 04:14:12 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return 0 ;
}
2009-03-11 00:28:28 +00:00
/* The first arg is the location of the tree ptr, or the
2008-04-01 20:02:19 +00:00
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 ;
2009-03-11 00:28:28 +00:00
2008-04-01 20:02:19 +00:00
/* 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 ;
2009-04-17 13:29:33 +00:00
return ;
}
2009-04-17 14:33:50 +00:00
if ( ( * parent_ptr ) - > specificity > node - > specificity ) {
2009-04-17 13:29:33 +00:00
/* insert at head */
node - > alt_char = ( * parent_ptr ) ;
* parent_ptr = node ;
return ;
2012-03-22 19:51:16 +00:00
}
2009-04-17 13:29:33 +00:00
lcurr = * parent_ptr ;
for ( curr = ( * parent_ptr ) - > alt_char ; curr ; curr = curr - > alt_char ) {
if ( curr - > specificity > node - > specificity ) {
node - > alt_char = curr ;
lcurr - > alt_char = node ;
break ;
2008-04-01 20:02:19 +00:00
}
2009-04-17 13:29:33 +00:00
lcurr = curr ;
2008-04-01 20:02:19 +00:00
}
2009-04-17 13:29:33 +00:00
if ( ! curr ) {
lcurr - > alt_char = node ;
}
2008-04-01 20:02:19 +00:00
2009-04-17 13:29:33 +00:00
}
2008-04-01 20:02:19 +00:00
2011-12-09 01:33:29 +00:00
struct pattern_node {
/*! Pattern node specificity */
int specif ;
/*! Pattern node match characters. */
char buf [ 256 ] ;
} ;
static struct match_char * add_pattern_node ( struct ast_context * con , struct match_char * current , const struct pattern_node * pattern , int is_pattern , int already , struct match_char * * nextcharptr )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
2008-03-19 04:14:12 +00:00
struct match_char * m ;
2011-12-09 01:33:29 +00:00
if ( ! ( m = ast_calloc ( 1 , sizeof ( * m ) + strlen ( pattern - > buf ) ) ) ) {
2008-03-19 04:14:12 +00:00
return NULL ;
2009-03-11 00:28:28 +00:00
}
2008-03-19 04:14:12 +00:00
2009-04-17 13:29:33 +00:00
/* strcpy is safe here since we know its size and have allocated
* just enough space for when we allocated m
*/
2011-12-09 01:33:29 +00:00
strcpy ( m - > x , pattern - > buf ) ;
2008-03-19 04:14:12 +00:00
2008-04-01 20:02:19 +00:00
/* the specificity scores are the same as used in the old
pattern matcher . */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
m - > is_pattern = is_pattern ;
2011-12-09 01:33:29 +00:00
if ( pattern - > specif = = 1 & & is_pattern & & pattern - > buf [ 0 ] = = ' N ' ) {
2010-09-09 18:53:09 +00:00
m - > specificity = 0x0832 ;
2011-12-09 01:33:29 +00:00
} else if ( pattern - > specif = = 1 & & is_pattern & & pattern - > buf [ 0 ] = = ' Z ' ) {
2010-09-09 18:53:09 +00:00
m - > specificity = 0x0931 ;
2011-12-09 01:33:29 +00:00
} else if ( pattern - > specif = = 1 & & is_pattern & & pattern - > buf [ 0 ] = = ' X ' ) {
2010-09-09 18:53:09 +00:00
m - > specificity = 0x0a30 ;
2011-12-09 01:33:29 +00:00
} else if ( pattern - > specif = = 1 & & is_pattern & & pattern - > buf [ 0 ] = = ' . ' ) {
2010-09-09 18:53:09 +00:00
m - > specificity = 0x18000 ;
2011-12-09 01:33:29 +00:00
} else if ( pattern - > specif = = 1 & & is_pattern & & pattern - > buf [ 0 ] = = ' ! ' ) {
2010-09-09 18:53:09 +00:00
m - > specificity = 0x28000 ;
2011-12-09 01:33:29 +00:00
} else {
m - > specificity = pattern - > specif ;
}
2009-03-11 00:28:28 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
if ( ! con - > pattern_tree ) {
2008-04-01 20:02:19 +00:00
insert_in_next_chars_alt_char_list ( & con - > pattern_tree , m ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else {
if ( already ) { /* switch to the new regime (traversing vs appending)*/
2008-04-01 20:02:19 +00:00
insert_in_next_chars_alt_char_list ( nextcharptr , m ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else {
2008-04-01 20:02:19 +00:00
insert_in_next_chars_alt_char_list ( & current - > next_char , m ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
}
2008-03-19 04:14:12 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return m ;
}
2011-12-09 01:33:29 +00:00
/*!
* \ internal
* \ brief Extract the next exten pattern node .
*
* \ param node Pattern node to fill .
* \ param src Next source character to read .
* \ param pattern TRUE if the exten is a pattern .
* \ param extenbuf Original exten buffer to use in diagnostic messages .
*
* \ retval Ptr to next extenbuf pos to read .
*/
static const char * get_pattern_node ( struct pattern_node * node , const char * src , int pattern , const char * extenbuf )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
2011-12-09 01:33:29 +00:00
# define INC_DST_OVERFLOW_CHECK \
do { \
if ( dst - node - > buf < sizeof ( node - > buf ) - 1 ) { \
+ + dst ; \
} else { \
overflow = 1 ; \
} \
} while ( 0 )
node - > specif = 0 ;
node - > buf [ 0 ] = ' \0 ' ;
while ( * src ) {
if ( * src = = ' [ ' & & pattern ) {
char * dst = node - > buf ;
const char * src_next ;
int length ;
int overflow = 0 ;
/* get past the '[' */
+ + src ;
for ( ; ; ) {
if ( * src = = ' \\ ' ) {
/* Escaped character. */
+ + src ;
if ( * src = = ' [ ' | | * src = = ' \\ ' | | * src = = ' - ' | | * src = = ' ] ' ) {
* dst = * src + + ;
INC_DST_OVERFLOW_CHECK ;
}
} else if ( * src = = ' - ' ) {
unsigned char first ;
unsigned char last ;
2009-02-18 06:00:40 +00:00
2011-12-09 01:33:29 +00:00
src_next = src ;
first = * ( src_next - 1 ) ;
last = * + + src_next ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
2011-12-09 01:33:29 +00:00
if ( last = = ' \\ ' ) {
/* Escaped character. */
last = * + + src_next ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2011-12-09 01:33:29 +00:00
/* Possible char range. */
if ( node - > buf [ 0 ] & & last ) {
/* Expand the char range. */
while ( + + first < = last ) {
* dst = first ;
INC_DST_OVERFLOW_CHECK ;
}
src = src_next + 1 ;
} else {
/*
* There was no left or right char for the range .
* It is just a ' - ' .
*/
* dst = * src + + ;
INC_DST_OVERFLOW_CHECK ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2011-12-09 01:33:29 +00:00
} else if ( * src = = ' \0 ' ) {
ast_log ( LOG_WARNING ,
" A matching ']' was not found for '[' in exten pattern '%s' \n " ,
extenbuf ) ;
break ;
} else if ( * src = = ' ] ' ) {
+ + src ;
2009-02-04 00:43:52 +00:00
break ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else {
2011-12-09 01:33:29 +00:00
* dst = * src + + ;
INC_DST_OVERFLOW_CHECK ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
}
2011-12-09 01:33:29 +00:00
/* null terminate the exploded range */
* dst = ' \0 ' ;
if ( overflow ) {
ast_log ( LOG_ERROR ,
" Expanded character set too large to deal with in exten pattern '%s'. Ignoring character set. \n " ,
extenbuf ) ;
node - > buf [ 0 ] = ' \0 ' ;
continue ;
}
/* Sort the characters in character set. */
length = strlen ( node - > buf ) ;
if ( ! length ) {
ast_log ( LOG_WARNING , " Empty character set in exten pattern '%s'. Ignoring. \n " ,
extenbuf ) ;
node - > buf [ 0 ] = ' \0 ' ;
continue ;
}
qsort ( node - > buf , length , 1 , compare_char ) ;
/* Remove duplicate characters from character set. */
dst = node - > buf ;
src_next = node - > buf ;
while ( * src_next + + ) {
if ( * dst ! = * src_next ) {
* + + dst = * src_next ;
}
}
length = strlen ( node - > buf ) ;
length < < = 8 ;
node - > specif = length | ( unsigned char ) node - > buf [ 0 ] ;
break ;
} else if ( * src = = ' - ' ) {
/* Skip dashes in all extensions. */
+ + src ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else {
2011-12-09 01:33:29 +00:00
if ( * src = = ' \\ ' ) {
/*
* XXX The escape character here does not remove any special
* meaning to characters except the ' [ ' , ' \\ ' , and ' - '
* characters since they are special only in this function .
*/
node - > buf [ 0 ] = * + + src ;
if ( ! node - > buf [ 0 ] ) {
break ;
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else {
2011-12-09 01:33:29 +00:00
node - > buf [ 0 ] = * src ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( pattern ) {
2011-12-09 01:33:29 +00:00
/* make sure n,x,z patterns are canonicalized to N,X,Z */
if ( node - > buf [ 0 ] = = ' n ' ) {
node - > buf [ 0 ] = ' N ' ;
} else if ( node - > buf [ 0 ] = = ' x ' ) {
node - > buf [ 0 ] = ' X ' ;
} else if ( node - > buf [ 0 ] = = ' z ' ) {
node - > buf [ 0 ] = ' Z ' ;
2009-04-17 13:29:33 +00:00
}
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2011-12-09 01:33:29 +00:00
node - > buf [ 1 ] = ' \0 ' ;
node - > specif = 1 ;
+ + src ;
break ;
}
}
return src ;
# undef INC_DST_OVERFLOW_CHECK
}
static struct match_char * add_exten_to_pattern_tree ( struct ast_context * con , struct ast_exten * e1 , int findonly )
{
struct match_char * m1 = NULL ;
struct match_char * m2 = NULL ;
struct match_char * * m0 ;
const char * pos ;
int already ;
int pattern = 0 ;
int idx_cur ;
int idx_next ;
char extenbuf [ 512 ] ;
struct pattern_node pat_node [ 2 ] ;
if ( e1 - > matchcid ) {
if ( sizeof ( extenbuf ) < strlen ( e1 - > exten ) + strlen ( e1 - > cidmatch ) + 2 ) {
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 NULL ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2011-12-09 01:33:29 +00:00
sprintf ( extenbuf , " %s/%s " , e1 - > exten , e1 - > cidmatch ) ; /* Safe. We just checked. */
} else {
ast_copy_string ( extenbuf , e1 - > exten , sizeof ( extenbuf ) ) ;
}
# ifdef NEED_DEBUG
ast_debug ( 1 , " Adding exten %s to tree \n " , extenbuf ) ;
# endif
m1 = con - > pattern_tree ; /* each pattern starts over at the root of the pattern tree */
m0 = & con - > pattern_tree ;
already = 1 ;
pos = extenbuf ;
if ( * pos = = ' _ ' ) {
pattern = 1 ;
+ + pos ;
}
idx_cur = 0 ;
pos = get_pattern_node ( & pat_node [ idx_cur ] , pos , pattern , extenbuf ) ;
for ( ; pat_node [ idx_cur ] . buf [ 0 ] ; idx_cur = idx_next ) {
idx_next = ( idx_cur + 1 ) % ARRAY_LEN ( pat_node ) ;
pos = get_pattern_node ( & pat_node [ idx_next ] , pos , pattern , extenbuf ) ;
/* See about adding node to tree. */
m2 = NULL ;
if ( already & & ( m2 = already_in_tree ( m1 , pat_node [ idx_cur ] . buf , pattern ) )
& & m2 - > next_char ) {
if ( ! pat_node [ idx_next ] . buf [ 0 ] ) {
/*
* This is the end of the pattern , but not the end of the tree .
* Mark this node with the exten . . . a shorter pattern might win
* if the longer one doesn ' t match .
*/
Fixed invalid memory access when adding extension to pattern match tree
When an extension is removed from a context, its entry in the pattern match
tree is not deleted. Instead, the extension is marked as deleted. When an
extension is removed and re-added, if that extension is also a prefix of
another extension, several log messages would report an error and did not
check whether or not the extension was deleted before accessing the memory.
Additionally, if the extension was already in the tree but previously
deleted, and the pattern was at the end of a match, the findonly flag was
not honored and the extension would be erroneously undeleted.
Additionaly, it was discovered that an IAX2 peer could be unregistered
via the CLI, while at the same time it could be scheduled for unregistration
by Asterisk. The unregistration method now checks to see if the peer
was already unregistered before continuing with an unregistration.
(closes issue ASTERISK-18135)
Reported by: Jaco Kroon, Henry Fernandes, Kristijan Vrban
Tested by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/1526
........
Merged revisions 342769 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 342770 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@342771 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-10-31 16:10:32 +00:00
if ( findonly ) {
return m2 ;
}
2009-04-17 13:29:33 +00:00
if ( m2 - > exten ) {
2011-12-09 01:33:29 +00:00
ast_log ( LOG_WARNING , " Found duplicate exten. Had %s found %s \n " ,
2016-07-28 19:10:04 +00:00
m2 - > deleted ? " (deleted/invalid) " : m2 - > exten - > name , e1 - > name ) ;
2009-04-17 13:29:33 +00:00
}
2007-11-13 21:19:11 +00:00
m2 - > exten = e1 ;
2007-11-21 01:09:47 +00:00
m2 - > deleted = 0 ;
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
m1 = m2 - > next_char ; /* m1 points to the node to compare against */
2008-04-01 20:02:19 +00:00
m0 = & m2 - > next_char ; /* m0 points to the ptr that points to m1 */
} else { /* not already OR not m2 OR nor m2->next_char */
2007-11-13 21:19:11 +00:00
if ( m2 ) {
2009-03-11 00:28:28 +00:00
if ( findonly ) {
2007-11-19 22:55:38 +00:00
return m2 ;
2009-03-11 00:28:28 +00:00
}
2008-04-01 20:02:19 +00:00
m1 = m2 ; /* while m0 stays the same */
2007-11-19 22:55:38 +00:00
} else {
2009-03-11 00:28:28 +00:00
if ( findonly ) {
2007-11-19 22:55:38 +00:00
return m1 ;
2009-03-11 00:28:28 +00:00
}
2011-12-09 01:33:29 +00:00
m1 = add_pattern_node ( con , m1 , & pat_node [ idx_cur ] , pattern , already , m0 ) ;
if ( ! m1 ) { /* m1 is the node just added */
2009-04-17 13:29:33 +00:00
return NULL ;
}
2008-04-01 20:02:19 +00:00
m0 = & m1 - > next_char ;
2007-11-19 22:55:38 +00:00
}
2011-12-09 01:33:29 +00:00
if ( ! pat_node [ idx_next ] . buf [ 0 ] ) {
2009-05-06 22:02:46 +00:00
if ( m2 & & m2 - > exten ) {
2011-12-09 01:33:29 +00:00
ast_log ( LOG_WARNING , " Found duplicate exten. Had %s found %s \n " ,
2016-07-28 19:10:04 +00:00
m2 - > deleted ? " (deleted/invalid) " : m2 - > exten - > name , e1 - > name ) ;
2009-04-17 13:29:33 +00:00
}
2007-11-21 01:09:47 +00:00
m1 - > deleted = 0 ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
m1 - > exten = e1 ;
2007-11-21 01:09:47 +00:00
}
2009-03-11 00:28:28 +00:00
2009-04-17 13:29:33 +00:00
/* The 'already' variable is a mini-optimization designed to make it so that we
* don ' t have to call already_in_tree when we know it will return false .
*/
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
already = 0 ;
}
}
return m1 ;
}
2007-11-21 15:29:39 +00:00
static void create_match_char_tree ( struct ast_context * con )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
struct ast_hashtab_iter * t1 ;
struct ast_exten * e1 ;
# ifdef NEED_DEBUG
int biggest_bucket , resizes , numobjs , numbucks ;
2009-03-11 00:28:28 +00:00
2011-02-04 16:55:39 +00:00
ast_debug ( 1 , " Creating Extension Trie for context %s(%p) \n " , con - > name , con ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_get_stats ( con - > root_table , & biggest_bucket , & resizes , & numobjs , & numbucks ) ;
2011-02-04 16:55:39 +00:00
ast_debug ( 1 , " This tree has %d objects in %d bucket lists, longest list=%d objects, and has resized %d times \n " ,
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
numobjs , numbucks , biggest_bucket , resizes ) ;
# endif
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
t1 = ast_hashtab_start_traversal ( con - > root_table ) ;
2009-03-11 00:28:28 +00:00
while ( ( e1 = ast_hashtab_next ( t1 ) ) ) {
if ( e1 - > exten ) {
2007-11-19 22:55:38 +00:00
add_exten_to_pattern_tree ( con , e1 , 0 ) ;
2009-03-11 00:28:28 +00:00
} else {
ast_log ( LOG_ERROR , " Attempt to create extension with no extension name. \n " ) ;
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
ast_hashtab_end_traversal ( t1 ) ;
}
2007-11-21 15:29:39 +00:00
static 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! */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
/* 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 */
2009-04-17 13:29:33 +00:00
ast_free ( pattern_tree ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2012-11-28 00:13:10 +00:00
/*!
* \ internal
* \ brief Get the length of the exten string .
*
* \ param str Exten to get length .
*
* \ retval strlen of exten .
*/
static int ext_cmp_exten_strlen ( const char * str )
{
int len ;
len = 0 ;
for ( ; ; ) {
/* Ignore '-' chars as eye candy fluff. */
while ( * str = = ' - ' ) {
+ + str ;
}
if ( ! * str ) {
break ;
}
+ + str ;
+ + len ;
}
return len ;
}
/*!
* \ internal
* \ brief Partial comparison of non - pattern extens .
*
* \ param left Exten to compare .
* \ param right Exten to compare . Also matches if this string ends first .
*
* \ retval < 0 if left < right
* \ retval = 0 if left = = right
* \ retval > 0 if left > right
*/
static int ext_cmp_exten_partial ( const char * left , const char * right )
{
int cmp ;
for ( ; ; ) {
/* Ignore '-' chars as eye candy fluff. */
while ( * left = = ' - ' ) {
+ + left ;
}
while ( * right = = ' - ' ) {
+ + right ;
}
if ( ! * right ) {
/*
* Right ended first for partial match or both ended at the same
* time for a match .
*/
cmp = 0 ;
break ;
}
cmp = * left - * right ;
if ( cmp ) {
break ;
}
+ + left ;
+ + right ;
}
return cmp ;
}
/*!
* \ internal
* \ brief Comparison of non - pattern extens .
*
* \ param left Exten to compare .
* \ param right Exten to compare .
*
* \ retval < 0 if left < right
* \ retval = 0 if left = = right
* \ retval > 0 if left > right
*/
static int ext_cmp_exten ( const char * left , const char * right )
{
int cmp ;
for ( ; ; ) {
/* Ignore '-' chars as eye candy fluff. */
while ( * left = = ' - ' ) {
+ + left ;
}
while ( * right = = ' - ' ) {
+ + right ;
}
cmp = * left - * right ;
if ( cmp ) {
break ;
}
if ( ! * left ) {
/*
* Get here only if both strings ended at the same time . cmp
* would be non - zero if only one string ended .
*/
break ;
}
+ + left ;
+ + right ;
}
return cmp ;
}
2006-05-10 07:45:14 +00:00
/*
* Special characters used in patterns :
* ' _ ' underscore is the leading character of a pattern .
* In other position it is treated as a regular char .
2012-11-28 00:13:10 +00:00
* ' - ' The ' - ' is a separator and ignored . Why ? So patterns like NXX - XXX - XXXX work .
2006-05-10 07:45:14 +00:00
* . one or more of any character . Only allowed at the end of
* a pattern .
* ! zero or more of anything . Also impacts the result of CANMATCH
* and MATCHMORE . Only allowed at the end of a pattern .
2006-05-10 20:34:18 +00:00
* In the core routine , ! causes a match with a return code of 2.
* In turn , depending on the search mode : ( XXX check if it is implemented )
* - E_MATCH retuns 1 ( does match )
* - E_MATCHMORE returns 0 ( no match )
* - E_CANMATCH returns 1 ( does match )
*
2006-05-10 07:45:14 +00:00
* / should not appear as it is considered the separator of the CID info .
* XXX at the moment we may stop on this char .
*
* X Z N match ranges 0 - 9 , 1 - 9 , 2 - 9 respectively .
* [ denotes the start of a set of character . Everything inside
* is considered literally . We can have ranges a - d and individual
* characters . A ' [ ' and ' - ' can be considered literally if they
* are just before ' ] ' .
* XXX currently there is no way to specify ' ] ' in a range , nor \ is
* considered specially .
*
* When we compare a pattern with a specific extension , all characters in the extension
(closes issue #14076)
Reported by: toc
Tested by: murf
OK, Well this issue has had its share of flip-flopping.
I found the following:
1. the code in question, in ext_cmp1 in pbx.c, would not
allow two extensions that vary only by any dashes contained
within them, to be defined in the same context.
2. for input dialstrings, dashes are NOT ignored.
So, skipping them when sorting patterns seemed a bit silly.
Thus, you might declare ext 891 in a context, but
if you try dialing 8-9-1, it will NOT match 891.
So, I proposed to remove the code from ext_cmp1 to
skip the spaces and dashes. Just kept us from
declaring 891 and 8-9-1 in the same context,
forcing users to generate otherwise uselessly
obfuscated dialplan code to get the same effect.
Then, I tried out 1.4, and found that:
1. you can declare 891 and 8-9-1 in the
same context!
2. You can't define 891, and have 8-9-1 match
it! Nor can you define 8-9-1, and have 891
match it!
So, it appears that my proposal simply restores
the pbx to behaving as it did in 1.4.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@164801 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-12-16 20:04:46 +00:00
* itself are considered literally .
2006-05-10 07:45:14 +00:00
* XXX do we want to consider space as a separator as well ?
* XXX do we want to consider the separators in non - patterns as well ?
*/
2006-05-09 18:34:30 +00:00
/*!
2012-11-28 00:13:10 +00:00
* \ brief helper functions to sort extension patterns in the desired way ,
2006-05-09 18:34:30 +00:00
* so that more specific patterns appear first .
*
2012-11-28 00:13:10 +00:00
* \ details
* The function compares individual characters ( or sets of ) , returning
2006-05-09 18:34:30 +00:00
* an int where bits 0 - 7 are the ASCII code of the first char in the set ,
2012-11-28 00:13:10 +00:00
* bits 8 - 15 are the number of characters in the set , and bits 16 - 20 are
* for special cases .
* This way more specific patterns ( smaller character sets ) appear first .
2006-05-09 18:34:30 +00:00
* Wildcards have a special value , so that we can directly compare them to
* sets by subtracting the two values . In particular :
2012-11-28 00:13:10 +00:00
* 0x001 xx one character , character set starting with xx
* 0x0 yyxx yy characters , character set starting with xx
* 0x18000 ' . ' ( one or more of anything )
* 0x28000 ' ! ' ( zero or more of anything )
* 0x30000 NUL ( end of string )
* 0x40000 error in set .
2006-05-09 18:34:30 +00:00
* The pointer to the string is advanced according to needs .
* NOTES :
2012-11-28 00:13:10 +00:00
* 1. the empty set is ignored .
* 2. given that a full set has always 0 as the first element ,
* we could encode the special cases as 0xff XX where XX
* is 1 , 2 , 3 , 4 as used above .
2006-05-09 18:34:30 +00:00
*/
2012-11-28 00:13:10 +00:00
static int ext_cmp_pattern_pos ( const char * * p , unsigned char * bitwise )
2006-05-09 18:34:30 +00:00
{
2012-11-28 00:13:10 +00:00
# define BITS_PER 8 /* Number of bits per unit (byte). */
unsigned char c ;
unsigned char cmin ;
int count ;
2006-05-09 18:34:30 +00:00
const char * end ;
2012-11-28 00:13:10 +00:00
do {
/* Get character and advance. (Ignore '-' chars as eye candy fluff.) */
do {
c = * ( * p ) + + ;
} while ( c = = ' - ' ) ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
/* always return unless we have a set of chars */
switch ( c ) {
default :
/* ordinary character */
bitwise [ c / BITS_PER ] = 1 < < ( ( BITS_PER - 1 ) - ( c % BITS_PER ) ) ;
return 0x0100 | c ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
case ' n ' :
case ' N ' :
/* 2..9 */
bitwise [ 6 ] = 0x3f ;
bitwise [ 7 ] = 0xc0 ;
return 0x0800 | ' 2 ' ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
case ' x ' :
case ' X ' :
/* 0..9 */
bitwise [ 6 ] = 0xff ;
bitwise [ 7 ] = 0xc0 ;
return 0x0A00 | ' 0 ' ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
case ' z ' :
case ' Z ' :
/* 1..9 */
bitwise [ 6 ] = 0x7f ;
bitwise [ 7 ] = 0xc0 ;
return 0x0900 | ' 1 ' ;
case ' . ' :
/* wildcard */
return 0x18000 ;
case ' ! ' :
/* earlymatch */
return 0x28000 ; /* less specific than '.' */
case ' \0 ' :
/* empty string */
* p = NULL ;
return 0x30000 ;
case ' [ ' :
/* char set */
break ;
}
/* locate end of set */
end = strchr ( * p , ' ] ' ) ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
if ( ! end ) {
ast_log ( LOG_WARNING , " Wrong usage of [] in the extension \n " ) ;
return 0x40000 ; /* XXX make this entry go last... */
}
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
count = 0 ;
cmin = 0xFF ;
for ( ; * p < end ; + + * p ) {
unsigned char c1 ; /* first char in range */
unsigned char c2 ; /* last char in range */
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
c1 = ( * p ) [ 0 ] ;
if ( * p + 2 < end & & ( * p ) [ 1 ] = = ' - ' ) { /* this is a range */
c2 = ( * p ) [ 2 ] ;
* p + = 2 ; /* skip a total of 3 chars */
} else { /* individual character */
c2 = c1 ;
}
if ( c1 < cmin ) {
cmin = c1 ;
}
for ( ; c1 < = c2 ; + + c1 ) {
unsigned char mask = 1 < < ( ( BITS_PER - 1 ) - ( c1 % BITS_PER ) ) ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
/*
* Note : If two character sets score the same , the one with the
* lowest ASCII values will compare as coming first . Must fill
* in most significant bits for lower ASCII values to accomplish
* the desired sort order .
*/
if ( ! ( bitwise [ c1 / BITS_PER ] & mask ) ) {
/* Add the character to the set. */
bitwise [ c1 / BITS_PER ] | = mask ;
count + = 0x100 ;
}
2009-11-10 22:14:22 +00:00
}
2006-05-09 18:34:30 +00:00
}
2012-11-28 00:13:10 +00:00
+ + * p ;
} while ( ! count ) ; /* While the char set was empty. */
return count | cmin ;
2006-05-09 18:34:30 +00:00
}
/*!
2012-11-28 00:13:10 +00:00
* \ internal
* \ brief Comparison of exten patterns .
*
* \ param left Pattern to compare .
* \ param right Pattern to compare .
*
* \ retval < 0 if left < right
* \ retval = 0 if left = = right
* \ retval > 0 if left > right
2006-05-09 18:34:30 +00:00
*/
2012-11-28 00:13:10 +00:00
static int ext_cmp_pattern ( const char * left , const char * right )
2006-05-09 18:34:30 +00:00
{
2012-11-28 00:13:10 +00:00
int cmp ;
int left_pos ;
int right_pos ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
for ( ; ; ) {
unsigned char left_bitwise [ 32 ] = { 0 , } ;
unsigned char right_bitwise [ 32 ] = { 0 , } ;
2006-05-09 18:34:30 +00:00
2012-11-28 00:13:10 +00:00
left_pos = ext_cmp_pattern_pos ( & left , left_bitwise ) ;
right_pos = ext_cmp_pattern_pos ( & right , right_bitwise ) ;
cmp = left_pos - right_pos ;
if ( ! cmp ) {
/*
* Are the character sets different , even though they score the same ?
*
* Note : Must swap left and right to get the sense of the
* comparison correct . Otherwise , we would need to multiply by
* - 1 instead .
*/
cmp = memcmp ( right_bitwise , left_bitwise , ARRAY_LEN ( left_bitwise ) ) ;
}
if ( cmp ) {
break ;
}
if ( ! left ) {
/*
* Get here only if both patterns ended at the same time . cmp
* would be non - zero if only one pattern ended .
*/
break ;
}
}
return cmp ;
}
2009-11-10 22:14:22 +00:00
2012-11-28 00:13:10 +00:00
/*!
* \ internal
* \ brief Comparison of dialplan extens for sorting purposes .
*
* \ param left Exten / pattern to compare .
* \ param right Exten / pattern to compare .
*
* \ retval < 0 if left < right
* \ retval = 0 if left = = right
* \ retval > 0 if left > right
*/
static int ext_cmp ( const char * left , const char * right )
{
/* Make sure non-pattern extens come first. */
if ( left [ 0 ] ! = ' _ ' ) {
if ( right [ 0 ] = = ' _ ' ) {
return - 1 ;
}
/* Compare two non-pattern extens. */
return ext_cmp_exten ( left , right ) ;
2009-11-10 22:14:22 +00:00
}
2012-11-28 00:13:10 +00:00
if ( right [ 0 ] ! = ' _ ' ) {
return 1 ;
}
/*
* OK , we need full pattern sorting routine .
*
* Skip past the underscores
*/
return ext_cmp_pattern ( left + 1 , right + 1 ) ;
2006-05-09 18:34:30 +00:00
}
2016-07-28 19:10:04 +00:00
static int ext_fluff_count ( const char * exten )
{
int fluff = 0 ;
if ( * exten ! = ' _ ' ) {
/* not a pattern, simple check. */
while ( * exten ) {
if ( * exten = = ' - ' ) {
fluff + + ;
}
exten + + ;
}
return fluff ;
}
/* do pattern check */
while ( * exten ) {
if ( * exten = = ' - ' ) {
fluff + + ;
} else if ( * exten = = ' [ ' ) {
/* skip set, dashes here matter. */
exten = strchr ( exten , ' ] ' ) ;
if ( ! exten ) {
/* we'll end up warning about this later, don't spam logs */
return fluff ;
}
}
exten + + ;
}
return fluff ;
}
2007-11-02 15:36:34 +00:00
int ast_extension_cmp ( const char * a , const char * b )
{
2012-11-28 00:13:10 +00:00
int cmp ;
cmp = ext_cmp ( a , b ) ;
if ( cmp < 0 ) {
return - 1 ;
}
if ( cmp > 0 ) {
return 1 ;
}
return 0 ;
2007-11-02 15:36:34 +00:00
}
2007-08-07 23:04:01 +00:00
/*!
* \ internal
* \ brief used ast_extension_ { match | close }
2006-05-09 08:31:42 +00:00
* mode is as follows :
* E_MATCH success only on exact match
* E_MATCHMORE success only on partial match ( i . e . leftover digits in pattern )
* E_CANMATCH either of the above .
2007-08-07 23:04:01 +00:00
* \ retval 0 on no - match
* \ retval 1 on match
* \ retval 2 on early match .
2006-05-09 08:31:42 +00:00
*/
2006-09-01 15:57:05 +00:00
2006-05-09 08:31:42 +00:00
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 */
2009-03-11 00:28:28 +00:00
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " match core: pat: '%s', dat: '%s', mode=%d \n " , pattern , data , ( int ) mode ) ;
# endif
2009-03-11 00:28:28 +00:00
2006-05-09 08:31:42 +00:00
if ( pattern [ 0 ] ! = ' _ ' ) { /* not a pattern, try exact or partial match */
2012-11-28 00:13:10 +00:00
int lp = ext_cmp_exten_strlen ( pattern ) ;
int ld = ext_cmp_exten_strlen ( data ) ;
2009-03-11 00:28:28 +00:00
2008-04-01 20:02:19 +00:00
if ( lp < ld ) { /* pattern too short, cannot match */
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (0) - pattern too short, cannot match \n " ) ;
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2006-05-09 08:31:42 +00:00
/* depending on the mode, accept full or partial match or both */
2008-04-01 20:02:19 +00:00
if ( mode = = E_MATCH ) {
# ifdef NEED_DEBUG_HERE
2012-11-28 00:13:10 +00:00
ast_log ( LOG_NOTICE , " return (!ext_cmp_exten(%s,%s) when mode== E_MATCH) \n " , pattern , data ) ;
2008-04-01 20:02:19 +00:00
# endif
2012-11-28 00:13:10 +00:00
return ! ext_cmp_exten ( pattern , data ) ; /* 1 on match, 0 on fail */
2009-03-11 00:28:28 +00:00
}
2012-11-28 00:13:10 +00:00
if ( ld = = 0 | | ! ext_cmp_exten_partial ( pattern , data ) ) { /* partial or full match */
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (mode(%d) == E_MATCHMORE ? lp(%d) > ld(%d) : 1) \n " , mode , lp , ld ) ;
# endif
2006-05-09 08:31:42 +00:00
return ( mode = = E_MATCHMORE ) ? lp > ld : 1 ; /* XXX should consider '!' and '/' ? */
2008-04-01 20:02:19 +00:00
} else {
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (0) when ld(%d) > 0 && pattern(%s) != data(%s) \n " , ld , pattern , data ) ;
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2006-05-09 08:31:42 +00:00
}
2012-11-28 00:13:10 +00:00
if ( mode = = E_MATCH & & data [ 0 ] = = ' _ ' ) {
/*
* XXX It is bad design that we don ' t know if we should be
* comparing data and pattern as patterns or comparing data if
* it conforms to pattern when the function is called . First ,
* assume they are both patterns . If they don ' t match then try
* to see if data conforms to the given pattern .
*
* note : if this test is left out , then _x . will not match _x . ! ! !
*/
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " Comparing as patterns first. pattern:%s data:%s \n " , pattern , data ) ;
# endif
if ( ! ext_cmp_pattern ( pattern + 1 , data + 1 ) ) {
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (1) - pattern matches pattern \n " ) ;
# endif
return 1 ;
}
}
+ + pattern ; /* skip leading _ */
2006-05-10 07:45:14 +00:00
/*
* XXX below we stop at ' / ' which is a separator for the CID info . However we should
* not store ' / ' in the pattern at all . When we insure it , we can remove the checks .
*/
2012-11-28 00:13:10 +00:00
for ( ; ; ) {
2006-05-09 08:31:42 +00:00
const char * end ;
2012-11-28 00:13:10 +00:00
/* Ignore '-' chars as eye candy fluff. */
while ( * data = = ' - ' ) {
+ + data ;
2006-05-09 08:31:42 +00:00
}
2012-11-28 00:13:10 +00:00
while ( * pattern = = ' - ' ) {
+ + pattern ;
}
if ( ! * data | | ! * pattern | | * pattern = = ' / ' ) {
break ;
}
switch ( * pattern ) {
2006-05-09 08:31:42 +00:00
case ' [ ' : /* a range */
2012-11-28 00:13:10 +00:00
+ + pattern ;
end = strchr ( pattern , ' ] ' ) ; /* XXX should deal with escapes ? */
if ( ! end ) {
2006-05-09 08:31:42 +00:00
ast_log ( LOG_WARNING , " Wrong usage of [] in the extension \n " ) ;
return 0 ; /* unconditional failure */
}
2012-11-28 00:13:10 +00:00
if ( pattern = = end ) {
/* Ignore empty character sets. */
+ + pattern ;
continue ;
}
for ( ; pattern < end ; + + pattern ) {
2006-05-09 08:31:42 +00:00
if ( pattern + 2 < end & & pattern [ 1 ] = = ' - ' ) { /* this is a range */
if ( * data > = pattern [ 0 ] & & * data < = pattern [ 2 ] )
break ; /* match found */
else {
pattern + = 2 ; /* skip a total of 3 chars */
continue ;
}
} else if ( * data = = pattern [ 0 ] )
break ; /* match found */
}
2012-11-28 00:13:10 +00:00
if ( pattern > = end ) {
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
2012-11-28 00:13:10 +00:00
ast_log ( LOG_NOTICE , " return (0) when pattern>=end \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2006-05-09 08:31:42 +00:00
pattern = end ; /* skip and continue */
break ;
2012-11-28 00:13:10 +00:00
case ' n ' :
2006-05-09 08:31:42 +00:00
case ' N ' :
2008-04-01 20:02:19 +00:00
if ( * data < ' 2 ' | | * data > ' 9 ' ) {
# ifdef NEED_DEBUG_HERE
2012-11-28 00:13:10 +00:00
ast_log ( LOG_NOTICE , " return (0) N is not matched \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2006-05-09 08:31:42 +00:00
break ;
2012-11-28 00:13:10 +00:00
case ' x ' :
2006-05-09 08:31:42 +00:00
case ' X ' :
2008-04-01 20:02:19 +00:00
if ( * data < ' 0 ' | | * data > ' 9 ' ) {
# ifdef NEED_DEBUG_HERE
2012-11-28 00:13:10 +00:00
ast_log ( LOG_NOTICE , " return (0) X is not matched \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2006-05-09 08:31:42 +00:00
break ;
2012-11-28 00:13:10 +00:00
case ' z ' :
2006-05-09 08:31:42 +00:00
case ' Z ' :
2008-04-01 20:02:19 +00:00
if ( * data < ' 1 ' | | * data > ' 9 ' ) {
# ifdef NEED_DEBUG_HERE
2012-11-28 00:13:10 +00:00
ast_log ( LOG_NOTICE , " return (0) Z is not matched \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2006-05-09 08:31:42 +00:00
break ;
case ' . ' : /* Must match, even with more digits */
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " return (1) when '.' is matched \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 1 ;
case ' ! ' : /* Early match */
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " return (2) when '!' is matched \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 2 ;
default :
2008-04-01 20:02:19 +00:00
if ( * data ! = * pattern ) {
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " return (0) when *data(%c) != *pattern(%c) \n " , * data , * pattern ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2012-11-28 00:13:10 +00:00
break ;
2006-05-09 08:31:42 +00:00
}
2012-11-28 00:13:10 +00:00
+ + data ;
+ + pattern ;
2006-05-09 08:31:42 +00:00
}
2008-04-01 20:02:19 +00:00
if ( * data ) /* data longer than pattern, no match */ {
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " return (0) when data longer than pattern \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 0 ;
2008-04-01 20:02:19 +00:00
}
2009-03-11 00:28:28 +00:00
2006-05-09 08:31:42 +00:00
/*
2012-11-28 00:13:10 +00:00
* match so far , but ran off the end of data .
2006-05-09 08:31:42 +00:00
* Depending on what is next , determine match or not .
*/
2008-04-01 20:02:19 +00:00
if ( * pattern = = ' \0 ' | | * pattern = = ' / ' ) { /* exact match */
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " at end, return (%d) in 'exact match' \n " , ( mode = = E_MATCHMORE ) ? 0 : 1 ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return ( mode = = E_MATCHMORE ) ? 0 : 1 ; /* this is a failure for E_MATCHMORE */
2008-04-01 20:02:19 +00:00
} else if ( * pattern = = ' ! ' ) { /* early match */
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " at end, return (2) when '!' is matched \n " ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return 2 ;
2008-04-01 20:02:19 +00:00
} else { /* partial match */
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " at end, return (%d) which deps on E_MATCH \n " , ( mode = = E_MATCH ) ? 0 : 1 ) ;
2008-04-01 20:02:19 +00:00
# endif
2006-05-09 08:31:42 +00:00
return ( mode = = E_MATCH ) ? 0 : 1 ; /* this is a failure for E_MATCH */
2008-04-01 20:02:19 +00:00
}
2006-05-09 08:31:42 +00:00
}
/*
* Wrapper around _extension_match_core ( ) to do performance measurement
* using the profiling code .
*/
static int extension_match_core ( const char * pattern , const char * data , enum ext_match_t mode )
{
int i ;
static int prof_id = - 2 ; /* marker for 'unallocated' id */
2009-03-11 00:28:28 +00:00
if ( prof_id = = - 2 ) {
2006-05-09 08:31:42 +00:00
prof_id = ast_add_profile ( " ext_match " , 0 ) ;
2009-03-11 00:28:28 +00:00
}
2006-05-09 08:31:42 +00:00
ast_mark ( prof_id , 1 ) ;
2011-11-11 15:47:39 +00:00
i = _extension_match_core ( ast_strlen_zero ( pattern ) ? " " : pattern , ast_strlen_zero ( data ) ? " " : data , mode ) ;
2006-05-09 08:31:42 +00:00
ast_mark ( prof_id , 0 ) ;
return i ;
2003-02-12 13:59:15 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_extension_match ( const char * pattern , const char * data )
1999-12-04 20:45:45 +00:00
{
2006-05-09 08:31:42 +00:00
return extension_match_core ( pattern , data , E_MATCH ) ;
1999-12-04 20:45:45 +00:00
}
2004-11-24 03:07:08 +00:00
int ast_extension_close ( const char * pattern , const char * data , int needmore )
2000-01-07 10:54:40 +00:00
{
2006-05-09 08:31:42 +00:00
if ( needmore ! = E_MATCHMORE & & needmore ! = E_CANMATCH )
ast_log ( LOG_WARNING , " invalid argument %d \n " , needmore ) ;
return extension_match_core ( pattern , data , needmore ) ;
2000-01-07 10:54:40 +00:00
}
2016-03-28 16:31:29 +00:00
/* This structure must remain in sync with ast_context for proper hashtab matching */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
struct fake_context /* this struct is purely for matching in the hashtab */
{
2009-03-11 00:28:28 +00:00
ast_rwlock_t lock ;
struct ast_exten * root ;
struct ast_hashtab * root_table ;
struct match_char * pattern_tree ;
struct ast_context * next ;
2016-07-14 18:51:42 +00:00
struct ast_includes includes ;
2016-07-15 07:59:48 +00:00
struct ast_ignorepats ignorepats ;
2016-07-16 00:28:16 +00:00
struct ast_sws alts ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
const char * registrar ;
int refcount ;
2016-03-28 16:31:29 +00:00
int autohints ;
2009-03-11 00:28:28 +00:00
ast_mutex_t macrolock ;
char name [ 256 ] ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} ;
2004-10-03 04:19:59 +00:00
struct ast_context * ast_context_find ( const char * name )
2000-01-24 07:14:18 +00:00
{
2011-07-08 01:26:01 +00:00
struct ast_context * tmp ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
struct fake_context item ;
2009-02-18 06:00:40 +00:00
2011-07-08 01:26:01 +00:00
if ( ! name ) {
return NULL ;
}
2007-02-28 20:46:01 +00:00
ast_rdlock_contexts ( ) ;
2011-07-08 01:26:01 +00:00
if ( contexts_table ) {
ast_copy_string ( item . name , name , sizeof ( item . name ) ) ;
tmp = ast_hashtab_lookup ( contexts_table , & item ) ;
2007-11-21 15:29:39 +00:00
} else {
2011-07-08 01:26:01 +00:00
tmp = NULL ;
while ( ( tmp = ast_walk_contexts ( tmp ) ) ) {
if ( ! strcasecmp ( name , tmp - > name ) ) {
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
break ;
2009-03-11 00:28:28 +00:00
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2006-05-09 13:52:01 +00:00
}
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2000-01-24 07:14:18 +00:00
return tmp ;
}
2005-07-19 15:54:17 +00:00
# define STATUS_NO_CONTEXT 1
# define STATUS_NO_EXTENSION 2
# define STATUS_NO_PRIORITY 3
2004-10-03 04:19:59 +00:00
# define STATUS_NO_LABEL 4
2005-07-19 15:54:17 +00:00
# define STATUS_SUCCESS 5
2001-03-30 18:47:35 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
static int matchcid ( const char * cidpattern , const char * callerid )
{
/* 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 */
2009-03-11 00:28:28 +00:00
if ( ast_strlen_zero ( callerid ) ) {
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
return ast_strlen_zero ( cidpattern ) ? 1 : 0 ;
2009-03-11 00:28:28 +00:00
}
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
return ast_extension_match ( cidpattern , callerid ) ;
}
2007-08-15 19:21:27 +00:00
struct ast_exten * pbx_find_extension ( struct ast_channel * chan ,
2006-05-09 08:31:42 +00:00
struct ast_context * bypass , struct pbx_find_info * q ,
2006-05-08 20:49:30 +00:00
const char * context , const char * exten , int priority ,
2006-05-09 08:31:42 +00:00
const char * label , const char * callerid , enum ext_match_t action )
2001-09-28 21:20:52 +00:00
{
int x , res ;
2008-02-11 18:27:47 +00:00
struct ast_context * tmp = NULL ;
struct ast_exten * e = NULL , * eroot = NULL ;
struct ast_exten pattern = { NULL , } ;
struct scoreboard score = { 0 , } ;
2008-03-10 21:48:20 +00:00
struct ast_str * tmpdata = NULL ;
2016-07-14 18:51:42 +00:00
int idx ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
pattern . label = label ;
pattern . priority = priority ;
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d \n " , context , exten , priority , label , ( int ) action ) ;
2007-11-21 01:09:47 +00:00
# endif
2008-05-14 16:52:30 +00:00
2001-03-30 18:47:35 +00:00
/* Initialize status if appropriate */
2006-05-09 08:31:42 +00:00
if ( q - > stacklen = = 0 ) {
q - > status = STATUS_NO_CONTEXT ;
q - > swo = NULL ;
q - > data = NULL ;
q - > foundcontext = NULL ;
2007-03-01 00:08:18 +00:00
} else if ( q - > stacklen > = AST_PBX_MAX_STACK ) {
2001-03-30 18:47:35 +00:00
ast_log ( LOG_WARNING , " Maximum PBX stack exceeded \n " ) ;
return NULL ;
}
2007-03-01 00:08:18 +00:00
2001-03-30 18:47:35 +00:00
/* Check first to see if we've already been checked */
2006-05-09 08:31:42 +00:00
for ( x = 0 ; x < q - > stacklen ; x + + ) {
if ( ! strcasecmp ( q - > incstack [ x ] , context ) )
2001-03-30 18:47:35 +00:00
return NULL ;
}
2007-03-01 00:08:18 +00:00
2009-03-11 00:28:28 +00:00
if ( bypass ) { /* bypass means we only look there */
2004-10-03 16:15:44 +00:00
tmp = bypass ;
2009-03-11 00:28:28 +00:00
} else { /* look in contexts */
2011-07-08 01:26:01 +00:00
tmp = find_context ( context ) ;
2009-03-11 00:28:28 +00:00
if ( ! tmp ) {
2006-05-08 20:49:30 +00:00
return NULL ;
2009-03-11 00:28:28 +00:00
}
2006-05-08 20:49:30 +00:00
}
2007-03-01 00:08:18 +00:00
2006-05-09 08:31:42 +00:00
if ( q - > status < STATUS_NO_EXTENSION )
q - > status = STATUS_NO_EXTENSION ;
2009-03-11 00:28:28 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
/* Do a search for matching extension */
2007-11-19 22:55:38 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
eroot = NULL ;
score . total_specificity = 0 ;
score . exten = 0 ;
score . total_length = 0 ;
2009-03-11 00:28:28 +00:00
if ( ! tmp - > pattern_tree & & tmp - > root_table ) {
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
create_match_char_tree ( tmp ) ;
# ifdef NEED_DEBUG
2011-02-04 16:55:39 +00:00
ast_debug ( 1 , " Tree Created in context %s: \n " , context ) ;
2007-11-21 01:09:47 +00:00
log_match_char_tree ( tmp - > pattern_tree , " " ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
# endif
}
2007-11-21 01:09:47 +00:00
# ifdef NEED_DEBUG
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " The Trie we are searching in: \n " ) ;
2007-11-21 01:09:47 +00:00
log_match_char_tree ( tmp - > pattern_tree , " :: " ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
# endif
2006-05-10 20:34:18 +00:00
2008-03-10 21:48:20 +00:00
do {
if ( ! ast_strlen_zero ( overrideswitch ) ) {
char * osw = ast_strdupa ( overrideswitch ) , * name ;
struct ast_switch * asw ;
ast_switch_f * aswf = NULL ;
char * datap ;
int eval = 0 ;
name = strsep ( & osw , " / " ) ;
asw = pbx_findswitch ( name ) ;
if ( ! asw ) {
ast_log ( LOG_WARNING , " No such switch '%s' \n " , name ) ;
break ;
}
if ( osw & & strchr ( osw , ' $ ' ) ) {
eval = 1 ;
}
if ( eval & & ! ( tmpdata = ast_str_thread_get ( & switch_data , 512 ) ) ) {
2012-04-06 18:19:03 +00:00
ast_log ( LOG_WARNING , " Can't evaluate overrideswitch?! \n " ) ;
2008-03-10 21:48:20 +00:00
break ;
} else if ( eval ) {
/* Substitute variables now */
2008-12-13 08:36:35 +00:00
pbx_substitute_variables_helper ( chan , osw , ast_str_buffer ( tmpdata ) , ast_str_size ( tmpdata ) ) ;
datap = ast_str_buffer ( tmpdata ) ;
2008-03-10 21:48:20 +00:00
} else {
datap = osw ;
}
/* equivalent of extension_match_core() at the switch level */
if ( action = = E_CANMATCH )
aswf = asw - > canmatch ;
else if ( action = = E_MATCHMORE )
aswf = asw - > matchmore ;
else /* action == E_MATCH */
aswf = asw - > exists ;
if ( ! aswf ) {
res = 0 ;
} else {
if ( chan ) {
ast_autoservice_start ( chan ) ;
}
res = aswf ( chan , context , exten , priority , callerid , datap ) ;
if ( chan ) {
ast_autoservice_stop ( chan ) ;
}
}
if ( res ) { /* Got a match */
q - > swo = asw ;
q - > data = datap ;
q - > foundcontext = context ;
/* XXX keep status = STATUS_NO_CONTEXT ? */
return NULL ;
}
}
} while ( 0 ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( extenpatternmatchnew ) {
2008-06-09 16:35:06 +00:00
new_find_extension ( exten , & score , tmp - > pattern_tree , 0 , 0 , callerid , label , action ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
eroot = score . exten ;
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( score . last_char = = ' ! ' & & action = = E_MATCHMORE ) {
2006-05-11 08:00:35 +00:00
/* We match an extension ending in '!'.
* The decision in this case is final and is NULL ( no match ) .
*/
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
ast_log ( LOG_NOTICE , " Returning MATCHMORE NULL with exclamation point. \n " ) ;
# endif
2006-05-11 08:00:35 +00:00
return NULL ;
}
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( ! eroot & & ( action = = E_CANMATCH | | action = = E_MATCHMORE ) & & score . canmatch_exten ) {
q - > status = STATUS_SUCCESS ;
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
ast_log ( LOG_NOTICE , " Returning CANMATCH exten %s \n " , score . canmatch_exten - > exten ) ;
# endif
return score . canmatch_exten ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( ( action = = E_MATCHMORE | | action = = E_CANMATCH ) & & eroot ) {
if ( score . node ) {
struct ast_exten * z = trie_find_next_match ( score . node ) ;
2008-04-01 20:02:19 +00:00
if ( z ) {
# ifdef NEED_DEBUG_HERE
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
ast_log ( LOG_NOTICE , " Returning CANMATCH/MATCHMORE next_match exten %s \n " , z - > exten ) ;
# endif
2008-04-01 20:02:19 +00:00
} else {
if ( score . canmatch_exten ) {
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " Returning CANMATCH/MATCHMORE canmatchmatch exten %s(%p) \n " , score . canmatch_exten - > exten , score . canmatch_exten ) ;
# endif
return score . canmatch_exten ;
} else {
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " Returning CANMATCH/MATCHMORE next_match exten NULL \n " ) ;
# endif
}
}
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
return z ;
}
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
2009-03-11 00:28:28 +00:00
ast_log ( LOG_NOTICE , " Returning CANMATCH/MATCHMORE NULL (no next_match) \n " ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
# endif
return NULL ; /* according to the code, complete matches are null matches in MATCHMORE mode */
}
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( eroot ) {
/* found entry, now look for the right priority */
if ( q - > status < STATUS_NO_PRIORITY )
q - > status = STATUS_NO_PRIORITY ;
e = NULL ;
if ( action = = E_FINDLABEL & & label ) {
2006-05-11 08:00:35 +00:00
if ( q - > status < STATUS_NO_LABEL )
q - > status = STATUS_NO_LABEL ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
e = ast_hashtab_lookup ( eroot - > peer_label_table , & pattern ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
} else {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
e = ast_hashtab_lookup ( eroot - > peer_table , & pattern ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
}
if ( e ) { /* found a valid match */
q - > status = STATUS_SUCCESS ;
q - > foundcontext = context ;
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
ast_log ( LOG_NOTICE , " Returning complete match of exten %s \n " , e - > exten ) ;
# endif
return e ;
}
2006-05-11 08:00:35 +00:00
}
2008-04-01 20:02:19 +00:00
} else { /* the old/current default exten pattern match algorithm */
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
/* scan the list trying to match extension and CID */
eroot = NULL ;
while ( ( eroot = ast_walk_context_extensions ( tmp , eroot ) ) ) {
int match = extension_match_core ( eroot - > exten , exten , action ) ;
/* 0 on fail, 1 on match, 2 on earlymatch */
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( ! match | | ( eroot - > matchcid & & ! matchcid ( eroot - > cidmatch , callerid ) ) )
continue ; /* keep trying */
if ( match = = 2 & & action = = E_MATCHMORE ) {
/* We match an extension ending in '!'.
* The decision in this case is final and is NULL ( no match ) .
*/
return NULL ;
}
/* found entry, now look for the right priority */
if ( q - > status < STATUS_NO_PRIORITY )
q - > status = STATUS_NO_PRIORITY ;
e = NULL ;
if ( action = = E_FINDLABEL & & label ) {
if ( q - > status < STATUS_NO_LABEL )
q - > status = STATUS_NO_LABEL ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
e = ast_hashtab_lookup ( eroot - > peer_label_table , & pattern ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
} else {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
e = ast_hashtab_lookup ( eroot - > peer_table , & pattern ) ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
}
if ( e ) { /* found a valid match */
q - > status = STATUS_SUCCESS ;
q - > foundcontext = context ;
return e ;
}
2006-05-08 21:09:03 +00:00
}
}
2009-03-11 00:28:28 +00:00
2006-05-08 21:09:03 +00:00
/* Check alternative switches */
2016-07-16 00:28:16 +00:00
for ( idx = 0 ; idx < ast_context_switches_count ( tmp ) ; idx + + ) {
const struct ast_sw * sw = ast_context_switches_get ( tmp , idx ) ;
struct ast_switch * asw = pbx_findswitch ( ast_get_switch_name ( sw ) ) ;
2006-05-09 08:31:42 +00:00
ast_switch_f * aswf = NULL ;
2016-07-16 00:28:16 +00:00
const char * datap ;
2006-05-09 08:31:42 +00:00
if ( ! asw ) {
2016-07-16 00:28:16 +00:00
ast_log ( LOG_WARNING , " No such switch '%s' \n " , ast_get_switch_name ( sw ) ) ;
2006-05-09 08:31:42 +00:00
continue ;
}
2009-03-11 00:28:28 +00:00
2006-05-09 08:31:42 +00:00
/* Substitute variables now */
2016-07-16 00:28:16 +00:00
if ( ast_get_switch_eval ( sw ) ) {
2008-03-10 21:48:20 +00:00
if ( ! ( tmpdata = ast_str_thread_get ( & switch_data , 512 ) ) ) {
2012-04-06 18:19:03 +00:00
ast_log ( LOG_WARNING , " Can't evaluate switch?! \n " ) ;
2008-03-10 21:48:20 +00:00
continue ;
}
2016-07-16 00:28:16 +00:00
pbx_substitute_variables_helper ( chan , ast_get_switch_data ( sw ) ,
ast_str_buffer ( tmpdata ) , ast_str_size ( tmpdata ) ) ;
datap = ast_str_buffer ( tmpdata ) ;
} else {
datap = ast_get_switch_data ( sw ) ;
2008-03-10 21:48:20 +00:00
}
2006-05-09 08:31:42 +00:00
/* equivalent of extension_match_core() at the switch level */
if ( action = = E_CANMATCH )
aswf = asw - > canmatch ;
else if ( action = = E_MATCHMORE )
aswf = asw - > matchmore ;
2006-05-10 20:34:18 +00:00
else /* action == E_MATCH */
2006-05-09 08:31:42 +00:00
aswf = asw - > exists ;
2007-12-04 22:07:35 +00:00
if ( ! aswf )
res = 0 ;
else {
if ( chan )
ast_autoservice_start ( chan ) ;
res = aswf ( chan , context , exten , priority , callerid , datap ) ;
if ( chan )
ast_autoservice_stop ( chan ) ;
}
2006-05-09 08:31:42 +00:00
if ( res ) { /* Got a match */
q - > swo = asw ;
q - > data = datap ;
q - > foundcontext = context ;
/* XXX keep status = STATUS_NO_CONTEXT ? */
return NULL ;
2006-05-08 21:09:03 +00:00
}
}
2006-05-09 08:31:42 +00:00
q - > incstack [ q - > stacklen + + ] = tmp - > name ; /* Setup the stack */
2006-05-08 21:09:03 +00:00
/* Now try any includes we have in this context */
2016-07-14 18:51:42 +00:00
for ( idx = 0 ; idx < ast_context_includes_count ( tmp ) ; idx + + ) {
const struct ast_include * i = ast_context_includes_get ( tmp , idx ) ;
2006-05-08 21:09:03 +00:00
if ( include_valid ( i ) ) {
2016-07-14 18:51:42 +00:00
if ( ( e = pbx_find_extension ( chan , bypass , q , include_rname ( i ) , exten , priority , label , callerid , action ) ) ) {
2008-04-01 20:02:19 +00:00
# ifdef NEED_DEBUG_HERE
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
ast_log ( LOG_NOTICE , " Returning recursive match of %s \n " , e - > exten ) ;
# endif
2006-05-08 21:09:03 +00:00
return e ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
}
2006-05-09 08:31:42 +00:00
if ( q - > swo )
2006-05-08 21:09:03 +00:00
return NULL ;
}
}
2001-03-30 18:47:35 +00:00
return NULL ;
}
2007-10-03 22:14:09 +00:00
static void exception_store_free ( void * data )
{
struct pbx_exception * exception = data ;
2007-11-04 19:44:31 +00:00
ast_string_field_free_memory ( exception ) ;
2007-10-03 22:14:09 +00:00
ast_free ( exception ) ;
}
2012-07-18 17:18:20 +00:00
static const struct ast_datastore_info exception_store_info = {
2007-10-03 22:14:09 +00:00
. type = " EXCEPTION " ,
. destroy = exception_store_free ,
} ;
2011-04-26 22:18:41 +00:00
/*!
* \ internal
* \ brief Set the PBX to execute the exception extension .
*
* \ param chan Channel to raise the exception on .
* \ param reason Reason exception is raised .
* \ param priority Dialplan priority to set .
*
* \ retval 0 on success .
* \ retval - 1 on error .
*/
2015-12-29 01:18:01 +00:00
int raise_exception ( struct ast_channel * chan , const char * reason , int priority )
2007-10-03 22:14:09 +00:00
{
struct ast_datastore * ds = ast_channel_datastore_find ( chan , & exception_store_info , NULL ) ;
struct pbx_exception * exception = NULL ;
if ( ! ds ) {
2008-08-05 16:56:11 +00:00
ds = ast_datastore_alloc ( & exception_store_info , NULL ) ;
2007-10-03 22:14:09 +00:00
if ( ! ds )
return - 1 ;
2010-01-15 18:21:50 +00:00
if ( ! ( exception = ast_calloc_with_stringfields ( 1 , struct pbx_exception , 128 ) ) ) {
2008-08-05 16:56:11 +00:00
ast_datastore_free ( ds ) ;
2007-10-03 22:14:09 +00:00
return - 1 ;
}
ds - > data = exception ;
ast_channel_datastore_add ( chan , ds ) ;
} else
exception = ds - > data ;
2008-11-01 21:10:07 +00:00
ast_string_field_set ( exception , reason , reason ) ;
2012-02-13 17:27:06 +00:00
ast_string_field_set ( exception , context , ast_channel_context ( chan ) ) ;
ast_string_field_set ( exception , exten , ast_channel_exten ( chan ) ) ;
2012-02-20 23:43:27 +00:00
exception - > priority = ast_channel_priority ( chan ) ;
2011-04-26 22:18:41 +00:00
set_ext_pri ( chan , " e " , priority ) ;
2008-11-01 21:10:07 +00:00
return 0 ;
}
static int acf_exception_read ( struct ast_channel * chan , const char * name , char * data , char * buf , size_t buflen )
{
struct ast_datastore * ds = ast_channel_datastore_find ( chan , & exception_store_info , NULL ) ;
struct pbx_exception * exception = NULL ;
if ( ! ds | | ! ds - > data )
return - 1 ;
exception = ds - > data ;
if ( ! strcasecmp ( data , " REASON " ) )
ast_copy_string ( buf , exception - > reason , buflen ) ;
else if ( ! strcasecmp ( data , " CONTEXT " ) )
ast_copy_string ( buf , exception - > context , buflen ) ;
else if ( ! strncasecmp ( data , " EXTEN " , 5 ) )
ast_copy_string ( buf , exception - > exten , buflen ) ;
else if ( ! strcasecmp ( data , " PRIORITY " ) )
snprintf ( buf , buflen , " %d " , exception - > priority ) ;
else
return - 1 ;
return 0 ;
}
static struct ast_custom_function exception_function = {
. name = " EXCEPTION " ,
. read = acf_exception_read ,
} ;
2009-03-11 00:28:28 +00:00
/*!
Merged revisions 89790 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r89790 | russell | 2007-11-27 15:45:51 -0600 (Tue, 27 Nov 2007) | 41 lines
Merge changes from team/russell/autoservice_1.4
This set of changes fixes an issue that was reported to me on IRC yesterday.
The user, d1mas, was using chan_zap for incoming calls and was having DTMF
recognition issues in some situations. Specifically, he noticed that the
problem occurred when using DISA or WaitExten. He also noticed that when
using Read, the problem did not occur. His system also used DUNDi for
dialplan lookups.
So, he theorized that if the DUNDi lookups blocked for some period of time,
that audio from the zap channel could get lost. If the audio got lost, then
it wouldn't be run through the DTMF detector, and digits could get lost.
He was correct, and the following set of changes fixes the problem. However,
the changes go a little bit further than what was necessary to fix this exact
problem.
1) I updated pbx_extension_helper() to autoservice the associated channel to
handle cases where extension lookups may take a long time. This would
normally be a dialplan switch that does some lookup over the network, such
as the DUNDi or IAX2 switches.
This ensures that even while a DUNDi lookup is blocking, the channel will be
continuously serviced.
2) I made a change to the autoservice code. This is actually something that
has bothered me for a long time. When a channel is in autoservice, _all_
frames get thrown away. However, some frames really shouldn't be thrown
away. The most notable examples are signalling (CONTROL) frames, and DTMF.
So, this patch queues up important frames while a channel is in autoservice.
When autoservice is stopped on the channel, the queued up frames get stuck
back on the channel so that they can get processed instead of thrown away.
3) I made another change to the autoservice code to handle the case where
autoservice is started on channels recursively.
Previously, you could call ast_autoservice_start() multiple times on a
channel, and it would stop the first time ast_autoservice_stop() gets
called. Now, it will ensure that autoservice doesn't actually stop until
the final call to ast_autoservice_stop().
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89791 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-27 22:05:36 +00:00
* \ brief The return value depends on the action :
2006-05-09 08:31:42 +00:00
*
* E_MATCH , E_CANMATCH , E_MATCHMORE require a real match ,
* and return 0 on failure , - 1 on match ;
* E_FINDLABEL maps the label to a priority , and returns
* the priority on success , . . . XXX
* E_SPAWN , spawn an application ,
2009-03-11 00:28:28 +00:00
*
2007-08-07 23:04:01 +00:00
* \ retval 0 on success .
* \ retval - 1 on failure .
Merged revisions 89790 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r89790 | russell | 2007-11-27 15:45:51 -0600 (Tue, 27 Nov 2007) | 41 lines
Merge changes from team/russell/autoservice_1.4
This set of changes fixes an issue that was reported to me on IRC yesterday.
The user, d1mas, was using chan_zap for incoming calls and was having DTMF
recognition issues in some situations. Specifically, he noticed that the
problem occurred when using DISA or WaitExten. He also noticed that when
using Read, the problem did not occur. His system also used DUNDi for
dialplan lookups.
So, he theorized that if the DUNDi lookups blocked for some period of time,
that audio from the zap channel could get lost. If the audio got lost, then
it wouldn't be run through the DTMF detector, and digits could get lost.
He was correct, and the following set of changes fixes the problem. However,
the changes go a little bit further than what was necessary to fix this exact
problem.
1) I updated pbx_extension_helper() to autoservice the associated channel to
handle cases where extension lookups may take a long time. This would
normally be a dialplan switch that does some lookup over the network, such
as the DUNDi or IAX2 switches.
This ensures that even while a DUNDi lookup is blocking, the channel will be
continuously serviced.
2) I made a change to the autoservice code. This is actually something that
has bothered me for a long time. When a channel is in autoservice, _all_
frames get thrown away. However, some frames really shouldn't be thrown
away. The most notable examples are signalling (CONTROL) frames, and DTMF.
So, this patch queues up important frames while a channel is in autoservice.
When autoservice is stopped on the channel, the queued up frames get stuck
back on the channel so that they can get processed instead of thrown away.
3) I made another change to the autoservice code to handle the case where
autoservice is started on channels recursively.
Previously, you could call ast_autoservice_start() multiple times on a
channel, and it would stop the first time ast_autoservice_stop() gets
called. Now, it will ensure that autoservice doesn't actually stop until
the final call to ast_autoservice_stop().
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89791 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-27 22:05:36 +00:00
*
* \ note The channel is auto - serviced in this function , because doing an extension
* match may block for a long time . For example , if the lookup has to use a network
* dialplan switch , such as DUNDi or IAX2 , it may take a while . However , the channel
* auto - service code will queue up any important signalling frames to be processed
* after this is done .
2006-05-09 08:31:42 +00:00
*/
static int pbx_extension_helper ( struct ast_channel * c , struct ast_context * con ,
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
const char * context , const char * exten , int priority ,
const char * label , const char * callerid , enum ext_match_t action , int * found , int combined_find_spawn )
2001-03-30 18:47:35 +00:00
{
struct ast_exten * e ;
1999-12-04 20:45:45 +00:00
struct ast_app * app ;
2013-12-16 16:12:44 +00:00
char * substitute = NULL ;
1999-12-18 07:01:48 +00:00
int res ;
2006-05-09 08:31:42 +00:00
struct pbx_find_info q = { . stacklen = 0 } ; /* the rest is reset in pbx_find_extension */
2004-06-12 14:34:15 +00:00
char passdata [ EXT_DATA_SIZE ] ;
2006-05-09 08:31:42 +00:00
int matching_action = ( action = = E_MATCH | | action = = E_CANMATCH | | action = = E_MATCHMORE ) ;
Merged revisions 89790 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r89790 | russell | 2007-11-27 15:45:51 -0600 (Tue, 27 Nov 2007) | 41 lines
Merge changes from team/russell/autoservice_1.4
This set of changes fixes an issue that was reported to me on IRC yesterday.
The user, d1mas, was using chan_zap for incoming calls and was having DTMF
recognition issues in some situations. Specifically, he noticed that the
problem occurred when using DISA or WaitExten. He also noticed that when
using Read, the problem did not occur. His system also used DUNDi for
dialplan lookups.
So, he theorized that if the DUNDi lookups blocked for some period of time,
that audio from the zap channel could get lost. If the audio got lost, then
it wouldn't be run through the DTMF detector, and digits could get lost.
He was correct, and the following set of changes fixes the problem. However,
the changes go a little bit further than what was necessary to fix this exact
problem.
1) I updated pbx_extension_helper() to autoservice the associated channel to
handle cases where extension lookups may take a long time. This would
normally be a dialplan switch that does some lookup over the network, such
as the DUNDi or IAX2 switches.
This ensures that even while a DUNDi lookup is blocking, the channel will be
continuously serviced.
2) I made a change to the autoservice code. This is actually something that
has bothered me for a long time. When a channel is in autoservice, _all_
frames get thrown away. However, some frames really shouldn't be thrown
away. The most notable examples are signalling (CONTROL) frames, and DTMF.
So, this patch queues up important frames while a channel is in autoservice.
When autoservice is stopped on the channel, the queued up frames get stuck
back on the channel so that they can get processed instead of thrown away.
3) I made another change to the autoservice code to handle the case where
autoservice is started on channels recursively.
Previously, you could call ast_autoservice_start() multiple times on a
channel, and it would stop the first time ast_autoservice_stop() gets
called. Now, it will ensure that autoservice doesn't actually stop until
the final call to ast_autoservice_stop().
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89791 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-27 22:05:36 +00:00
2007-02-28 20:46:01 +00:00
ast_rdlock_contexts ( ) ;
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
if ( found )
* found = 0 ;
Merged revisions 89790 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r89790 | russell | 2007-11-27 15:45:51 -0600 (Tue, 27 Nov 2007) | 41 lines
Merge changes from team/russell/autoservice_1.4
This set of changes fixes an issue that was reported to me on IRC yesterday.
The user, d1mas, was using chan_zap for incoming calls and was having DTMF
recognition issues in some situations. Specifically, he noticed that the
problem occurred when using DISA or WaitExten. He also noticed that when
using Read, the problem did not occur. His system also used DUNDi for
dialplan lookups.
So, he theorized that if the DUNDi lookups blocked for some period of time,
that audio from the zap channel could get lost. If the audio got lost, then
it wouldn't be run through the DTMF detector, and digits could get lost.
He was correct, and the following set of changes fixes the problem. However,
the changes go a little bit further than what was necessary to fix this exact
problem.
1) I updated pbx_extension_helper() to autoservice the associated channel to
handle cases where extension lookups may take a long time. This would
normally be a dialplan switch that does some lookup over the network, such
as the DUNDi or IAX2 switches.
This ensures that even while a DUNDi lookup is blocking, the channel will be
continuously serviced.
2) I made a change to the autoservice code. This is actually something that
has bothered me for a long time. When a channel is in autoservice, _all_
frames get thrown away. However, some frames really shouldn't be thrown
away. The most notable examples are signalling (CONTROL) frames, and DTMF.
So, this patch queues up important frames while a channel is in autoservice.
When autoservice is stopped on the channel, the queued up frames get stuck
back on the channel so that they can get processed instead of thrown away.
3) I made another change to the autoservice code to handle the case where
autoservice is started on channels recursively.
Previously, you could call ast_autoservice_start() multiple times on a
channel, and it would stop the first time ast_autoservice_stop() gets
called. Now, it will ensure that autoservice doesn't actually stop until
the final call to ast_autoservice_stop().
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89791 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-27 22:05:36 +00:00
2006-05-09 08:31:42 +00:00
e = pbx_find_extension ( c , con , & q , context , exten , priority , label , callerid , action ) ;
2001-03-30 18:47:35 +00:00
if ( e ) {
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
if ( found )
* found = 1 ;
2006-05-09 08:31:42 +00:00
if ( matching_action ) {
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2006-05-09 08:31:42 +00:00
return - 1 ; /* success, we found it */
} else if ( action = = E_FINDLABEL ) { /* map the label to a priority */
2004-10-03 04:19:59 +00:00
res = e - > priority ;
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2006-05-09 08:31:42 +00:00
return res ; /* the priority we were looking for */
} else { /* spawn */
2006-09-28 22:49:55 +00:00
if ( ! e - > cached_app )
e - > cached_app = pbx_findapp ( e - > app ) ;
app = e - > cached_app ;
2013-12-16 16:12:44 +00:00
if ( ast_strlen_zero ( e - > data ) ) {
* passdata = ' \0 ' ;
} else {
const char * tmp ;
if ( ( ! ( tmp = strchr ( e - > data , ' $ ' ) ) ) | | ( ! strstr ( tmp , " ${ " ) & & ! strstr ( tmp , " $[ " ) ) ) {
/* no variables to substitute, copy on through */
ast_copy_string ( passdata , e - > data , sizeof ( passdata ) ) ;
} else {
/* save e->data on stack for later processing after lock released */
substitute = ast_strdupa ( e - > data ) ;
}
}
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2006-05-09 08:31:42 +00:00
if ( ! app ) {
ast_log ( LOG_WARNING , " No application '%s' for extension (%s, %s, %d) \n " , e - > app , context , exten , priority ) ;
return - 1 ;
}
2012-02-13 17:27:06 +00:00
if ( ast_channel_context ( c ) ! = context )
ast_channel_context_set ( c , context ) ;
if ( ast_channel_exten ( c ) ! = exten )
ast_channel_exten_set ( c , exten ) ;
2012-02-20 23:43:27 +00:00
ast_channel_priority_set ( c , priority ) ;
2013-12-16 16:12:44 +00:00
if ( substitute ) {
pbx_substitute_variables_helper ( c , substitute , passdata , sizeof ( passdata ) - 1 ) ;
}
2016-01-05 01:46:25 +00:00
ast_debug ( 1 , " Launching '%s' \n " , app_name ( app ) ) ;
2014-01-14 18:14:02 +00:00
if ( VERBOSITY_ATLEAST ( 3 ) ) {
2013-02-14 18:47:56 +00:00
ast_verb ( 3 , " Executing [%s@%s:%d] " COLORIZE_FMT " ( \" " COLORIZE_FMT " \" , \" " COLORIZE_FMT " \" ) %s \n " ,
2006-06-08 05:24:50 +00:00
exten , context , priority ,
2016-01-05 01:46:25 +00:00
COLORIZE ( COLOR_BRCYAN , 0 , app_name ( app ) ) ,
2013-02-14 18:47:56 +00:00
COLORIZE ( COLOR_BRMAGENTA , 0 , ast_channel_name ( c ) ) ,
COLORIZE ( COLOR_BRMAGENTA , 0 , passdata ) ,
2006-05-09 08:31:42 +00:00
" in new stack " ) ;
}
return pbx_exec ( c , app , passdata ) ; /* 0 on success, -1 on failure */
2001-03-30 18:47:35 +00:00
}
2006-05-09 08:31:42 +00:00
} else if ( q . swo ) { /* not found here, but in another switch */
2008-09-26 17:50:35 +00:00
if ( found )
* found = 1 ;
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
Merged revisions 89790 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r89790 | russell | 2007-11-27 15:45:51 -0600 (Tue, 27 Nov 2007) | 41 lines
Merge changes from team/russell/autoservice_1.4
This set of changes fixes an issue that was reported to me on IRC yesterday.
The user, d1mas, was using chan_zap for incoming calls and was having DTMF
recognition issues in some situations. Specifically, he noticed that the
problem occurred when using DISA or WaitExten. He also noticed that when
using Read, the problem did not occur. His system also used DUNDi for
dialplan lookups.
So, he theorized that if the DUNDi lookups blocked for some period of time,
that audio from the zap channel could get lost. If the audio got lost, then
it wouldn't be run through the DTMF detector, and digits could get lost.
He was correct, and the following set of changes fixes the problem. However,
the changes go a little bit further than what was necessary to fix this exact
problem.
1) I updated pbx_extension_helper() to autoservice the associated channel to
handle cases where extension lookups may take a long time. This would
normally be a dialplan switch that does some lookup over the network, such
as the DUNDi or IAX2 switches.
This ensures that even while a DUNDi lookup is blocking, the channel will be
continuously serviced.
2) I made a change to the autoservice code. This is actually something that
has bothered me for a long time. When a channel is in autoservice, _all_
frames get thrown away. However, some frames really shouldn't be thrown
away. The most notable examples are signalling (CONTROL) frames, and DTMF.
So, this patch queues up important frames while a channel is in autoservice.
When autoservice is stopped on the channel, the queued up frames get stuck
back on the channel so that they can get processed instead of thrown away.
3) I made another change to the autoservice code to handle the case where
autoservice is started on channels recursively.
Previously, you could call ast_autoservice_start() multiple times on a
channel, and it would stop the first time ast_autoservice_stop() gets
called. Now, it will ensure that autoservice doesn't actually stop until
the final call to ast_autoservice_stop().
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89791 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-27 22:05:36 +00:00
if ( matching_action ) {
2004-10-03 04:19:59 +00:00
return - 1 ;
Merged revisions 89790 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r89790 | russell | 2007-11-27 15:45:51 -0600 (Tue, 27 Nov 2007) | 41 lines
Merge changes from team/russell/autoservice_1.4
This set of changes fixes an issue that was reported to me on IRC yesterday.
The user, d1mas, was using chan_zap for incoming calls and was having DTMF
recognition issues in some situations. Specifically, he noticed that the
problem occurred when using DISA or WaitExten. He also noticed that when
using Read, the problem did not occur. His system also used DUNDi for
dialplan lookups.
So, he theorized that if the DUNDi lookups blocked for some period of time,
that audio from the zap channel could get lost. If the audio got lost, then
it wouldn't be run through the DTMF detector, and digits could get lost.
He was correct, and the following set of changes fixes the problem. However,
the changes go a little bit further than what was necessary to fix this exact
problem.
1) I updated pbx_extension_helper() to autoservice the associated channel to
handle cases where extension lookups may take a long time. This would
normally be a dialplan switch that does some lookup over the network, such
as the DUNDi or IAX2 switches.
This ensures that even while a DUNDi lookup is blocking, the channel will be
continuously serviced.
2) I made a change to the autoservice code. This is actually something that
has bothered me for a long time. When a channel is in autoservice, _all_
frames get thrown away. However, some frames really shouldn't be thrown
away. The most notable examples are signalling (CONTROL) frames, and DTMF.
So, this patch queues up important frames while a channel is in autoservice.
When autoservice is stopped on the channel, the queued up frames get stuck
back on the channel so that they can get processed instead of thrown away.
3) I made another change to the autoservice code to handle the case where
autoservice is started on channels recursively.
Previously, you could call ast_autoservice_start() multiple times on a
channel, and it would stop the first time ast_autoservice_stop() gets
called. Now, it will ensure that autoservice doesn't actually stop until
the final call to ast_autoservice_stop().
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89791 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-27 22:05:36 +00:00
} else {
2006-05-09 08:31:42 +00:00
if ( ! q . swo - > exec ) {
ast_log ( LOG_WARNING , " No execution engine for switch %s \n " , q . swo - > name ) ;
2001-09-28 21:20:52 +00:00
res = - 1 ;
}
2006-05-09 08:31:42 +00:00
return q . swo - > exec ( c , q . foundcontext ? q . foundcontext : context , exten , priority , callerid , q . data ) ;
2001-09-28 21:20:52 +00:00
}
2006-05-09 08:31:42 +00:00
} else { /* not found anywhere, see what happened */
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2009-11-11 19:48:18 +00:00
/* Using S_OR here because Solaris doesn't like NULL being passed to ast_log */
2006-05-09 08:31:42 +00:00
switch ( q . status ) {
2001-03-30 18:47:35 +00:00
case STATUS_NO_CONTEXT :
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
if ( ! matching_action & & ! combined_find_spawn )
2009-11-11 19:48:18 +00:00
ast_log ( LOG_NOTICE , " Cannot find extension context '%s' \n " , S_OR ( context , " " ) ) ;
2001-03-30 18:47:35 +00:00
break ;
case STATUS_NO_EXTENSION :
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
if ( ! matching_action & & ! combined_find_spawn )
2009-11-11 19:48:18 +00:00
ast_log ( LOG_NOTICE , " Cannot find extension '%s' in context '%s' \n " , exten , S_OR ( context , " " ) ) ;
2001-03-30 18:47:35 +00:00
break ;
case STATUS_NO_PRIORITY :
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
if ( ! matching_action & & ! combined_find_spawn )
2009-11-11 19:48:18 +00:00
ast_log ( LOG_NOTICE , " No such priority %d in extension '%s' in context '%s' \n " , priority , exten , S_OR ( context , " " ) ) ;
2001-03-30 18:47:35 +00:00
break ;
2004-10-03 04:19:59 +00:00
case STATUS_NO_LABEL :
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
if ( context & & ! combined_find_spawn )
2009-11-11 19:48:18 +00:00
ast_log ( LOG_NOTICE , " No such label '%s' in extension '%s' in context '%s' \n " , label , exten , S_OR ( context , " " ) ) ;
2004-10-03 04:19:59 +00:00
break ;
2001-03-30 18:47:35 +00:00
default :
2007-06-12 16:13:45 +00:00
ast_debug ( 1 , " Shouldn't happen! \n " ) ;
2001-03-30 18:47:35 +00:00
}
2006-05-09 08:03:52 +00:00
2006-05-09 08:31:42 +00:00
return ( matching_action ) ? 0 : - 1 ;
2001-03-30 18:47:35 +00:00
}
1999-12-04 20:45:45 +00:00
}
2001-03-30 18:47:35 +00:00
2007-08-07 23:04:01 +00:00
/*! \brief Find hint for given extension in context */
2008-10-30 00:45:47 +00:00
static struct ast_exten * ast_hint_extension_nolock ( struct ast_channel * c , const char * context , const char * exten )
2003-03-30 22:55:42 +00:00
{
2006-05-09 08:31:42 +00:00
struct pbx_find_info q = { . stacklen = 0 } ; /* the rest is set in pbx_find_context */
2008-10-30 00:45:47 +00:00
return pbx_find_extension ( c , NULL , & q , context , exten , PRIORITY_HINT , NULL , " " , E_MATCH ) ;
}
2003-03-30 22:55:42 +00:00
2008-10-30 00:45:47 +00:00
static struct ast_exten * ast_hint_extension ( struct ast_channel * c , const char * context , const char * exten )
{
struct ast_exten * e ;
2007-02-28 20:46:01 +00:00
ast_rdlock_contexts ( ) ;
2008-10-30 00:45:47 +00:00
e = ast_hint_extension_nolock ( c , context , exten ) ;
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2003-03-30 22:55:42 +00:00
return e ;
}
2009-07-08 22:15:06 +00:00
enum ast_extension_states ast_devstate_to_extenstate ( enum ast_device_state devstate )
{
switch ( devstate ) {
case AST_DEVICE_ONHOLD :
return AST_EXTENSION_ONHOLD ;
case AST_DEVICE_BUSY :
return AST_EXTENSION_BUSY ;
case AST_DEVICE_UNKNOWN :
2010-07-16 18:31:08 +00:00
return AST_EXTENSION_NOT_INUSE ;
case AST_DEVICE_UNAVAILABLE :
2009-07-08 22:15:06 +00:00
case AST_DEVICE_INVALID :
return AST_EXTENSION_UNAVAILABLE ;
case AST_DEVICE_RINGINUSE :
return ( AST_EXTENSION_INUSE | AST_EXTENSION_RINGING ) ;
case AST_DEVICE_RINGING :
return AST_EXTENSION_RINGING ;
case AST_DEVICE_INUSE :
return AST_EXTENSION_INUSE ;
case AST_DEVICE_NOT_INUSE :
return AST_EXTENSION_NOT_INUSE ;
case AST_DEVICE_TOTAL : /* not a device state, included for completeness */
break ;
}
return AST_EXTENSION_NOT_INUSE ;
}
2012-06-04 20:26:12 +00:00
/*!
* \ internal
* \ brief Parse out the presence portion of the hint string
*/
static char * parse_hint_presence ( struct ast_str * hint_args )
{
char * copy = ast_strdupa ( ast_str_buffer ( hint_args ) ) ;
char * tmp = " " ;
if ( ( tmp = strrchr ( copy , ' , ' ) ) ) {
* tmp = ' \0 ' ;
tmp + + ;
} else {
return NULL ;
}
ast_str_set ( & hint_args , 0 , " %s " , tmp ) ;
return ast_str_buffer ( hint_args ) ;
}
/*!
* \ internal
* \ brief Parse out the device portion of the hint string
*/
static char * parse_hint_device ( struct ast_str * hint_args )
{
char * copy = ast_strdupa ( ast_str_buffer ( hint_args ) ) ;
char * tmp ;
if ( ( tmp = strrchr ( copy , ' , ' ) ) ) {
* tmp = ' \0 ' ;
}
ast_str_set ( & hint_args , 0 , " %s " , copy ) ;
return ast_str_buffer ( hint_args ) ;
}
2012-08-09 14:52:16 +00:00
static void device_state_info_dt ( void * obj )
{
struct ast_device_state_info * info = obj ;
ao2_cleanup ( info - > causing_channel ) ;
}
static struct ao2_container * alloc_device_state_info ( void )
{
return ao2_container_alloc_options ( AO2_ALLOC_OPT_LOCK_NOLOCK , 1 , NULL , NULL ) ;
}
static int ast_extension_state3 ( struct ast_str * hint_app , struct ao2_container * device_state_info )
2003-03-30 22:55:42 +00:00
{
2011-07-22 20:46:36 +00:00
char * cur ;
char * rest ;
2008-06-10 14:06:29 +00:00
struct ast_devstate_aggregate agg ;
2003-03-30 22:55:42 +00:00
2011-07-22 20:46:36 +00:00
/* One or more devices separated with a & character */
2012-06-04 20:26:12 +00:00
rest = parse_hint_device ( hint_app ) ;
2005-03-17 21:05:10 +00:00
2008-06-10 14:06:29 +00:00
ast_devstate_aggregate_init ( & agg ) ;
2011-07-22 20:46:36 +00:00
while ( ( cur = strsep ( & rest , " & " ) ) ) {
2012-08-09 14:52:16 +00:00
enum ast_device_state state = ast_device_state ( cur ) ;
ast_devstate_aggregate_add ( & agg , state ) ;
if ( device_state_info ) {
struct ast_device_state_info * obj ;
obj = ao2_alloc_options ( sizeof ( * obj ) + strlen ( cur ) , device_state_info_dt , AO2_ALLOC_OPT_LOCK_NOLOCK ) ;
/* if failed we cannot add this device */
if ( obj ) {
obj - > device_state = state ;
strcpy ( obj - > device_name , cur ) ;
ao2_link ( device_state_info , obj ) ;
ao2_ref ( obj , - 1 ) ;
}
}
2011-07-22 20:46:36 +00:00
}
2008-06-10 14:06:29 +00:00
2011-07-22 20:46:36 +00:00
return ast_devstate_to_extenstate ( ast_devstate_aggregate_result ( & agg ) ) ;
}
2005-03-29 06:16:49 +00:00
2011-07-22 20:46:36 +00:00
/*! \brief Check state of extension by using hints */
2012-08-09 14:52:16 +00:00
static int ast_extension_state2 ( struct ast_exten * e , struct ao2_container * device_state_info )
2011-07-22 20:46:36 +00:00
{
struct ast_str * hint_app = ast_str_thread_get ( & extensionstate_buf , 32 ) ;
2004-07-17 02:25:53 +00:00
2011-07-22 20:46:36 +00:00
if ( ! e | | ! hint_app ) {
return - 1 ;
2009-06-26 19:31:14 +00:00
}
2008-06-10 14:06:29 +00:00
2011-07-22 20:46:36 +00:00
ast_str_set ( & hint_app , 0 , " %s " , ast_get_extension_app ( e ) ) ;
2012-08-09 14:52:16 +00:00
return ast_extension_state3 ( hint_app , device_state_info ) ;
2003-03-30 22:55:42 +00:00
}
2007-08-07 23:04:01 +00:00
/*! \brief Return extension_state as string */
2005-08-29 23:53:29 +00:00
const char * ast_extension_state2str ( int extension_state )
{
int i ;
2008-07-08 16:40:28 +00:00
for ( i = 0 ; ( i < ARRAY_LEN ( extension_states ) ) ; i + + ) {
2006-04-06 16:44:31 +00:00
if ( extension_states [ i ] . extension_state = = extension_state )
2005-08-29 23:53:29 +00:00
return extension_states [ i ] . text ;
}
2006-05-09 08:03:52 +00:00
return " Unknown " ;
2005-08-29 23:53:29 +00:00
}
2003-03-30 22:55:42 +00:00
2013-08-16 17:33:21 +00:00
/*!
* \ internal
* \ brief Check extension state for an extension by using hint
*/
2012-08-09 14:52:16 +00:00
static int internal_extension_state_extended ( struct ast_channel * c , const char * context , const char * exten ,
struct ao2_container * device_state_info )
2003-03-30 22:55:42 +00:00
{
2004-05-09 07:19:00 +00:00
struct ast_exten * e ;
2003-03-30 22:55:42 +00:00
2009-03-11 00:28:28 +00:00
if ( ! ( e = ast_hint_extension ( c , context , exten ) ) ) { /* Do we have a hint for this extension ? */
return - 1 ; /* No hint, return -1 */
}
2003-03-30 22:55:42 +00:00
2010-05-20 22:23:32 +00:00
if ( e - > exten [ 0 ] = = ' _ ' ) {
/* Create this hint on-the-fly */
ast_add_extension ( e - > parent - > name , 0 , exten , e - > priority , e - > label ,
e - > matchcid ? e - > cidmatch : NULL , e - > app , ast_strdup ( e - > data ) , ast_free_ptr ,
e - > registrar ) ;
if ( ! ( e = ast_hint_extension ( c , context , exten ) ) ) {
/* Improbable, but not impossible */
return - 1 ;
}
}
2012-08-09 14:52:16 +00:00
return ast_extension_state2 ( e , device_state_info ) ; /* Check all devices in the hint */
}
/*! \brief Check extension state for an extension by using hint */
int ast_extension_state ( struct ast_channel * c , const char * context , const char * exten )
{
return internal_extension_state_extended ( c , context , exten , NULL ) ;
}
/*! \brief Check extended extension state for an extension by using hint */
int ast_extension_state_extended ( struct ast_channel * c , const char * context , const char * exten ,
struct ao2_container * * device_state_info )
{
struct ao2_container * container = NULL ;
int ret ;
if ( device_state_info ) {
container = alloc_device_state_info ( ) ;
}
ret = internal_extension_state_extended ( c , context , exten , container ) ;
if ( ret < 0 & & container ) {
ao2_ref ( container , - 1 ) ;
container = NULL ;
}
if ( device_state_info ) {
get_device_state_causing_channels ( container ) ;
* device_state_info = container ;
}
return ret ;
2003-03-30 22:55:42 +00:00
}
2012-06-04 20:26:12 +00:00
static int extension_presence_state_helper ( struct ast_exten * e , char * * subtype , char * * message )
{
struct ast_str * hint_app = ast_str_thread_get ( & extensionstate_buf , 32 ) ;
char * presence_provider ;
const char * app ;
if ( ! e | | ! hint_app ) {
return - 1 ;
}
app = ast_get_extension_app ( e ) ;
if ( ast_strlen_zero ( app ) ) {
return - 1 ;
}
ast_str_set ( & hint_app , 0 , " %s " , app ) ;
presence_provider = parse_hint_presence ( hint_app ) ;
if ( ast_strlen_zero ( presence_provider ) ) {
/* No presence string in the hint */
return 0 ;
}
return ast_presence_state ( presence_provider , subtype , message ) ;
}
int ast_hint_presence_state ( struct ast_channel * c , const char * context , const char * exten , char * * subtype , char * * message )
{
struct ast_exten * e ;
if ( ! ( e = ast_hint_extension ( c , context , exten ) ) ) { /* Do we have a hint for this extension ? */
return - 1 ; /* No hint, return -1 */
}
if ( e - > exten [ 0 ] = = ' _ ' ) {
/* Create this hint on-the-fly */
ast_add_extension ( e - > parent - > name , 0 , exten , e - > priority , e - > label ,
e - > matchcid ? e - > cidmatch : NULL , e - > app , ast_strdup ( e - > data ) , ast_free_ptr ,
e - > registrar ) ;
if ( ! ( e = ast_hint_extension ( c , context , exten ) ) ) {
/* Improbable, but not impossible */
return - 1 ;
}
}
return extension_presence_state_helper ( e , subtype , message ) ;
}
static int execute_state_callback ( ast_state_cb_type cb ,
const char * context ,
const char * exten ,
void * data ,
enum ast_state_cb_update_reason reason ,
2012-08-09 14:52:16 +00:00
struct ast_hint * hint ,
struct ao2_container * device_state_info )
2012-06-04 20:26:12 +00:00
{
int res = 0 ;
struct ast_state_cb_info info = { 0 , } ;
info . reason = reason ;
/* Copy over current hint data */
if ( hint ) {
ao2_lock ( hint ) ;
info . exten_state = hint - > laststate ;
2012-08-09 14:52:16 +00:00
info . device_state_info = device_state_info ;
2012-06-04 20:26:12 +00:00
info . presence_state = hint - > last_presence_state ;
if ( ! ( ast_strlen_zero ( hint - > last_presence_subtype ) ) ) {
info . presence_subtype = ast_strdupa ( hint - > last_presence_subtype ) ;
} else {
info . presence_subtype = " " ;
}
if ( ! ( ast_strlen_zero ( hint - > last_presence_message ) ) ) {
info . presence_message = ast_strdupa ( hint - > last_presence_message ) ;
} else {
info . presence_message = " " ;
}
ao2_unlock ( hint ) ;
} else {
info . exten_state = AST_EXTENSION_REMOVED ;
}
2016-04-06 22:57:20 +00:00
res = cb ( context , exten , & info , data ) ;
2012-06-04 20:26:12 +00:00
return res ;
}
2012-08-09 14:52:16 +00:00
/*!
* / internal
* / brief Identify a channel for every device which is supposedly responsible for the device state .
*
* Especially when the device is ringing , the oldest ringing channel is chosen .
* For all other cases the first encountered channel in the specific state is chosen .
*/
static void get_device_state_causing_channels ( struct ao2_container * c )
{
struct ao2_iterator iter ;
struct ast_device_state_info * info ;
struct ast_channel * chan ;
if ( ! c | | ! ao2_container_count ( c ) ) {
return ;
}
iter = ao2_iterator_init ( c , 0 ) ;
for ( ; ( info = ao2_iterator_next ( & iter ) ) ; ao2_ref ( info , - 1 ) ) {
enum ast_channel_state search_state = 0 ; /* prevent false uninit warning */
char match [ AST_CHANNEL_NAME ] ;
struct ast_channel_iterator * chan_iter ;
struct timeval chantime = { 0 , } ; /* prevent false uninit warning */
switch ( info - > device_state ) {
case AST_DEVICE_RINGING :
case AST_DEVICE_RINGINUSE :
/* find ringing channel */
search_state = AST_STATE_RINGING ;
break ;
case AST_DEVICE_BUSY :
/* find busy channel */
search_state = AST_STATE_BUSY ;
break ;
case AST_DEVICE_ONHOLD :
case AST_DEVICE_INUSE :
/* find up channel */
search_state = AST_STATE_UP ;
break ;
case AST_DEVICE_UNKNOWN :
case AST_DEVICE_NOT_INUSE :
case AST_DEVICE_INVALID :
case AST_DEVICE_UNAVAILABLE :
case AST_DEVICE_TOTAL /* not a state */ :
/* no channels are of interest */
continue ;
}
/* iterate over all channels of the device */
snprintf ( match , sizeof ( match ) , " %s- " , info - > device_name ) ;
chan_iter = ast_channel_iterator_by_name_new ( match , strlen ( match ) ) ;
for ( ; ( chan = ast_channel_iterator_next ( chan_iter ) ) ; ast_channel_unref ( chan ) ) {
ast_channel_lock ( chan ) ;
/* this channel's state doesn't match */
if ( search_state ! = ast_channel_state ( chan ) ) {
ast_channel_unlock ( chan ) ;
continue ;
}
/* any non-ringing channel will fit */
if ( search_state ! = AST_STATE_RINGING ) {
ast_channel_unlock ( chan ) ;
info - > causing_channel = chan ; /* is kept ref'd! */
break ;
}
/* but we need the oldest ringing channel of the device to match with undirected pickup */
if ( ! info - > causing_channel ) {
chantime = ast_channel_creationtime ( chan ) ;
ast_channel_ref ( chan ) ; /* must ref it! */
info - > causing_channel = chan ;
} else if ( ast_tvcmp ( ast_channel_creationtime ( chan ) , chantime ) < 0 ) {
chantime = ast_channel_creationtime ( chan ) ;
ast_channel_unref ( info - > causing_channel ) ;
ast_channel_ref ( chan ) ; /* must ref it! */
info - > causing_channel = chan ;
}
ast_channel_unlock ( chan ) ;
}
ast_channel_iterator_destroy ( chan_iter ) ;
}
ao2_iterator_destroy ( & iter ) ;
}
2016-01-08 22:59:44 +00:00
static void device_state_notify_callbacks ( struct ast_hint * hint , struct ast_str * * hint_app )
{
struct ao2_iterator cb_iter ;
struct ast_state_cb * state_cb ;
2016-04-07 15:59:13 +00:00
int state ;
int same_state ;
2016-01-08 22:59:44 +00:00
struct ao2_container * device_state_info ;
int first_extended_cb_call = 1 ;
char context_name [ AST_MAX_CONTEXT ] ;
char exten_name [ AST_MAX_EXTENSION ] ;
ao2_lock ( hint ) ;
if ( ! hint - > exten ) {
/* The extension has already been destroyed */
ao2_unlock ( hint ) ;
return ;
}
/*
* Save off strings in case the hint extension gets destroyed
* while we are notifying the watchers .
*/
ast_copy_string ( context_name ,
ast_get_context_name ( ast_get_extension_context ( hint - > exten ) ) ,
sizeof ( context_name ) ) ;
ast_copy_string ( exten_name , ast_get_extension_name ( hint - > exten ) ,
sizeof ( exten_name ) ) ;
ast_str_set ( hint_app , 0 , " %s " , ast_get_extension_app ( hint - > exten ) ) ;
ao2_unlock ( hint ) ;
/*
* Get device state for this hint .
*
* NOTE : We cannot hold any locks while determining the hint
* device state or notifying the watchers without causing a
* deadlock . ( conlock , hints , and hint )
*/
/* Make a container so state3 can fill it if we wish.
* If that failed we simply do not provide the extended state info .
*/
device_state_info = alloc_device_state_info ( ) ;
state = ast_extension_state3 ( * hint_app , device_state_info ) ;
2016-04-07 15:59:13 +00:00
same_state = state = = hint - > laststate ;
if ( same_state & & ( ~ state & AST_EXTENSION_RINGING ) ) {
2016-01-08 22:59:44 +00:00
ao2_cleanup ( device_state_info ) ;
return ;
}
/* Device state changed since last check - notify the watchers. */
hint - > laststate = state ; /* record we saw the change */
/* For general callbacks */
2016-04-07 15:59:13 +00:00
if ( ! same_state ) {
cb_iter = ao2_iterator_init ( statecbs , 0 ) ;
for ( ; ( state_cb = ao2_iterator_next ( & cb_iter ) ) ; ao2_ref ( state_cb , - 1 ) ) {
execute_state_callback ( state_cb - > change_cb ,
context_name ,
exten_name ,
state_cb - > data ,
AST_HINT_UPDATE_DEVICE ,
hint ,
NULL ) ;
}
ao2_iterator_destroy ( & cb_iter ) ;
2016-01-08 22:59:44 +00:00
}
/* For extension callbacks */
/* extended callbacks are called when the state changed or when AST_STATE_RINGING is
* included . Normal callbacks are only called when the state changed .
*/
cb_iter = ao2_iterator_init ( hint - > callbacks , 0 ) ;
for ( ; ( state_cb = ao2_iterator_next ( & cb_iter ) ) ; ao2_ref ( state_cb , - 1 ) ) {
if ( state_cb - > extended & & first_extended_cb_call ) {
/* Fill detailed device_state_info now that we know it is used by extd. callback */
first_extended_cb_call = 0 ;
get_device_state_causing_channels ( device_state_info ) ;
}
if ( state_cb - > extended | | ! same_state ) {
execute_state_callback ( state_cb - > change_cb ,
2016-04-07 15:59:13 +00:00
context_name ,
exten_name ,
state_cb - > data ,
AST_HINT_UPDATE_DEVICE ,
hint ,
state_cb - > extended ? device_state_info : NULL ) ;
2016-01-08 22:59:44 +00:00
}
}
ao2_iterator_destroy ( & cb_iter ) ;
ao2_cleanup ( device_state_info ) ;
}
static void presence_state_notify_callbacks ( struct ast_hint * hint , struct ast_str * * hint_app ,
struct ast_presence_state_message * presence_state )
{
struct ao2_iterator cb_iter ;
struct ast_state_cb * state_cb ;
char context_name [ AST_MAX_CONTEXT ] ;
char exten_name [ AST_MAX_EXTENSION ] ;
ao2_lock ( hint ) ;
if ( ! hint - > exten ) {
/* The extension has already been destroyed */
ao2_unlock ( hint ) ;
return ;
}
/*
* Save off strings in case the hint extension gets destroyed
* while we are notifying the watchers .
*/
ast_copy_string ( context_name ,
ast_get_context_name ( ast_get_extension_context ( hint - > exten ) ) ,
sizeof ( context_name ) ) ;
ast_copy_string ( exten_name , ast_get_extension_name ( hint - > exten ) ,
sizeof ( exten_name ) ) ;
ast_str_set ( hint_app , 0 , " %s " , ast_get_extension_app ( hint - > exten ) ) ;
ao2_unlock ( hint ) ;
/* Check to see if update is necessary */
if ( ( hint - > last_presence_state = = presence_state - > state ) & &
( ( hint - > last_presence_subtype & & presence_state - > subtype & &
! strcmp ( hint - > last_presence_subtype , presence_state - > subtype ) ) | |
( ! hint - > last_presence_subtype & & ! presence_state - > subtype ) ) & &
( ( hint - > last_presence_message & & presence_state - > message & &
! strcmp ( hint - > last_presence_message , presence_state - > message ) ) | |
( ! hint - > last_presence_message & & ! presence_state - > message ) ) ) {
/* this update is the same as the last, do nothing */
return ;
}
/* update new values */
ast_free ( hint - > last_presence_subtype ) ;
ast_free ( hint - > last_presence_message ) ;
hint - > last_presence_state = presence_state - > state ;
hint - > last_presence_subtype = presence_state - > subtype ? ast_strdup ( presence_state - > subtype ) : NULL ;
hint - > last_presence_message = presence_state - > message ? ast_strdup ( presence_state - > message ) : NULL ;
/* For general callbacks */
cb_iter = ao2_iterator_init ( statecbs , 0 ) ;
for ( ; ( state_cb = ao2_iterator_next ( & cb_iter ) ) ; ao2_ref ( state_cb , - 1 ) ) {
execute_state_callback ( state_cb - > change_cb ,
2016-04-07 15:59:13 +00:00
context_name ,
exten_name ,
state_cb - > data ,
AST_HINT_UPDATE_PRESENCE ,
hint ,
NULL ) ;
2016-01-08 22:59:44 +00:00
}
ao2_iterator_destroy ( & cb_iter ) ;
/* For extension callbacks */
cb_iter = ao2_iterator_init ( hint - > callbacks , 0 ) ;
for ( ; ( state_cb = ao2_iterator_next ( & cb_iter ) ) ; ao2_cleanup ( state_cb ) ) {
execute_state_callback ( state_cb - > change_cb ,
2016-04-07 15:59:13 +00:00
context_name ,
exten_name ,
state_cb - > data ,
AST_HINT_UPDATE_PRESENCE ,
hint ,
NULL ) ;
2016-01-08 22:59:44 +00:00
}
ao2_iterator_destroy ( & cb_iter ) ;
}
static int handle_hint_change_message_type ( struct stasis_message * msg , enum ast_state_cb_update_reason reason )
{
struct ast_hint * hint ;
struct ast_str * hint_app ;
if ( hint_change_message_type ( ) ! = stasis_message_type ( msg ) ) {
return 0 ;
}
if ( ! ( hint_app = ast_str_create ( 1024 ) ) ) {
return - 1 ;
}
hint = stasis_message_data ( msg ) ;
2016-04-07 15:59:13 +00:00
switch ( reason ) {
case AST_HINT_UPDATE_DEVICE :
2016-01-08 22:59:44 +00:00
device_state_notify_callbacks ( hint , & hint_app ) ;
2016-04-07 15:59:13 +00:00
break ;
case AST_HINT_UPDATE_PRESENCE :
{
char * presence_subtype = NULL ;
char * presence_message = NULL ;
int state ;
2016-01-08 22:59:44 +00:00
2016-04-07 15:59:13 +00:00
state = extension_presence_state_helper (
hint - > exten , & presence_subtype , & presence_message ) ;
{
struct ast_presence_state_message presence_state = {
. state = state > 0 ? state : AST_PRESENCE_INVALID ,
. subtype = presence_subtype ,
. message = presence_message
} ;
2016-01-08 22:59:44 +00:00
2016-04-07 15:59:13 +00:00
presence_state_notify_callbacks ( hint , & hint_app , & presence_state ) ;
}
2016-01-08 22:59:44 +00:00
2016-04-07 15:59:13 +00:00
ast_free ( presence_subtype ) ;
ast_free ( presence_message ) ;
}
break ;
2016-01-08 22:59:44 +00:00
}
ast_free ( hint_app ) ;
return 1 ;
}
Multiple revisions 399887,400138,400178,400180-400181
........
r399887 | dlee | 2013-09-26 10:41:47 -0500 (Thu, 26 Sep 2013) | 1 line
Minor performance bump by not allocate manager variable struct if we don't need it
........
r400138 | dlee | 2013-09-30 10:24:00 -0500 (Mon, 30 Sep 2013) | 23 lines
Stasis performance improvements
This patch addresses several performance problems that were found in
the initial performance testing of Asterisk 12.
The Stasis dispatch object was allocated as an AO2 object, even though
it has a very confined lifecycle. This was replaced with a straight
ast_malloc().
The Stasis message router was spending an inordinate amount of time
searching hash tables. In this case, most of our routers had 6 or
fewer routes in them to begin with. This was replaced with an array
that's searched linearly for the route.
We more heavily rely on AO2 objects in Asterisk 12, and the memset()
in ao2_ref() actually became noticeable on the profile. This was
#ifdef'ed to only run when AO2_DEBUG was enabled.
After being misled by an erroneous comment in taskprocessor.c during
profiling, the wrong comment was removed.
Review: https://reviewboard.asterisk.org/r/2873/
........
r400178 | dlee | 2013-09-30 13:26:27 -0500 (Mon, 30 Sep 2013) | 24 lines
Taskprocessor optimization; switch Stasis to use taskprocessors
This patch optimizes taskprocessor to use a semaphore for signaling,
which the OS can do a better job at managing contention and waiting
that we can with a mutex and condition.
The taskprocessor execution was also slightly optimized to reduce the
number of locks taken.
The only observable difference in the taskprocessor implementation is
that when the final reference to the taskprocessor goes away, it will
execute all tasks to completion instead of discarding the unexecuted
tasks.
For systems where unnamed semaphores are not supported, a really
simple semaphore implementation is provided. (Which gives identical
performance as the original taskprocessor implementation).
The way we ended up implementing Stasis caused the threadpool to be a
burden instead of a boost to performance. This was switched to just
use taskprocessors directly for subscriptions.
Review: https://reviewboard.asterisk.org/r/2881/
........
r400180 | dlee | 2013-09-30 13:39:34 -0500 (Mon, 30 Sep 2013) | 28 lines
Optimize how Stasis forwards are dispatched
This patch optimizes how forwards are dispatched in Stasis.
Originally, forwards were dispatched as subscriptions that are invoked
on the publishing thread. This did not account for the vast number of
forwards we would end up having in the system, and the amount of work it
would take to walk though the forward subscriptions.
This patch modifies Stasis so that rather than walking the tree of
forwards on every dispatch, when forwards and subscriptions are changed,
the subscriber list for every topic in the tree is changed.
This has a couple of benefits. First, this reduces the workload of
dispatching messages. It also reduces contention when dispatching to
different topics that happen to forward to the same aggregation topic
(as happens with all of the channel, bridge and endpoint topics).
Since forwards are no longer subscriptions, the bulk of this patch is
simply changing stasis_subscription objects to stasis_forward objects
(which, admittedly, I should have done in the first place.)
Since this required me to yet again put in a growing array, I finally
abstracted that out into a set of ast_vector macros in
asterisk/vector.h.
Review: https://reviewboard.asterisk.org/r/2883/
........
r400181 | dlee | 2013-09-30 13:48:57 -0500 (Mon, 30 Sep 2013) | 28 lines
Remove dispatch object allocation from Stasis publishing
While looking for areas for performance improvement, I realized that an
unused feature in Stasis was negatively impacting performance.
When a message is sent to a subscriber, a dispatch object is allocated
for the dispatch, containing the topic the message was published to, the
subscriber the message is being sent to, and the message itself.
The topic is actually unused by any subscriber in Asterisk today. And
the subscriber is associated with the taskprocessor the message is being
dispatched to.
First, this patch removes the unused topic parameter from Stasis
subscription callbacks.
Second, this patch introduces the concept of taskprocessor local data,
data that may be set on a taskprocessor and provided along with the data
pointer when a task is pushed using the ast_taskprocessor_push_local()
call. This allows the task to have both data specific to that
taskprocessor, in addition to data specific to that invocation.
With those two changes, the dispatch object can be removed completely,
and the message is simply refcounted and sent directly to the
taskprocessor.
Review: https://reviewboard.asterisk.org/r/2884/
........
Merged revisions 399887,400138,400178,400180-400181 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400186 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-09-30 18:55:27 +00:00
static void device_state_cb ( void * unused , struct stasis_subscription * sub , struct stasis_message * msg )
2003-03-30 22:55:42 +00:00
{
2013-04-16 15:33:59 +00:00
struct ast_device_state_message * dev_state ;
2011-07-22 20:46:36 +00:00
struct ast_str * hint_app ;
struct ast_hintdevice * device ;
struct ast_hintdevice * cmpdevice ;
struct ao2_iterator * dev_iter ;
2016-03-28 16:31:29 +00:00
struct ao2_iterator auto_iter ;
struct ast_autohint * autohint ;
char * virtual_device ;
char * type ;
char * device_name ;
2016-01-08 22:59:44 +00:00
if ( handle_hint_change_message_type ( msg , AST_HINT_UPDATE_DEVICE ) ) {
return ;
}
2009-01-21 23:25:27 +00:00
2013-04-16 15:33:59 +00:00
if ( ast_device_state_message_type ( ) ! = stasis_message_type ( msg ) ) {
return ;
}
dev_state = stasis_message_data ( msg ) ;
if ( dev_state - > eid ) {
/* ignore non-aggregate states */
return ;
}
2016-03-28 16:31:29 +00:00
if ( ao2_container_count ( hintdevices ) = = 0 & & ao2_container_count ( autohints ) = = 0 ) {
2011-07-22 20:46:36 +00:00
/* There are no hints monitoring devices. */
2013-04-16 15:33:59 +00:00
return ;
2010-11-30 09:49:25 +00:00
}
2011-07-22 20:46:36 +00:00
hint_app = ast_str_create ( 1024 ) ;
if ( ! hint_app ) {
2013-04-16 15:33:59 +00:00
return ;
2010-09-20 15:57:52 +00:00
}
2013-04-16 15:33:59 +00:00
cmpdevice = ast_alloca ( sizeof ( * cmpdevice ) + strlen ( dev_state - > device ) ) ;
strcpy ( cmpdevice - > hintdevice , dev_state - > device ) ;
2004-07-14 07:44:19 +00:00
2011-07-22 20:46:36 +00:00
ast_mutex_lock ( & context_merge_lock ) ; /* Hold off ast_merge_contexts_and_delete */
2016-03-28 16:31:29 +00:00
/* Initially we find all hints for the device and notify them */
2011-07-22 20:46:36 +00:00
dev_iter = ao2_t_callback ( hintdevices ,
2015-04-29 19:49:23 +00:00
OBJ_SEARCH_OBJECT | OBJ_MULTIPLE ,
2010-11-30 09:49:25 +00:00
hintdevice_cmp_multiple ,
cmpdevice ,
" find devices in container " ) ;
2016-03-28 16:31:29 +00:00
if ( dev_iter ) {
for ( ; ( device = ao2_iterator_next ( dev_iter ) ) ; ao2_t_ref ( device , - 1 , " Next device " ) ) {
if ( device - > hint ) {
device_state_notify_callbacks ( device - > hint , & hint_app ) ;
}
}
ao2_iterator_destroy ( dev_iter ) ;
2011-07-22 20:46:36 +00:00
}
2016-03-28 16:31:29 +00:00
/* Second stage we look for any autohint contexts and if the device is not already in the hints
* we create it .
*/
type = ast_strdupa ( dev_state - > device ) ;
if ( ast_strlen_zero ( type ) ) {
goto end ;
}
/* Determine if this is a virtual/custom device or a real device */
virtual_device = strchr ( type , ' : ' ) ;
device_name = strchr ( type , ' / ' ) ;
if ( virtual_device & & ( ! device_name | | ( virtual_device < device_name ) ) ) {
device_name = virtual_device ;
}
/* Invalid device state name - not a virtual/custom device and not a real device */
if ( ast_strlen_zero ( device_name ) ) {
goto end ;
}
* device_name + + = ' \0 ' ;
auto_iter = ao2_iterator_init ( autohints , 0 ) ;
for ( ; ( autohint = ao2_iterator_next ( & auto_iter ) ) ; ao2_t_ref ( autohint , - 1 , " Next autohint " ) ) {
if ( ast_get_hint ( NULL , 0 , NULL , 0 , NULL , autohint - > context , device_name ) ) {
continue ;
2008-03-19 04:32:13 +00:00
}
2016-03-28 16:31:29 +00:00
/* The device has no hint in the context referenced by this autohint so create one */
ast_add_extension ( autohint - > context , 0 , device_name ,
PRIORITY_HINT , NULL , NULL , dev_state - > device ,
ast_strdup ( dev_state - > device ) , ast_free_ptr , autohint - > registrar ) ;
/* Since this hint was just created there are no watchers, so we don't need to notify anyone */
2004-11-13 22:44:33 +00:00
}
2016-03-28 16:31:29 +00:00
ao2_iterator_destroy ( & auto_iter ) ;
2011-07-22 20:46:36 +00:00
2016-03-28 16:31:29 +00:00
end :
ast_mutex_unlock ( & context_merge_lock ) ;
2011-07-22 20:46:36 +00:00
ast_free ( hint_app ) ;
2013-04-16 15:33:59 +00:00
return ;
Merge major changes to the way device state is passed around Asterisk. The two
places that cared about device states were app_queue and the hint code in pbx.c.
The changes include converting it to use the Asterisk event system, as well as
other efficiency improvements.
* app_queue: This module used to register a callback into devicestate.c to
monitor device state changes. Now, it is just a subscriber to Asterisk
events with the type, device state.
* pbx.c hints: Previously, the device state processing thread in devicestate.c
would call ast_hint_state_changed() each time the state of a device changed.
Then, that code would go looking for all the hints that monitor that device,
and call their callbacks. All of this blocked the device state processing
thread. Now, the hint code is a subscriber of Asterisk events with the
type, device state. Furthermore, when this code receives a device state
change event, it queues it up to be processed by another thread so that it
doesn't block one of the event processing threads.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@66958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-01 23:34:43 +00:00
}
2011-12-23 02:35:13 +00:00
/*!
* \ internal
* \ brief Destroy the given state callback object .
*
* \ param doomed State callback to destroy .
*
* \ return Nothing
*/
static void destroy_state_cb ( void * doomed )
{
struct ast_state_cb * state_cb = doomed ;
if ( state_cb - > destroy_cb ) {
state_cb - > destroy_cb ( state_cb - > id , state_cb - > data ) ;
}
}
2013-08-16 17:33:21 +00:00
/*!
* \ internal
* \ brief Add watcher for extension states with destructor
*/
2012-08-09 14:52:16 +00:00
static int extension_state_add_destroy ( const char * context , const char * exten ,
ast_state_cb_type change_cb , ast_state_cb_destroy_type destroy_cb , void * data , int extended )
2003-03-30 22:55:42 +00:00
{
2006-01-11 04:31:59 +00:00
struct ast_hint * hint ;
2011-01-18 20:40:59 +00:00
struct ast_state_cb * state_cb ;
2004-07-17 02:25:53 +00:00
struct ast_exten * e ;
2011-07-22 20:46:36 +00:00
int id ;
2003-03-30 22:55:42 +00:00
2005-03-17 21:05:10 +00:00
/* If there's no context and extension: add callback to statecbs list */
2004-07-17 02:25:53 +00:00
if ( ! context & & ! exten ) {
2011-12-23 02:35:13 +00:00
/* Prevent multiple adds from adding the same change_cb at the same time. */
2011-07-22 20:46:36 +00:00
ao2_lock ( statecbs ) ;
2003-04-06 18:19:51 +00:00
2011-12-23 02:35:13 +00:00
/* Remove any existing change_cb. */
ao2_find ( statecbs , change_cb , OBJ_UNLINK | OBJ_NODATA ) ;
2006-05-09 08:03:52 +00:00
2011-12-23 02:35:13 +00:00
/* Now insert the change_cb */
if ( ! ( state_cb = ao2_alloc ( sizeof ( * state_cb ) , destroy_state_cb ) ) ) {
2011-07-22 20:46:36 +00:00
ao2_unlock ( statecbs ) ;
2004-07-17 02:25:53 +00:00
return - 1 ;
}
2011-01-18 20:40:59 +00:00
state_cb - > id = 0 ;
2011-12-23 02:35:13 +00:00
state_cb - > change_cb = change_cb ;
state_cb - > destroy_cb = destroy_cb ;
2011-01-18 20:40:59 +00:00
state_cb - > data = data ;
2012-08-09 14:52:16 +00:00
state_cb - > extended = extended ;
2011-01-18 20:40:59 +00:00
ao2_link ( statecbs , state_cb ) ;
2004-07-17 02:25:53 +00:00
2011-07-22 20:46:36 +00:00
ao2_ref ( state_cb , - 1 ) ;
ao2_unlock ( statecbs ) ;
2004-07-17 02:25:53 +00:00
return 0 ;
2005-03-29 06:16:49 +00:00
}
2004-07-17 02:25:53 +00:00
if ( ! context | | ! exten )
return - 1 ;
2005-03-17 21:05:10 +00:00
/* This callback type is for only one hint, so get the hint */
2006-05-09 08:03:52 +00:00
e = ast_hint_extension ( NULL , context , exten ) ;
2004-07-17 02:25:53 +00:00
if ( ! e ) {
return - 1 ;
2003-04-06 18:19:51 +00:00
}
2005-03-29 06:16:49 +00:00
2008-03-19 16:54:12 +00:00
/* 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 ,
2010-01-14 16:52:22 +00:00
e - > matchcid ? e - > cidmatch : NULL , e - > app , ast_strdup ( e - > data ) , ast_free_ptr ,
2008-03-19 16:54:12 +00:00
e - > registrar ) ;
e = ast_hint_extension ( NULL , context , exten ) ;
if ( ! e | | e - > exten [ 0 ] = = ' _ ' ) {
return - 1 ;
}
}
2011-07-22 20:46:36 +00:00
/* Find the hint in the hints container */
ao2_lock ( hints ) ; /* Locked to hold off ast_merge_contexts_and_delete */
2010-11-30 09:49:25 +00:00
hint = ao2_find ( hints , e , 0 ) ;
2006-01-11 04:31:59 +00:00
if ( ! hint ) {
2011-07-22 20:46:36 +00:00
ao2_unlock ( hints ) ;
2004-07-17 02:25:53 +00:00
return - 1 ;
}
2005-03-17 21:05:10 +00:00
/* Now insert the callback in the callback list */
2011-12-23 02:35:13 +00:00
if ( ! ( state_cb = ao2_alloc ( sizeof ( * state_cb ) , destroy_state_cb ) ) ) {
2010-11-30 09:49:25 +00:00
ao2_ref ( hint , - 1 ) ;
2011-07-22 20:46:36 +00:00
ao2_unlock ( hints ) ;
2004-07-17 02:25:53 +00:00
return - 1 ;
2003-04-06 18:19:51 +00:00
}
2011-12-23 02:35:13 +00:00
do {
id = stateid + + ; /* Unique ID for this callback */
/* Do not allow id to ever be -1 or 0. */
} while ( id = = - 1 | | id = = 0 ) ;
2011-07-22 20:46:36 +00:00
state_cb - > id = id ;
2011-12-23 02:35:13 +00:00
state_cb - > change_cb = change_cb ; /* Pointer to callback routine */
state_cb - > destroy_cb = destroy_cb ;
2011-01-18 20:40:59 +00:00
state_cb - > data = data ; /* Data for the callback */
2012-08-09 14:52:16 +00:00
state_cb - > extended = extended ;
2011-01-18 20:40:59 +00:00
ao2_link ( hint - > callbacks , state_cb ) ;
2003-04-06 18:19:51 +00:00
2011-07-22 20:46:36 +00:00
ao2_ref ( state_cb , - 1 ) ;
2010-11-30 09:49:25 +00:00
ao2_ref ( hint , - 1 ) ;
2011-07-22 20:46:36 +00:00
ao2_unlock ( hints ) ;
2008-03-19 04:32:13 +00:00
2011-07-22 20:46:36 +00:00
return id ;
2003-03-30 22:55:42 +00:00
}
2012-08-09 14:52:16 +00:00
int ast_extension_state_add_destroy ( const char * context , const char * exten ,
ast_state_cb_type change_cb , ast_state_cb_destroy_type destroy_cb , void * data )
{
return extension_state_add_destroy ( context , exten , change_cb , destroy_cb , data , 0 ) ;
}
2011-12-23 02:35:13 +00:00
int ast_extension_state_add ( const char * context , const char * exten ,
ast_state_cb_type change_cb , void * data )
{
2012-08-09 14:52:16 +00:00
return extension_state_add_destroy ( context , exten , change_cb , NULL , data , 0 ) ;
}
int ast_extension_state_add_destroy_extended ( const char * context , const char * exten ,
ast_state_cb_type change_cb , ast_state_cb_destroy_type destroy_cb , void * data )
{
return extension_state_add_destroy ( context , exten , change_cb , destroy_cb , data , 1 ) ;
}
int ast_extension_state_add_extended ( const char * context , const char * exten ,
ast_state_cb_type change_cb , void * data )
{
return extension_state_add_destroy ( context , exten , change_cb , NULL , data , 1 ) ;
2011-12-23 02:35:13 +00:00
}
2010-11-30 09:49:25 +00:00
/*! \brief Find Hint by callback id */
static int find_hint_by_cb_id ( void * obj , void * arg , int flags )
{
2011-01-18 20:40:59 +00:00
struct ast_state_cb * state_cb ;
2010-11-30 09:49:25 +00:00
const struct ast_hint * hint = obj ;
int * id = arg ;
2011-01-18 20:40:59 +00:00
if ( ( state_cb = ao2_find ( hint - > callbacks , id , 0 ) ) ) {
ao2_ref ( state_cb , - 1 ) ;
return CMP_MATCH | CMP_STOP ;
2010-11-30 09:49:25 +00:00
}
return 0 ;
}
2011-12-23 02:35:13 +00:00
int ast_extension_state_del ( int id , ast_state_cb_type change_cb )
2003-04-06 18:19:51 +00:00
{
2011-12-23 02:35:13 +00:00
struct ast_state_cb * p_cur ;
2006-05-08 22:53:57 +00:00
int ret = - 1 ;
2005-03-29 06:16:49 +00:00
2006-05-08 22:53:57 +00:00
if ( ! id ) { /* id == 0 is a callback without extension */
2011-12-23 02:35:13 +00:00
if ( ! change_cb ) {
2011-07-22 20:46:36 +00:00
return ret ;
}
2011-12-23 02:35:13 +00:00
p_cur = ao2_find ( statecbs , change_cb , OBJ_UNLINK ) ;
2011-01-18 20:40:59 +00:00
if ( p_cur ) {
ret = 0 ;
ao2_ref ( p_cur , - 1 ) ;
2004-07-17 02:25:53 +00:00
}
2006-05-08 22:53:57 +00:00
} else { /* callback with extension, find the callback based on ID */
struct ast_hint * hint ;
2010-11-30 09:49:25 +00:00
2011-07-22 20:46:36 +00:00
ao2_lock ( hints ) ; /* Locked to hold off ast_merge_contexts_and_delete */
2010-11-30 09:49:25 +00:00
hint = ao2_callback ( hints , 0 , find_hint_by_cb_id , & id ) ;
if ( hint ) {
2011-01-18 20:40:59 +00:00
p_cur = ao2_find ( hint - > callbacks , & id , OBJ_UNLINK ) ;
if ( p_cur ) {
ret = 0 ;
ao2_ref ( p_cur , - 1 ) ;
2006-05-08 22:53:57 +00:00
}
2010-11-30 09:49:25 +00:00
ao2_ref ( hint , - 1 ) ;
2004-07-17 02:25:53 +00:00
}
2011-07-22 20:46:36 +00:00
ao2_unlock ( hints ) ;
2003-04-06 18:19:51 +00:00
}
2008-03-19 04:32:13 +00:00
2006-05-08 22:53:57 +00:00
return ret ;
2003-04-06 18:19:51 +00:00
}
2011-01-18 20:40:59 +00:00
static int hint_id_cmp ( void * obj , void * arg , int flags )
{
const struct ast_state_cb * cb = obj ;
int * id = arg ;
return ( cb - > id = = * id ) ? CMP_MATCH | CMP_STOP : 0 ;
}
2011-07-22 20:46:36 +00:00
/*!
* \ internal
* \ brief Destroy the given hint object .
*
* \ param obj Hint to destroy .
*
* \ return Nothing
*/
static void destroy_hint ( void * obj )
{
struct ast_hint * hint = obj ;
2015-04-29 19:49:23 +00:00
int i ;
2011-07-22 20:46:36 +00:00
if ( hint - > callbacks ) {
struct ast_state_cb * state_cb ;
const char * context_name ;
const char * exten_name ;
if ( hint - > exten ) {
context_name = ast_get_context_name ( ast_get_extension_context ( hint - > exten ) ) ;
exten_name = ast_get_extension_name ( hint - > exten ) ;
hint - > exten = NULL ;
} else {
/* The extension has already been destroyed */
context_name = hint - > context_name ;
exten_name = hint - > exten_name ;
}
2012-06-04 20:26:12 +00:00
hint - > laststate = AST_EXTENSION_DEACTIVATED ;
2011-07-22 20:46:36 +00:00
while ( ( state_cb = ao2_callback ( hint - > callbacks , OBJ_UNLINK , NULL , NULL ) ) ) {
/* Notify with -1 and remove all callbacks */
2012-06-04 20:26:12 +00:00
execute_state_callback ( state_cb - > change_cb ,
context_name ,
exten_name ,
state_cb - > data ,
AST_HINT_UPDATE_DEVICE ,
2012-08-09 14:52:16 +00:00
hint ,
NULL ) ;
2011-07-22 20:46:36 +00:00
ao2_ref ( state_cb , - 1 ) ;
}
ao2_ref ( hint - > callbacks , - 1 ) ;
}
2015-04-29 19:49:23 +00:00
for ( i = 0 ; i < AST_VECTOR_SIZE ( & hint - > devices ) ; i + + ) {
char * device = AST_VECTOR_GET ( & hint - > devices , i ) ;
ast_free ( device ) ;
}
AST_VECTOR_FREE ( & hint - > devices ) ;
2012-06-04 20:26:12 +00:00
ast_free ( hint - > last_presence_subtype ) ;
ast_free ( hint - > last_presence_message ) ;
2011-07-22 20:46:36 +00:00
}
/*! \brief Remove hint from extension */
static int ast_remove_hint ( struct ast_exten * e )
2003-04-06 18:19:51 +00:00
{
2011-07-22 20:46:36 +00:00
/* Cleanup the Notifys if hint is removed */
2006-01-11 04:31:59 +00:00
struct ast_hint * hint ;
2003-04-06 18:19:51 +00:00
2010-11-30 09:49:25 +00:00
if ( ! e ) {
2004-07-17 02:25:53 +00:00
return - 1 ;
2010-11-30 09:49:25 +00:00
}
2005-03-29 06:16:49 +00:00
2011-07-22 20:46:36 +00:00
hint = ao2_find ( hints , e , OBJ_UNLINK ) ;
if ( ! hint ) {
2010-11-30 09:49:25 +00:00
return - 1 ;
2005-03-29 06:16:49 +00:00
}
2004-07-17 02:25:53 +00:00
2011-07-22 20:46:36 +00:00
remove_hintdevice ( hint ) ;
/*
* The extension is being destroyed so we must save some
* information to notify that the extension is deactivated .
*/
ao2_lock ( hint ) ;
ast_copy_string ( hint - > context_name ,
ast_get_context_name ( ast_get_extension_context ( hint - > exten ) ) ,
sizeof ( hint - > context_name ) ) ;
ast_copy_string ( hint - > exten_name , ast_get_extension_name ( hint - > exten ) ,
sizeof ( hint - > exten_name ) ) ;
hint - > exten = NULL ;
ao2_unlock ( hint ) ;
ao2_ref ( hint , - 1 ) ;
return 0 ;
}
/*! \brief Add hint to hint list, check initial extension state */
static int ast_add_hint ( struct ast_exten * e )
{
struct ast_hint * hint_new ;
struct ast_hint * hint_found ;
2012-06-04 20:26:12 +00:00
char * message = NULL ;
char * subtype = NULL ;
int presence_state ;
2005-02-21 06:31:01 +00:00
2011-07-22 20:46:36 +00:00
if ( ! e ) {
2004-07-17 02:25:53 +00:00
return - 1 ;
2003-04-06 18:19:51 +00:00
}
2011-07-22 20:46:36 +00:00
/*
* We must create the hint we wish to add before determining if
* it is already in the hints container to avoid possible
* deadlock when getting the current extension state .
*/
hint_new = ao2_alloc ( sizeof ( * hint_new ) , destroy_hint ) ;
if ( ! hint_new ) {
2011-01-18 20:40:59 +00:00
return - 1 ;
}
2015-04-29 19:49:23 +00:00
AST_VECTOR_INIT ( & hint_new - > devices , 8 ) ;
2010-11-30 09:49:25 +00:00
2011-07-22 20:46:36 +00:00
/* Initialize new hint. */
hint_new - > callbacks = ao2_container_alloc ( 1 , NULL , hint_id_cmp ) ;
if ( ! hint_new - > callbacks ) {
ao2_ref ( hint_new , - 1 ) ;
return - 1 ;
}
hint_new - > exten = e ;
2014-05-29 18:51:41 +00:00
if ( strstr ( e - > app , " ${ " ) & & e - > exten [ 0 ] = = ' _ ' ) {
/* The hint is dynamic and hasn't been evaluted yet */
hint_new - > laststate = AST_DEVICE_INVALID ;
hint_new - > last_presence_state = AST_PRESENCE_INVALID ;
} else {
hint_new - > laststate = ast_extension_state2 ( e , NULL ) ;
if ( ( presence_state = extension_presence_state_helper ( e , & subtype , & message ) ) > 0 ) {
hint_new - > last_presence_state = presence_state ;
hint_new - > last_presence_subtype = subtype ;
hint_new - > last_presence_message = message ;
}
2012-06-04 20:26:12 +00:00
}
2003-04-06 18:19:51 +00:00
2011-07-22 20:46:36 +00:00
/* Prevent multiple add hints from adding the same hint at the same time. */
ao2_lock ( hints ) ;
2003-04-06 18:19:51 +00:00
2011-07-22 20:46:36 +00:00
/* Search if hint exists, do nothing */
hint_found = ao2_find ( hints , e , 0 ) ;
if ( hint_found ) {
ao2_ref ( hint_found , - 1 ) ;
ao2_unlock ( hints ) ;
ao2_ref ( hint_new , - 1 ) ;
ast_debug ( 2 , " HINTS: Not re-adding existing hint %s: %s \n " ,
ast_get_extension_name ( e ) , ast_get_extension_app ( e ) ) ;
return - 1 ;
}
/* Add new hint to the hints container */
ast_debug ( 2 , " HINTS: Adding hint %s: %s \n " ,
ast_get_extension_name ( e ) , ast_get_extension_app ( e ) ) ;
ao2_link ( hints , hint_new ) ;
if ( add_hintdevice ( hint_new , ast_get_extension_app ( e ) ) ) {
2010-11-30 09:49:25 +00:00
ast_log ( LOG_WARNING , " Could not add devices for hint: %s@%s. \n " ,
ast_get_extension_name ( e ) ,
ast_get_context_name ( ast_get_extension_context ( e ) ) ) ;
}
2011-07-22 20:46:36 +00:00
2015-01-19 18:15:03 +00:00
/* if not dynamic */
if ( ! ( strstr ( e - > app , " ${ " ) & & e - > exten [ 0 ] = = ' _ ' ) ) {
struct ast_state_cb * state_cb ;
struct ao2_iterator cb_iter ;
/* For general callbacks */
cb_iter = ao2_iterator_init ( statecbs , 0 ) ;
for ( ; ( state_cb = ao2_iterator_next ( & cb_iter ) ) ; ao2_ref ( state_cb , - 1 ) ) {
execute_state_callback ( state_cb - > change_cb ,
2016-04-07 15:59:13 +00:00
ast_get_context_name ( ast_get_extension_context ( e ) ) ,
ast_get_extension_name ( e ) ,
state_cb - > data ,
AST_HINT_UPDATE_DEVICE ,
hint_new ,
NULL ) ;
2015-01-19 18:15:03 +00:00
}
ao2_iterator_destroy ( & cb_iter ) ;
}
2011-07-22 20:46:36 +00:00
ao2_unlock ( hints ) ;
ao2_ref ( hint_new , - 1 ) ;
2009-03-11 00:28:28 +00:00
2010-11-30 09:49:25 +00:00
return 0 ;
2009-02-18 15:35:26 +00:00
}
2016-01-08 22:59:44 +00:00
/*! \brief Publish a hint changed event */
static int publish_hint_change ( struct ast_hint * hint , struct ast_exten * ne )
2006-05-09 08:03:52 +00:00
{
2016-01-08 22:59:44 +00:00
struct stasis_message * message ;
2005-03-29 06:16:49 +00:00
2016-01-08 22:59:44 +00:00
if ( ! hint_change_message_type ( ) ) {
2011-07-22 20:46:36 +00:00
return - 1 ;
}
2016-01-08 22:59:44 +00:00
/* The message is going to be published to two topics so the hint needs two refs */
if ( ! ( message = stasis_message_create ( hint_change_message_type ( ) , ao2_bump ( hint ) ) ) ) {
ao2_ref ( hint , - 1 ) ;
2015-09-16 13:22:35 +00:00
return - 1 ;
}
2016-01-08 22:59:44 +00:00
stasis_publish ( ast_device_state_topic_all ( ) , message ) ;
stasis_publish ( ast_presence_state_topic_all ( ) , message ) ;
ao2_ref ( message , - 1 ) ;
return 0 ;
}
/*! \brief Change hint for an extension */
static int ast_change_hint ( struct ast_exten * oe , struct ast_exten * ne )
{
struct ast_hint * hint ;
if ( ! oe | | ! ne ) {
return - 1 ;
}
2015-09-16 13:22:35 +00:00
2011-07-22 20:46:36 +00:00
ao2_lock ( hints ) ; /* Locked to hold off others while we move the hint around. */
2010-11-30 09:49:25 +00:00
2011-07-22 20:46:36 +00:00
/*
* Unlink the hint from the hints container as the extension
* name ( which is the hash value ) could change .
*/
hint = ao2_find ( hints , oe , OBJ_UNLINK ) ;
2010-11-30 09:49:25 +00:00
if ( ! hint ) {
2011-07-22 20:46:36 +00:00
ao2_unlock ( hints ) ;
2015-09-16 13:22:35 +00:00
ast_mutex_unlock ( & context_merge_lock ) ;
2010-11-30 09:49:25 +00:00
return - 1 ;
2003-04-06 18:19:51 +00:00
}
2005-12-24 06:23:36 +00:00
2011-07-22 20:46:36 +00:00
remove_hintdevice ( hint ) ;
/* Update the hint and put it back in the hints container. */
2010-11-30 09:49:25 +00:00
ao2_lock ( hint ) ;
hint - > exten = ne ;
2015-09-16 13:22:35 +00:00
2011-07-22 20:46:36 +00:00
ao2_unlock ( hint ) ;
2015-09-16 13:22:35 +00:00
2011-07-22 20:46:36 +00:00
ao2_link ( hints , hint ) ;
2010-11-30 09:49:25 +00:00
if ( add_hintdevice ( hint , ast_get_extension_app ( ne ) ) ) {
ast_log ( LOG_WARNING , " Could not add devices for hint: %s@%s. \n " ,
ast_get_extension_name ( ne ) ,
ast_get_context_name ( ast_get_extension_context ( ne ) ) ) ;
}
2011-07-22 20:46:36 +00:00
ao2_unlock ( hints ) ;
2015-09-16 13:22:35 +00:00
2016-01-08 22:59:44 +00:00
publish_hint_change ( hint , ne ) ;
2015-09-16 13:22:35 +00:00
2010-11-30 09:49:25 +00:00
ao2_ref ( hint , - 1 ) ;
2006-05-09 08:03:52 +00:00
2010-11-30 09:49:25 +00:00
return 0 ;
2003-03-30 22:55:42 +00:00
}
2007-08-07 23:04:01 +00:00
/*! \brief Get hint for channel */
2005-02-01 01:53:25 +00:00
int ast_get_hint ( char * hint , int hintsize , char * name , int namesize , struct ast_channel * c , const char * context , const char * exten )
2003-03-30 22:55:42 +00:00
{
2006-04-06 16:44:31 +00:00
struct ast_exten * e = ast_hint_extension ( c , context , exten ) ;
2005-06-05 16:32:16 +00:00
2005-02-01 01:53:25 +00:00
if ( e ) {
2006-05-09 08:03:52 +00:00
if ( hint )
2006-04-06 16:44:31 +00:00
ast_copy_string ( hint , ast_get_extension_app ( e ) , hintsize ) ;
2005-02-01 01:53:25 +00:00
if ( name ) {
2006-04-06 16:44:31 +00:00
const char * tmp = ast_get_extension_app_data ( e ) ;
2005-02-01 01:53:25 +00:00
if ( tmp )
2006-04-06 16:44:31 +00:00
ast_copy_string ( name , tmp , namesize ) ;
2005-02-01 01:53:25 +00:00
}
2005-12-24 06:23:36 +00:00
return - 1 ;
2003-03-30 22:55:42 +00:00
}
2006-05-09 08:03:52 +00:00
return 0 ;
2003-03-30 22:55:42 +00:00
}
2009-04-29 18:53:01 +00:00
/*! \brief Get hint for channel */
int ast_str_get_hint ( struct ast_str * * hint , ssize_t hintsize , struct ast_str * * name , ssize_t namesize , struct ast_channel * c , const char * context , const char * exten )
{
struct ast_exten * e = ast_hint_extension ( c , context , exten ) ;
if ( ! e ) {
return 0 ;
}
if ( hint ) {
ast_str_set ( hint , hintsize , " %s " , ast_get_extension_app ( e ) ) ;
}
if ( name ) {
const char * tmp = ast_get_extension_app_data ( e ) ;
if ( tmp ) {
ast_str_set ( name , namesize , " %s " , tmp ) ;
}
}
return - 1 ;
}
2006-05-09 08:03:52 +00:00
int ast_exists_extension ( struct ast_channel * c , const char * context , const char * exten , int priority , const char * callerid )
1999-12-04 20:45:45 +00:00
{
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
return pbx_extension_helper ( c , NULL , context , exten , priority , NULL , callerid , E_MATCH , 0 , 0 ) ;
1999-12-04 20:45:45 +00:00
}
2006-05-09 08:03:52 +00:00
int ast_findlabel_extension ( struct ast_channel * c , const char * context , const char * exten , const char * label , const char * callerid )
2000-01-07 10:54:40 +00:00
{
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
return pbx_extension_helper ( c , NULL , context , exten , 0 , label , callerid , E_FINDLABEL , 0 , 0 ) ;
2004-10-03 16:15:44 +00:00
}
2006-05-09 08:03:52 +00:00
int ast_findlabel_extension2 ( struct ast_channel * c , struct ast_context * con , const char * exten , const char * label , const char * callerid )
2004-10-03 16:15:44 +00:00
{
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
return pbx_extension_helper ( c , con , NULL , exten , 0 , label , callerid , E_FINDLABEL , 0 , 0 ) ;
2000-01-07 10:54:40 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_canmatch_extension ( struct ast_channel * c , const char * context , const char * exten , int priority , const char * callerid )
2003-02-02 19:04:14 +00:00
{
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
return pbx_extension_helper ( c , NULL , context , exten , priority , NULL , callerid , E_CANMATCH , 0 , 0 ) ;
2003-02-02 19:04:14 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_matchmore_extension ( struct ast_channel * c , const char * context , const char * exten , int priority , const char * callerid )
1999-12-04 20:45:45 +00:00
{
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
return pbx_extension_helper ( c , NULL , context , exten , priority , NULL , callerid , E_MATCHMORE , 0 , 0 ) ;
2004-10-03 04:19:59 +00:00
}
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
int ast_spawn_extension ( struct ast_channel * c , const char * context , const char * exten , int priority , const char * callerid , int * found , int combined_find_spawn )
2004-10-03 04:19:59 +00:00
{
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
return pbx_extension_helper ( c , NULL , context , exten , priority , NULL , callerid , E_SPAWN , found , combined_find_spawn ) ;
1999-12-04 20:45:45 +00:00
}
2012-06-29 17:02:32 +00:00
void ast_pbx_h_exten_run ( struct ast_channel * chan , const char * context )
{
int autoloopflag ;
int found ;
int spawn_error ;
ast_channel_lock ( chan ) ;
CDRs: fix a variety of dial status problems, h/hangup handler creating CDRs
This patch fixes a number of small-ish problems that were noticed when
witnessing the records that the FreePBX dialplan produces:
(1) Mid-call events (as well as privacy options) have the ability to change the
overall state of the Dial operation after the called party answers. This
means that publishing the DialEnd event when the called party is premature;
we have to wait for the execution of these subroutines to complete before
we can signal the overall status of the DialEnd. This patch moves that
publication and adds handlers for the mid-call events.
(2) The AST_FLAG_OUTGOING channel flag is cleared if an after bridge goto
datastore is detected. This flag was preventing CDRs from being recorded
for all outbound channels that had a 'continue' option enabled on them by
the Dial application.
(3) The CDR engine now locks the 'Dial' application as being the CDR
application if it detects that the current CDR has entered that app. This
is similar to the logic that is done for Parking. In general, if we entered
into Dial, then we want that CDR to record the application as such - this
prevents pre-dial handlers, mid-call handlers, and other shenaniganry
from changing the application value.
(4) The CDR engine now checks for the AST_SOFTHANGUP_HANGUP_EXEC in more places
to determine if the channel is in hangup logic or dead. In either case, we
don't want to record changes in the channel.
(5) The default option for "endbeforehexten" has been changed to "yes". In
general, you don't want to see CDRs in the 'h' exten or in hangup logic.
Since the semantics of that option changed in 12, it made sense to update
the default value as well.
(6) Finally, because we now have the ability to synchronize on the messages
published to the CDR topic, on shutdown the CDR engine will now synchronize
to the messages currently in flight. This helps to ensure that all
in-flight CDRs are written before shutting down.
(closes issue ASTERISK-23164)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3154
........
Merged revisions 407084 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407085 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-31 23:40:51 +00:00
/*
* Make sure that the channel is marked as hungup since we are
* going to run the h exten on it .
*/
ast_softhangup_nolock ( chan , AST_SOFTHANGUP_HANGUP_EXEC ) ;
2012-06-29 17:02:32 +00:00
/* Set h exten location */
if ( context ! = ast_channel_context ( chan ) ) {
ast_channel_context_set ( chan , context ) ;
}
ast_channel_exten_set ( chan , " h " ) ;
ast_channel_priority_set ( chan , 1 ) ;
/* Save autoloop flag */
autoloopflag = ast_test_flag ( ast_channel_flags ( chan ) , AST_FLAG_IN_AUTOLOOP ) ;
ast_set_flag ( ast_channel_flags ( chan ) , AST_FLAG_IN_AUTOLOOP ) ;
ast_channel_unlock ( chan ) ;
for ( ; ; ) {
spawn_error = ast_spawn_extension ( chan , ast_channel_context ( chan ) ,
ast_channel_exten ( chan ) , ast_channel_priority ( chan ) ,
S_COR ( ast_channel_caller ( chan ) - > id . number . valid ,
ast_channel_caller ( chan ) - > id . number . str , NULL ) , & found , 1 ) ;
ast_channel_lock ( chan ) ;
if ( spawn_error ) {
/* The code after the loop needs the channel locked. */
break ;
}
ast_channel_priority_set ( chan , ast_channel_priority ( chan ) + 1 ) ;
ast_channel_unlock ( chan ) ;
}
if ( found & & spawn_error ) {
/* Something bad happened, or a hangup has been requested. */
ast_debug ( 1 , " Spawn extension (%s,%s,%d) exited non-zero on '%s' \n " ,
ast_channel_context ( chan ) , ast_channel_exten ( chan ) ,
ast_channel_priority ( chan ) , ast_channel_name ( chan ) ) ;
ast_verb ( 2 , " Spawn extension (%s, %s, %d) exited non-zero on '%s' \n " ,
ast_channel_context ( chan ) , ast_channel_exten ( chan ) ,
ast_channel_priority ( chan ) , ast_channel_name ( chan ) ) ;
}
/* An "h" exten has been run, so indicate that one has been run. */
ast_set_flag ( ast_channel_flags ( chan ) , AST_FLAG_BRIDGE_HANGUP_RUN ) ;
/* Restore autoloop flag */
ast_set2_flag ( ast_channel_flags ( chan ) , autoloopflag , AST_FLAG_IN_AUTOLOOP ) ;
ast_channel_unlock ( chan ) ;
}
2007-08-07 23:04:01 +00:00
/*! helper function to set extension and priority */
2015-12-29 01:18:01 +00:00
void set_ext_pri ( struct ast_channel * c , const char * exten , int pri )
2006-04-19 09:18:30 +00:00
{
2007-11-26 17:49:47 +00:00
ast_channel_lock ( c ) ;
2012-02-13 17:27:06 +00:00
ast_channel_exten_set ( c , exten ) ;
2012-02-20 23:43:27 +00:00
ast_channel_priority_set ( c , pri ) ;
2007-11-26 17:49:47 +00:00
ast_channel_unlock ( c ) ;
2006-04-19 09:18:30 +00:00
}
2006-05-09 08:31:42 +00:00
/*!
2007-08-07 23:04:01 +00:00
* \ brief collect digits from the channel into the buffer .
2010-06-08 14:38:18 +00:00
* \ param c , buf , buflen , pos
2008-12-08 23:04:49 +00:00
* \ param waittime is in milliseconds
2007-08-07 23:04:01 +00:00
* \ retval 0 on timeout or done .
* \ retval - 1 on error .
*/
2006-05-09 08:31:42 +00:00
static int collect_digits ( struct ast_channel * c , int waittime , char * buf , int buflen , int pos )
1999-12-04 20:45:45 +00:00
{
2005-06-05 15:04:43 +00:00
int digit ;
2006-05-09 08:31:42 +00:00
buf [ pos ] = ' \0 ' ; /* make sure it is properly terminated */
2012-02-13 17:27:06 +00:00
while ( ast_matchmore_extension ( c , ast_channel_context ( c ) , buf , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2006-05-09 08:31:42 +00:00
/* As long as we're willing to wait, and as long as it's not defined,
keep reading digits until we can ' t possibly get a right answer anymore . */
2008-12-08 18:47:32 +00:00
digit = ast_waitfordigit ( c , waittime ) ;
2012-03-01 22:09:18 +00:00
if ( ast_channel_softhangup_internal_flag ( c ) & AST_SOFTHANGUP_ASYNCGOTO ) {
Merged revisions 303549 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
................
r303549 | russell | 2011-01-24 14:51:37 -0600 (Mon, 24 Jan 2011) | 45 lines
Merged revisions 303548 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2
................
r303548 | russell | 2011-01-24 14:49:53 -0600 (Mon, 24 Jan 2011) | 38 lines
Merged revisions 303546 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r303546 | russell | 2011-01-24 14:32:21 -0600 (Mon, 24 Jan 2011) | 31 lines
Fix channel redirect out of MeetMe() and other issues with channel softhangup.
Mantis issue #18585 reports that a channel redirect out of MeetMe() stopped
working properly. This issue includes a patch that resolves the issue by
removing a call to ast_check_hangup() from app_meetme.c. I left that in my
patch, as it doesn't need to be there. However, the rest of the patch fixes
this problem with or without the change to app_meetme.
The key difference between what happens before and after this patch is the
effect of the END_OF_Q control frame. After END_OF_Q is hit in ast_read(),
ast_read() will return NULL. With the ast_check_hangup() removed, app_meetme
sees this which causes it to exit as intended. Checking ast_check_hangup()
caused app_meetme to exit earlier in the process, and the target of the
redirect saw the condition where ast_read() returned NULL.
Removing ast_check_hangup() works around the issue in app_meetme, but doesn't
solve the issue if another application did the same thing. There are also
other edge cases where if an application finishes at the same time that a
redirect happens, the target of the redirect will think that the channel hung
up. So, I made some changes in pbx.c to resolve it at a deeper level. There
are already places that unset the SOFTHANGUP_ASYNCGOTO flag in an attempt to
abort the hangup process. My patch extends this to remove the END_OF_Q frame
from the channel's read queue, making the "abort hangup" more complete. This
same technique was used in every place where a softhangup flag was cleared.
(closes issue #18585)
Reported by: oej
Tested by: oej, wedhorn, russell
Review: https://reviewboard.asterisk.org/r/1082/
........
................
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@303551 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-24 20:57:28 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_ASYNCGOTO ) ;
2006-05-09 08:31:42 +00:00
} else {
if ( ! digit ) /* No entry */
break ;
if ( digit < 0 ) /* Error, maybe a hangup */
return - 1 ;
if ( pos < buflen - 1 ) { /* XXX maybe error otherwise ? */
buf [ pos + + ] = digit ;
buf [ pos ] = ' \0 ' ;
}
2012-02-20 23:43:27 +00:00
waittime = ast_channel_pbx ( c ) - > dtimeoutms ;
2006-05-09 08:31:42 +00:00
}
}
return 0 ;
}
2009-03-11 00:28:28 +00:00
static enum ast_pbx_result __ast_pbx_run ( struct ast_channel * c ,
2008-12-18 19:33:42 +00:00
struct ast_pbx_args * args )
2006-05-09 08:31:42 +00:00
{
int found = 0 ; /* set if we find at least one match */
int res = 0 ;
2005-04-29 15:04:26 +00:00
int autoloopflag ;
2006-05-09 08:31:42 +00:00
int error = 0 ; /* set an error conditions */
2012-02-20 23:43:27 +00:00
struct ast_pbx * pbx ;
2015-03-13 01:12:35 +00:00
ast_callid callid ;
2001-03-30 18:47:35 +00:00
2012-03-16 15:38:45 +00:00
/* A little initial setup here */
if ( ast_channel_pbx ( c ) ) {
ast_log ( LOG_WARNING , " %s already has PBX structure?? \n " , ast_channel_name ( c ) ) ;
/* XXX and now what ? */
ast_free ( ast_channel_pbx ( c ) ) ;
}
if ( ! ( pbx = ast_calloc ( 1 , sizeof ( * pbx ) ) ) ) {
2013-02-09 03:51:32 +00:00
return AST_PBX_FAILED ;
2012-03-16 15:38:45 +00:00
}
2012-05-17 16:28:20 +00:00
2012-05-23 20:39:22 +00:00
callid = ast_read_threadstorage_callid ( ) ;
/* If the thread isn't already associated with a callid, we should create that association. */
if ( ! callid ) {
2012-05-17 16:28:20 +00:00
/* Associate new PBX thread with the channel call id if it is availble.
* If not , create a new one instead .
*/
2012-05-23 20:39:22 +00:00
callid = ast_channel_callid ( c ) ;
if ( ! callid ) {
2012-05-17 16:28:20 +00:00
callid = ast_create_callid ( ) ;
2012-05-23 20:39:22 +00:00
if ( callid ) {
2013-12-18 20:33:37 +00:00
ast_channel_lock ( c ) ;
2012-05-23 20:39:22 +00:00
ast_channel_callid_set ( c , callid ) ;
2013-12-18 20:33:37 +00:00
ast_channel_unlock ( c ) ;
2012-05-23 20:39:22 +00:00
}
2012-05-17 16:28:20 +00:00
}
ast_callid_threadassoc_add ( callid ) ;
2015-03-13 01:12:35 +00:00
callid = 0 ;
2012-05-17 16:28:20 +00:00
}
2012-03-16 15:38:45 +00:00
ast_channel_pbx_set ( c , pbx ) ;
/* Set reasonable defaults */
ast_channel_pbx ( c ) - > rtimeoutms = 10000 ;
ast_channel_pbx ( c ) - > dtimeoutms = 5000 ;
2001-03-30 18:47:35 +00:00
2017-05-13 16:40:00 +00:00
ast_channel_lock ( c ) ;
2012-03-13 18:20:34 +00:00
autoloopflag = ast_test_flag ( ast_channel_flags ( c ) , AST_FLAG_IN_AUTOLOOP ) ; /* save value to restore at the end */
ast_set_flag ( ast_channel_flags ( c ) , AST_FLAG_IN_AUTOLOOP ) ;
2017-05-13 16:40:00 +00:00
ast_channel_unlock ( c ) ;
2005-04-29 15:04:26 +00:00
2012-02-13 17:27:06 +00:00
if ( ast_strlen_zero ( ast_channel_exten ( c ) ) ) {
2011-09-21 09:39:13 +00:00
/* If not successful fall back to 's' - but only if there is no given exten */
2012-02-20 23:43:27 +00:00
ast_verb ( 2 , " Starting %s at %s,%s,%d failed so falling back to exten 's' \n " , ast_channel_name ( c ) , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) ) ;
2006-04-19 09:18:30 +00:00
/* XXX the original code used the existing priority in the call to
* ast_exists_extension ( ) , and reset it to 1 afterwards .
* I believe the correct thing is to set it to 1 immediately .
2011-09-21 09:39:13 +00:00
*/
2006-04-19 09:18:30 +00:00
set_ext_pri ( c , " s " , 1 ) ;
1999-12-04 20:45:45 +00:00
}
2011-09-21 09:39:13 +00:00
2005-12-24 06:23:36 +00:00
for ( ; ; ) {
2006-05-09 08:31:42 +00:00
char dst_exten [ 256 ] ; /* buffer to accumulate digits */
int pos = 0 ; /* XXX should check bounds */
int digit = 0 ;
2008-04-28 16:37:45 +00:00
int invalid = 0 ;
int timeout = 0 ;
2006-05-09 08:31:42 +00:00
2012-10-09 22:24:10 +00:00
/* No digits pressed yet */
dst_exten [ pos ] = ' \0 ' ;
2006-05-09 08:31:42 +00:00
/* loop on priorities in this context/exten */
2012-02-20 23:43:27 +00:00
while ( ! ( res = ast_spawn_extension ( c , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ,
2010-07-14 15:48:36 +00:00
& found , 1 ) ) ) {
2014-06-08 18:12:53 +00:00
2011-04-26 22:18:41 +00:00
if ( ! ast_check_hangup ( c ) ) {
2012-02-20 23:43:27 +00:00
ast_channel_priority_set ( c , ast_channel_priority ( c ) + 1 ) ;
2011-04-26 22:18:41 +00:00
continue ;
}
/* Check softhangup flags. */
2012-03-01 22:09:18 +00:00
if ( ast_channel_softhangup_internal_flag ( c ) & AST_SOFTHANGUP_ASYNCGOTO ) {
Merged revisions 303549 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
................
r303549 | russell | 2011-01-24 14:51:37 -0600 (Mon, 24 Jan 2011) | 45 lines
Merged revisions 303548 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2
................
r303548 | russell | 2011-01-24 14:49:53 -0600 (Mon, 24 Jan 2011) | 38 lines
Merged revisions 303546 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r303546 | russell | 2011-01-24 14:32:21 -0600 (Mon, 24 Jan 2011) | 31 lines
Fix channel redirect out of MeetMe() and other issues with channel softhangup.
Mantis issue #18585 reports that a channel redirect out of MeetMe() stopped
working properly. This issue includes a patch that resolves the issue by
removing a call to ast_check_hangup() from app_meetme.c. I left that in my
patch, as it doesn't need to be there. However, the rest of the patch fixes
this problem with or without the change to app_meetme.
The key difference between what happens before and after this patch is the
effect of the END_OF_Q control frame. After END_OF_Q is hit in ast_read(),
ast_read() will return NULL. With the ast_check_hangup() removed, app_meetme
sees this which causes it to exit as intended. Checking ast_check_hangup()
caused app_meetme to exit earlier in the process, and the target of the
redirect saw the condition where ast_read() returned NULL.
Removing ast_check_hangup() works around the issue in app_meetme, but doesn't
solve the issue if another application did the same thing. There are also
other edge cases where if an application finishes at the same time that a
redirect happens, the target of the redirect will think that the channel hung
up. So, I made some changes in pbx.c to resolve it at a deeper level. There
are already places that unset the SOFTHANGUP_ASYNCGOTO flag in an attempt to
abort the hangup process. My patch extends this to remove the END_OF_Q frame
from the channel's read queue, making the "abort hangup" more complete. This
same technique was used in every place where a softhangup flag was cleared.
(closes issue #18585)
Reported by: oej
Tested by: oej, wedhorn, russell
Review: https://reviewboard.asterisk.org/r/1082/
........
................
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@303551 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-24 20:57:28 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_ASYNCGOTO ) ;
2008-02-11 17:25:04 +00:00
continue ;
2011-04-26 22:18:41 +00:00
}
2012-03-01 22:09:18 +00:00
if ( ast_channel_softhangup_internal_flag ( c ) & AST_SOFTHANGUP_TIMEOUT ) {
2012-02-13 17:27:06 +00:00
if ( ast_exists_extension ( c , ast_channel_context ( c ) , " T " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2011-04-26 22:18:41 +00:00
set_ext_pri ( c , " T " , 1 ) ;
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
2012-02-29 16:52:47 +00:00
memset ( ast_channel_whentohangup ( c ) , 0 , sizeof ( * ast_channel_whentohangup ( c ) ) ) ;
2011-04-26 22:18:41 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_TIMEOUT ) ;
continue ;
2012-02-13 17:27:06 +00:00
} else if ( ast_exists_extension ( c , ast_channel_context ( c ) , " e " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2011-04-26 22:18:41 +00:00
raise_exception ( c , " ABSOLUTETIMEOUT " , 1 ) ;
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
2012-02-29 16:52:47 +00:00
memset ( ast_channel_whentohangup ( c ) , 0 , sizeof ( * ast_channel_whentohangup ( c ) ) ) ;
2011-04-26 22:18:41 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_TIMEOUT ) ;
continue ;
}
/* Call timed out with no special extension to jump to. */
2006-05-09 08:31:42 +00:00
error = 1 ;
break ;
2001-04-27 15:07:56 +00:00
}
2011-04-26 22:18:41 +00:00
ast_debug ( 1 , " Extension %s, priority %d returned normally even though call was hung up \n " ,
2012-02-20 23:43:27 +00:00
ast_channel_exten ( c ) , ast_channel_priority ( c ) ) ;
2011-04-26 22:18:41 +00:00
error = 1 ;
break ;
2006-05-09 08:31:42 +00:00
} /* end while - from here on we can use 'break' to go out */
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
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 ' ;
2008-04-28 16:37:45 +00:00
} else if ( res = = AST_PBX_INCOMPLETE ) {
2012-02-20 23:43:27 +00:00
ast_debug ( 1 , " Spawn extension (%s,%s,%d) exited INCOMPLETE on '%s' \n " , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) , ast_channel_name ( c ) ) ;
ast_verb ( 2 , " Spawn extension (%s, %s, %d) exited INCOMPLETE on '%s' \n " , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) , ast_channel_name ( c ) ) ;
2008-04-28 16:37:45 +00:00
/* Don't cycle on incomplete - this will happen if the only extension that matches is our "incomplete" extension */
2012-02-13 17:27:06 +00:00
if ( ! ast_matchmore_extension ( c , ast_channel_context ( c ) , ast_channel_exten ( c ) , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2008-04-28 16:37:45 +00:00
invalid = 1 ;
} else {
2012-02-13 17:27:06 +00:00
ast_copy_string ( dst_exten , ast_channel_exten ( c ) , sizeof ( dst_exten ) ) ;
2008-04-28 16:37:45 +00:00
digit = 1 ;
pos = strlen ( dst_exten ) ;
}
2007-11-06 23:08:36 +00:00
} else {
2012-02-20 23:43:27 +00:00
ast_debug ( 1 , " Spawn extension (%s,%s,%d) exited non-zero on '%s' \n " , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) , ast_channel_name ( c ) ) ;
ast_verb ( 2 , " Spawn extension (%s, %s, %d) exited non-zero on '%s' \n " , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) , ast_channel_name ( c ) ) ;
2009-03-11 00:28:28 +00:00
2010-07-14 15:48:36 +00:00
if ( ( res = = AST_PBX_ERROR )
2012-02-13 17:27:06 +00:00
& & ast_exists_extension ( c , ast_channel_context ( c ) , " e " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2007-11-06 23:08:36 +00:00
/* if we are already on the 'e' exten, don't jump to it again */
2012-02-13 17:27:06 +00:00
if ( ! strcmp ( ast_channel_exten ( c ) , " e " ) ) {
2012-02-20 23:43:27 +00:00
ast_verb ( 2 , " Spawn extension (%s, %s, %d) exited ERROR while already on 'e' exten on '%s' \n " , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) , ast_channel_name ( c ) ) ;
2007-11-06 23:08:36 +00:00
error = 1 ;
} else {
2011-04-26 22:18:41 +00:00
raise_exception ( c , " ERROR " , 1 ) ;
2007-11-06 23:08:36 +00:00
continue ;
}
}
2009-03-11 00:28:28 +00:00
2012-03-01 22:09:18 +00:00
if ( ast_channel_softhangup_internal_flag ( c ) & AST_SOFTHANGUP_ASYNCGOTO ) {
Merged revisions 303549 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
................
r303549 | russell | 2011-01-24 14:51:37 -0600 (Mon, 24 Jan 2011) | 45 lines
Merged revisions 303548 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2
................
r303548 | russell | 2011-01-24 14:49:53 -0600 (Mon, 24 Jan 2011) | 38 lines
Merged revisions 303546 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r303546 | russell | 2011-01-24 14:32:21 -0600 (Mon, 24 Jan 2011) | 31 lines
Fix channel redirect out of MeetMe() and other issues with channel softhangup.
Mantis issue #18585 reports that a channel redirect out of MeetMe() stopped
working properly. This issue includes a patch that resolves the issue by
removing a call to ast_check_hangup() from app_meetme.c. I left that in my
patch, as it doesn't need to be there. However, the rest of the patch fixes
this problem with or without the change to app_meetme.
The key difference between what happens before and after this patch is the
effect of the END_OF_Q control frame. After END_OF_Q is hit in ast_read(),
ast_read() will return NULL. With the ast_check_hangup() removed, app_meetme
sees this which causes it to exit as intended. Checking ast_check_hangup()
caused app_meetme to exit earlier in the process, and the target of the
redirect saw the condition where ast_read() returned NULL.
Removing ast_check_hangup() works around the issue in app_meetme, but doesn't
solve the issue if another application did the same thing. There are also
other edge cases where if an application finishes at the same time that a
redirect happens, the target of the redirect will think that the channel hung
up. So, I made some changes in pbx.c to resolve it at a deeper level. There
are already places that unset the SOFTHANGUP_ASYNCGOTO flag in an attempt to
abort the hangup process. My patch extends this to remove the END_OF_Q frame
from the channel's read queue, making the "abort hangup" more complete. This
same technique was used in every place where a softhangup flag was cleared.
(closes issue #18585)
Reported by: oej
Tested by: oej, wedhorn, russell
Review: https://reviewboard.asterisk.org/r/1082/
........
................
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@303551 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-24 20:57:28 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_ASYNCGOTO ) ;
2008-02-04 15:16:05 +00:00
continue ;
2011-04-26 22:18:41 +00:00
}
2012-03-01 22:09:18 +00:00
if ( ast_channel_softhangup_internal_flag ( c ) & AST_SOFTHANGUP_TIMEOUT ) {
2012-02-13 17:27:06 +00:00
if ( ast_exists_extension ( c , ast_channel_context ( c ) , " T " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2011-04-26 22:18:41 +00:00
set_ext_pri ( c , " T " , 1 ) ;
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
2012-02-29 16:52:47 +00:00
memset ( ast_channel_whentohangup ( c ) , 0 , sizeof ( * ast_channel_whentohangup ( c ) ) ) ;
2011-04-26 22:18:41 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_TIMEOUT ) ;
continue ;
2012-02-13 17:27:06 +00:00
} else if ( ast_exists_extension ( c , ast_channel_context ( c ) , " e " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2011-04-26 22:18:41 +00:00
raise_exception ( c , " ABSOLUTETIMEOUT " , 1 ) ;
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
2012-02-29 16:52:47 +00:00
memset ( ast_channel_whentohangup ( c ) , 0 , sizeof ( * ast_channel_whentohangup ( c ) ) ) ;
2011-04-26 22:18:41 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_TIMEOUT ) ;
continue ;
}
/* Call timed out with no special extension to jump to. */
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
}
2011-04-26 22:18:41 +00:00
error = 1 ;
break ;
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
}
}
2006-05-09 08:31:42 +00:00
if ( error )
break ;
2007-10-03 22:14:09 +00:00
/*!\note
* We get here on a failure of some kind : non - existing extension or
* hangup . We have options , here . We can either catch the failure
* and continue , or we can drop out entirely . */
2006-05-09 08:31:42 +00:00
2010-07-14 15:48:36 +00:00
if ( invalid
2012-05-07 18:42:48 +00:00
| | ( ast_strlen_zero ( dst_exten ) & &
2012-05-07 18:58:40 +00:00
! ast_exists_extension ( c , ast_channel_context ( c ) , ast_channel_exten ( c ) , 1 ,
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) ) {
2007-10-03 22:14:09 +00:00
/*!\note
* If there is no match at priority 1 , it is not a valid extension anymore .
* Try to continue at " i " ( for invalid ) or " e " ( for exception ) or exit if
* neither exist .
2006-04-19 09:18:30 +00:00
*/
2012-02-13 17:27:06 +00:00
if ( ast_exists_extension ( c , ast_channel_context ( c ) , " i " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2012-04-20 16:04:37 +00:00
ast_verb ( 3 , " Channel '%s' sent to invalid extension: context,exten,priority=%s,%s,%d \n " ,
ast_channel_name ( c ) , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) ) ;
2012-02-13 17:27:06 +00:00
pbx_builtin_setvar_helper ( c , " INVALID_EXTEN " , ast_channel_exten ( c ) ) ;
2006-04-19 09:18:30 +00:00
set_ext_pri ( c , " i " , 1 ) ;
2012-02-13 17:27:06 +00:00
} else if ( ast_exists_extension ( c , ast_channel_context ( c ) , " e " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2011-04-26 22:18:41 +00:00
raise_exception ( c , " INVALID " , 1 ) ;
2001-04-27 15:07:56 +00:00
} else {
2012-04-20 16:04:37 +00:00
ast_log ( LOG_WARNING , " Channel '%s' sent to invalid extension but no invalid handler: context,exten,priority=%s,%s,%d \n " ,
ast_channel_name ( c ) , ast_channel_context ( c ) , ast_channel_exten ( c ) , ast_channel_priority ( c ) ) ;
2006-05-09 08:31:42 +00:00
error = 1 ; /* we know what to do with it */
break ;
2001-04-27 15:07:56 +00:00
}
2012-03-01 22:09:18 +00:00
} else if ( ast_channel_softhangup_internal_flag ( c ) & AST_SOFTHANGUP_TIMEOUT ) {
2003-03-07 06:00:13 +00:00
/* If we get this far with AST_SOFTHANGUP_TIMEOUT, then we know that the "T" extension is next. */
Merged revisions 303549 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
................
r303549 | russell | 2011-01-24 14:51:37 -0600 (Mon, 24 Jan 2011) | 45 lines
Merged revisions 303548 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2
................
r303548 | russell | 2011-01-24 14:49:53 -0600 (Mon, 24 Jan 2011) | 38 lines
Merged revisions 303546 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r303546 | russell | 2011-01-24 14:32:21 -0600 (Mon, 24 Jan 2011) | 31 lines
Fix channel redirect out of MeetMe() and other issues with channel softhangup.
Mantis issue #18585 reports that a channel redirect out of MeetMe() stopped
working properly. This issue includes a patch that resolves the issue by
removing a call to ast_check_hangup() from app_meetme.c. I left that in my
patch, as it doesn't need to be there. However, the rest of the patch fixes
this problem with or without the change to app_meetme.
The key difference between what happens before and after this patch is the
effect of the END_OF_Q control frame. After END_OF_Q is hit in ast_read(),
ast_read() will return NULL. With the ast_check_hangup() removed, app_meetme
sees this which causes it to exit as intended. Checking ast_check_hangup()
caused app_meetme to exit earlier in the process, and the target of the
redirect saw the condition where ast_read() returned NULL.
Removing ast_check_hangup() works around the issue in app_meetme, but doesn't
solve the issue if another application did the same thing. There are also
other edge cases where if an application finishes at the same time that a
redirect happens, the target of the redirect will think that the channel hung
up. So, I made some changes in pbx.c to resolve it at a deeper level. There
are already places that unset the SOFTHANGUP_ASYNCGOTO flag in an attempt to
abort the hangup process. My patch extends this to remove the END_OF_Q frame
from the channel's read queue, making the "abort hangup" more complete. This
same technique was used in every place where a softhangup flag was cleared.
(closes issue #18585)
Reported by: oej
Tested by: oej, wedhorn, russell
Review: https://reviewboard.asterisk.org/r/1082/
........
................
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@303551 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-24 20:57:28 +00:00
ast_channel_clear_softhangup ( c , AST_SOFTHANGUP_TIMEOUT ) ;
2006-05-09 08:31:42 +00:00
} else { /* keypress received, get more digits for a full extension */
int waittime = 0 ;
2001-04-27 15:07:56 +00:00
if ( digit )
2012-02-20 23:43:27 +00:00
waittime = ast_channel_pbx ( c ) - > dtimeoutms ;
2004-10-16 19:46:02 +00:00
else if ( ! autofallthrough )
2012-02-20 23:43:27 +00:00
waittime = ast_channel_pbx ( c ) - > rtimeoutms ;
2006-05-09 08:31:42 +00:00
if ( ! waittime ) {
const char * status = pbx_builtin_getvar_helper ( c , " DIALSTATUS " ) ;
2005-03-14 05:51:20 +00:00
if ( ! status )
status = " UNKNOWN " ;
2012-01-09 22:15:50 +00:00
ast_verb ( 3 , " Auto fallthrough, channel '%s' status is '%s' \n " , ast_channel_name ( c ) , status ) ;
2005-03-14 05:51:20 +00:00
if ( ! strcasecmp ( status , " CONGESTION " ) )
2015-12-29 01:18:01 +00:00
res = indicate_congestion ( c , " 10 " ) ;
2005-03-14 05:51:20 +00:00
else if ( ! strcasecmp ( status , " CHANUNAVAIL " ) )
2015-12-29 01:18:01 +00:00
res = indicate_congestion ( c , " 10 " ) ;
2005-03-14 05:51:20 +00:00
else if ( ! strcasecmp ( status , " BUSY " ) )
2015-12-29 01:18:01 +00:00
res = indicate_busy ( c , " 10 " ) ;
2006-05-09 08:31:42 +00:00
error = 1 ; /* XXX disable message */
break ; /* exit from the 'for' loop */
}
if ( collect_digits ( c , waittime , dst_exten , sizeof ( dst_exten ) , pos ) )
break ;
2008-04-28 16:37:45 +00:00
if ( res = = AST_PBX_INCOMPLETE & & ast_strlen_zero ( & dst_exten [ pos ] ) )
timeout = 1 ;
2010-07-14 15:48:36 +00:00
if ( ! timeout
2012-02-13 17:27:06 +00:00
& & ast_exists_extension ( c , ast_channel_context ( c ) , dst_exten , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) { /* Prepare the next cycle */
2006-05-09 08:31:42 +00:00
set_ext_pri ( c , dst_exten , 1 ) ;
2010-07-14 15:48:36 +00:00
} else {
2006-05-09 08:31:42 +00:00
/* No such extension */
2008-04-28 16:37:45 +00:00
if ( ! timeout & & ! ast_strlen_zero ( dst_exten ) ) {
2006-05-09 08:31:42 +00:00
/* An invalid extension */
2012-02-13 17:27:06 +00:00
if ( ast_exists_extension ( c , ast_channel_context ( c ) , " i " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2012-02-13 17:27:06 +00:00
ast_verb ( 3 , " Invalid extension '%s' in context '%s' on %s \n " , dst_exten , ast_channel_context ( c ) , ast_channel_name ( c ) ) ;
2006-05-09 08:31:42 +00:00
pbx_builtin_setvar_helper ( c , " INVALID_EXTEN " , dst_exten ) ;
set_ext_pri ( c , " i " , 1 ) ;
2012-02-13 17:27:06 +00:00
} else if ( ast_exists_extension ( c , ast_channel_context ( c ) , " e " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2011-04-26 22:18:41 +00:00
raise_exception ( c , " INVALID " , 1 ) ;
2006-05-09 08:31:42 +00:00
} else {
2011-04-26 22:18:41 +00:00
ast_log ( LOG_WARNING ,
" Invalid extension '%s', but no rule 'i' or 'e' in context '%s' \n " ,
2012-02-13 17:27:06 +00:00
dst_exten , ast_channel_context ( c ) ) ;
2006-05-09 08:31:42 +00:00
found = 1 ; /* XXX disable message */
break ;
}
} else {
/* A simple timeout */
2012-02-13 17:27:06 +00:00
if ( ast_exists_extension ( c , ast_channel_context ( c ) , " t " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2012-01-09 22:15:50 +00:00
ast_verb ( 3 , " Timeout on %s \n " , ast_channel_name ( c ) ) ;
2006-05-09 08:31:42 +00:00
set_ext_pri ( c , " t " , 1 ) ;
2012-02-13 17:27:06 +00:00
} else if ( ast_exists_extension ( c , ast_channel_context ( c ) , " e " , 1 ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( c ) - > id . number . valid , ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
2011-04-26 22:18:41 +00:00
raise_exception ( c , " RESPONSETIMEOUT " , 1 ) ;
2006-05-09 08:31:42 +00:00
} else {
2011-04-26 22:18:41 +00:00
ast_log ( LOG_WARNING ,
" Timeout, but no rule 't' or 'e' in context '%s' \n " ,
2012-02-13 17:27:06 +00:00
ast_channel_context ( c ) ) ;
2006-05-09 08:31:42 +00:00
found = 1 ; /* XXX disable message */
break ;
}
}
}
1999-12-04 20:45:45 +00:00
}
}
2008-12-18 19:33:42 +00:00
if ( ! found & & ! error ) {
2012-01-09 22:15:50 +00:00
ast_log ( LOG_WARNING , " Don't know what to do with '%s' \n " , ast_channel_name ( c ) ) ;
2008-12-18 19:33:42 +00:00
}
if ( ! args | | ! args - > no_hangup_chan ) {
2009-10-22 17:11:23 +00:00
ast_softhangup ( c , AST_SOFTHANGUP_APPUNLOAD ) ;
2012-06-29 17:02:32 +00:00
if ( ! ast_test_flag ( ast_channel_flags ( c ) , AST_FLAG_BRIDGE_HANGUP_RUN )
& & ast_exists_extension ( c , ast_channel_context ( c ) , " h " , 1 ,
S_COR ( ast_channel_caller ( c ) - > id . number . valid ,
ast_channel_caller ( c ) - > id . number . str , NULL ) ) ) {
ast_pbx_h_exten_run ( c , ast_channel_context ( c ) ) ;
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
}
2012-06-29 17:02:32 +00:00
ast_pbx_hangup_handler_run ( c ) ;
2002-06-21 01:40:13 +00:00
}
2012-06-29 17:02:32 +00:00
2017-05-13 16:40:00 +00:00
ast_channel_lock ( c ) ;
2012-03-13 18:20:34 +00:00
ast_set2_flag ( ast_channel_flags ( c ) , autoloopflag , AST_FLAG_IN_AUTOLOOP ) ;
ast_clear_flag ( ast_channel_flags ( c ) , AST_FLAG_BRIDGE_HANGUP_RUN ) ; /* from one round to the next, make sure this gets cleared */
2017-05-13 16:40:00 +00:00
ast_channel_unlock ( c ) ;
2012-03-16 15:38:45 +00:00
pbx_destroy ( ast_channel_pbx ( c ) ) ;
ast_channel_pbx_set ( c , NULL ) ;
2008-12-18 19:33:42 +00:00
if ( ! args | | ! args - > no_hangup_chan ) {
2000-01-24 07:14:18 +00:00
ast_hangup ( c ) ;
2008-12-18 19:33:42 +00:00
}
2013-02-09 03:51:32 +00:00
return AST_PBX_SUCCESS ;
2001-03-30 18:47:35 +00:00
}
2009-03-11 00:28:28 +00:00
/*!
2007-08-07 23:04:01 +00:00
* \ brief Increase call count for channel
* \ retval 0 on success
2012-03-22 19:51:16 +00:00
* \ retval non - zero if a configured limit ( maxcalls , maxload , minmemfree ) was reached
2007-08-07 23:04:01 +00:00
*/
2005-09-13 21:59:45 +00:00
static int increase_call_count ( const struct ast_channel * c )
{
int failed = 0 ;
2005-10-26 03:58:32 +00:00
double curloadavg ;
2007-08-01 19:37:59 +00:00
# if defined(HAVE_SYSINFO)
2007-04-11 19:11:32 +00:00
long curfreemem ;
struct sysinfo sys_info ;
2007-04-11 20:59:08 +00:00
# endif
2007-04-11 19:11:32 +00:00
2005-09-13 21:59:45 +00:00
ast_mutex_lock ( & maxcalllock ) ;
2013-08-05 14:35:00 +00:00
if ( ast_option_maxcalls ) {
if ( countcalls > = ast_option_maxcalls ) {
ast_log ( LOG_WARNING , " Maximum call limit of %d calls exceeded by '%s'! \n " , ast_option_maxcalls , ast_channel_name ( c ) ) ;
2005-09-13 21:59:45 +00:00
failed = - 1 ;
}
}
2013-08-05 14:35:00 +00:00
if ( ast_option_maxload ) {
2005-10-26 03:58:32 +00:00
getloadavg ( & curloadavg , 1 ) ;
2013-08-05 14:35:00 +00:00
if ( curloadavg > = ast_option_maxload ) {
ast_log ( LOG_WARNING , " Maximum loadavg limit of %f load exceeded by '%s' (currently %f)! \n " , ast_option_maxload , ast_channel_name ( c ) , curloadavg ) ;
2005-10-26 03:58:32 +00:00
failed = - 1 ;
}
}
2007-08-01 19:37:59 +00:00
# if defined(HAVE_SYSINFO)
2007-04-11 19:11:32 +00:00
if ( option_minmemfree ) {
if ( ! sysinfo ( & sys_info ) ) {
/* make sure that the free system memory is above the configured low watermark
* convert the amount of freeram from mem_units to MB */
2011-05-06 21:07:49 +00:00
curfreemem = sys_info . freeram * sys_info . mem_unit ;
2009-03-11 00:28:28 +00:00
curfreemem / = 1024 * 1024 ;
2007-04-11 19:11:32 +00:00
if ( curfreemem < option_minmemfree ) {
ast_log ( LOG_WARNING , " Available system memory (~%ldMB) is below the configured low watermark (%ldMB) \n " , curfreemem , option_minmemfree ) ;
failed = - 1 ;
}
}
}
2007-04-11 20:59:08 +00:00
# endif
2009-03-11 00:28:28 +00:00
2007-12-07 16:11:05 +00:00
if ( ! failed ) {
2006-05-09 08:03:52 +00:00
countcalls + + ;
2007-12-07 16:11:05 +00:00
totalcalls + + ;
}
2005-09-13 21:59:45 +00:00
ast_mutex_unlock ( & maxcalllock ) ;
return failed ;
}
static void decrease_call_count ( void )
{
ast_mutex_lock ( & maxcalllock ) ;
if ( countcalls > 0 )
countcalls - - ;
ast_mutex_unlock ( & maxcalllock ) ;
}
2006-05-09 08:31:42 +00:00
static void destroy_exten ( struct ast_exten * e )
{
if ( e - > priority = = PRIORITY_HINT )
ast_remove_hint ( e ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( e - > peer_table )
ast_hashtab_destroy ( e - > peer_table , 0 ) ;
if ( e - > peer_label_table )
ast_hashtab_destroy ( e - > peer_label_table , 0 ) ;
2006-05-09 08:31:42 +00:00
if ( e - > datad )
e - > datad ( e - > data ) ;
2007-06-06 21:20:11 +00:00
ast_free ( e ) ;
2006-05-09 08:31:42 +00:00
}
2001-03-30 18:47:35 +00:00
static void * pbx_thread ( void * data )
{
/* Oh joyeous kernel, we're a new thread, with nothing to do but
2005-09-02 18:07:26 +00:00
answer this channel and get it going .
*/
2005-09-13 21:59:45 +00:00
/* NOTE:
The launcher of this function _MUST_ increment ' countcalls '
before invoking the function ; it will be decremented when the
PBX has finished running on the channel
*/
2001-03-30 18:47:35 +00:00
struct ast_channel * c = data ;
2005-09-13 21:59:45 +00:00
2008-12-18 19:33:42 +00:00
__ast_pbx_run ( c , NULL ) ;
2005-09-13 21:59:45 +00:00
decrease_call_count ( ) ;
1999-12-04 20:45:45 +00:00
pthread_exit ( NULL ) ;
2005-09-13 21:59:45 +00:00
2001-03-30 18:47:35 +00:00
return NULL ;
1999-12-04 20:45:45 +00:00
}
2005-09-13 21:59:45 +00:00
enum ast_pbx_result ast_pbx_start ( struct ast_channel * c )
1999-12-04 20:45:45 +00:00
{
pthread_t t ;
2005-09-13 21:59:45 +00:00
1999-12-04 20:45:45 +00:00
if ( ! c ) {
ast_log ( LOG_WARNING , " Asked to start thread on NULL channel? \n " ) ;
2005-09-13 21:59:45 +00:00
return AST_PBX_FAILED ;
1999-12-04 20:45:45 +00:00
}
2006-05-09 08:03:52 +00:00
2011-09-07 07:48:25 +00:00
if ( ! ast_test_flag ( & ast_options , AST_OPT_FLAG_FULLY_BOOTED ) ) {
ast_log ( LOG_WARNING , " PBX requires Asterisk to be fully booted \n " ) ;
return AST_PBX_FAILED ;
}
2005-09-13 21:59:45 +00:00
if ( increase_call_count ( c ) )
return AST_PBX_CALL_LIMIT ;
1999-12-04 20:45:45 +00:00
/* Start a new thread, and get something handling this channel. */
2007-05-24 18:30:19 +00:00
if ( ast_pthread_create_detached ( & t , NULL , pbx_thread , c ) ) {
1999-12-04 20:45:45 +00:00
ast_log ( LOG_WARNING , " Failed to create new channel thread \n " ) ;
2008-12-09 20:30:07 +00:00
decrease_call_count ( ) ;
2005-09-13 21:59:45 +00:00
return AST_PBX_FAILED ;
1999-12-04 20:45:45 +00:00
}
2005-09-13 21:59:45 +00:00
return AST_PBX_SUCCESS ;
1999-12-04 20:45:45 +00:00
}
2001-09-28 21:20:52 +00:00
2008-12-18 19:33:42 +00:00
enum ast_pbx_result ast_pbx_run_args ( struct ast_channel * c , struct ast_pbx_args * args )
2005-05-18 01:49:13 +00:00
{
2005-09-13 21:59:45 +00:00
enum ast_pbx_result res = AST_PBX_SUCCESS ;
2011-09-07 07:48:25 +00:00
if ( ! ast_test_flag ( & ast_options , AST_OPT_FLAG_FULLY_BOOTED ) ) {
ast_log ( LOG_WARNING , " PBX requires Asterisk to be fully booted \n " ) ;
return AST_PBX_FAILED ;
}
2008-12-18 19:33:42 +00:00
if ( increase_call_count ( c ) ) {
2005-09-13 21:59:45 +00:00
return AST_PBX_CALL_LIMIT ;
2008-12-18 19:33:42 +00:00
}
res = __ast_pbx_run ( c , args ) ;
2005-09-13 21:59:45 +00:00
decrease_call_count ( ) ;
2005-05-18 01:49:13 +00:00
return res ;
}
2008-12-18 19:33:42 +00:00
enum ast_pbx_result ast_pbx_run ( struct ast_channel * c )
{
return ast_pbx_run_args ( c , NULL ) ;
}
2005-05-18 01:49:13 +00:00
int ast_active_calls ( void )
{
return countcalls ;
}
2007-12-07 16:11:05 +00:00
int ast_processed_calls ( void )
{
return totalcalls ;
}
2004-10-16 19:46:02 +00:00
int pbx_set_autofallthrough ( int newval )
{
2006-04-06 16:44:31 +00:00
int oldval = autofallthrough ;
autofallthrough = newval ;
2004-10-16 19:46:02 +00:00
return oldval ;
}
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
int pbx_set_extenpatternmatchnew ( int newval )
{
int oldval = extenpatternmatchnew ;
extenpatternmatchnew = newval ;
return oldval ;
}
2008-03-10 21:48:20 +00:00
void pbx_set_overrideswitch ( const char * newval )
{
if ( overrideswitch ) {
ast_free ( overrideswitch ) ;
}
if ( ! ast_strlen_zero ( newval ) ) {
overrideswitch = ast_strdup ( newval ) ;
} else {
overrideswitch = NULL ;
}
}
2009-02-18 15:35:26 +00:00
/*!
* \ brief lookup for a context with a given name ,
* \ retval found context or NULL if not found .
2011-07-08 01:26:01 +00:00
*/
2009-02-18 15:35:26 +00:00
static struct ast_context * find_context ( const char * context )
{
struct fake_context item ;
ast_copy_string ( item . name , context , sizeof ( item . name ) ) ;
2011-07-08 01:26:01 +00:00
return ast_hashtab_lookup ( contexts_table , & item ) ;
2009-02-18 15:35:26 +00:00
}
2007-08-07 23:04:01 +00:00
/*!
* \ brief lookup for a context with a given name ,
* \ retval with conlock held if found .
* \ retval NULL if not found .
2011-07-08 01:26:01 +00:00
*/
2006-04-19 08:52:15 +00:00
static struct ast_context * find_context_locked ( const char * context )
{
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
struct fake_context item ;
2008-03-04 04:26:39 +00:00
ast_copy_string ( item . name , context , sizeof ( item . name ) ) ;
2007-02-28 20:46:01 +00:00
ast_rdlock_contexts ( ) ;
2011-07-08 01:26:01 +00:00
c = ast_hashtab_lookup ( contexts_table , & item ) ;
if ( ! c ) {
2007-11-27 22:14:55 +00:00
ast_unlock_contexts ( ) ;
2011-07-08 01:26:01 +00:00
}
2006-05-08 11:20:19 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return c ;
2006-04-19 08:52:15 +00:00
}
2007-08-07 23:04:01 +00:00
/*!
* \ brief Remove included contexts .
2004-07-17 02:25:53 +00:00
* This function locks contexts list by & conlist , search for the right context
2001-09-28 21:20:52 +00:00
* structure , leave context list locked and call ast_context_remove_include2
* which removes include , unlock contexts list and return . . .
2011-07-08 01:26:01 +00:00
*/
2004-10-03 04:19:59 +00:00
int ast_context_remove_include ( const char * context , const char * include , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2006-04-19 09:31:41 +00:00
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-19 09:31:41 +00:00
if ( c ) {
/* found, remove include from this context ... */
ret = ast_context_remove_include2 ( c , include , registrar ) ;
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2006-04-19 09:31:41 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2007-08-07 23:04:01 +00:00
/*!
* \ brief Locks context , remove included contexts , unlocks context .
2001-09-28 21:20:52 +00:00
* When we call this function , & conlock lock must be locked , because when
* we giving * con argument , some process can remove / change this context
* and after that there can be segfault .
*
2007-08-07 23:04:01 +00:00
* \ retval 0 on success .
* \ retval - 1 on failure .
2001-09-28 21:20:52 +00:00
*/
2004-10-03 04:19:59 +00:00
int ast_context_remove_include2 ( struct ast_context * con , const char * include , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2006-05-08 21:49:22 +00:00
int ret = - 1 ;
2016-07-14 18:51:42 +00:00
int idx ;
2001-09-28 21:20:52 +00:00
2007-02-28 20:46:01 +00:00
ast_wrlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
2006-05-08 21:49:22 +00:00
/* find our include */
2016-07-14 18:51:42 +00:00
for ( idx = 0 ; idx < ast_context_includes_count ( con ) ; idx + + ) {
struct ast_include * i = AST_VECTOR_GET ( & con - > includes , idx ) ;
if ( ! strcmp ( ast_get_include_name ( i ) , include ) & &
( ! registrar | | ! strcmp ( ast_get_include_registrar ( i ) , registrar ) ) ) {
2001-09-28 21:20:52 +00:00
/* remove from list */
(closes issue #12960)
Reported by: mnicholson
Spent most of the day on this bug, and the
solution was so simple. Just had to find and
understand the problem.
The problem was, that the routine to copy
the existing switches, includes, and ignorepats
from the old context to the new one, wasn't
getting called when the context is already
existent. (In other words, if AEL is adding
a new context to the mix, they get copied,
but if pbx_config already defined a context,
then the copy wasn't happening. This made
no sense, so I moved the call to copy the
includes & etc, no matter the case.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@131129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-15 23:36:19 +00:00
ast_verb ( 3 , " Removing inclusion of context '%s' in context '%s; registrar=%s' \n " , include , ast_get_context_name ( con ) , registrar ) ;
2016-07-14 18:51:42 +00:00
AST_VECTOR_REMOVE_ORDERED ( & con - > includes , idx ) ;
2001-09-28 21:20:52 +00:00
/* free include and return */
2016-07-14 07:40:26 +00:00
include_free ( i ) ;
2006-05-08 21:49:22 +00:00
ret = 0 ;
break ;
2001-09-28 21:20:52 +00:00
}
}
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2006-05-08 21:49:22 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2005-11-14 19:00:38 +00:00
/*!
* \ note This function locks contexts list by & conlist , search for the rigt context
2001-09-28 21:20:52 +00:00
* structure , leave context list locked and call ast_context_remove_switch2
* which removes switch , unlock contexts list and return . . .
*/
2004-10-03 04:19:59 +00:00
int ast_context_remove_switch ( const char * context , const char * sw , const char * data , const char * registrar )
1999-12-04 20:45:45 +00:00
{
2005-12-26 21:38:50 +00:00
int ret = - 1 ; /* default error return */
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-19 08:52:15 +00:00
if ( c ) {
2006-05-09 08:03:52 +00:00
/* remove switch from this context ... */
2006-04-19 08:52:15 +00:00
ret = ast_context_remove_switch2 ( c , sw , data , registrar ) ;
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2005-12-26 21:38:50 +00:00
return ret ;
1999-12-04 20:45:45 +00:00
}
2001-09-28 21:20:52 +00:00
2005-11-14 19:00:38 +00:00
/*!
* \ brief This function locks given context , removes switch , unlock context and
* return .
* \ note When we call this function , & conlock lock must be locked , because when
2001-09-28 21:20:52 +00:00
* we giving * con argument , some process can remove / change this context
* and after that there can be segfault .
*
*/
2004-10-03 04:19:59 +00:00
int ast_context_remove_switch2 ( struct ast_context * con , const char * sw , const char * data , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2016-07-16 00:28:16 +00:00
int idx ;
2006-04-19 08:52:15 +00:00
int ret = - 1 ;
2001-09-28 21:20:52 +00:00
2007-02-28 20:46:01 +00:00
ast_wrlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
2006-05-08 11:20:19 +00:00
/* walk switches */
2016-07-16 00:28:16 +00:00
for ( idx = 0 ; idx < ast_context_switches_count ( con ) ; idx + + ) {
struct ast_sw * i = AST_VECTOR_GET ( & con - > alts , idx ) ;
if ( ! strcmp ( ast_get_switch_name ( i ) , sw ) & &
! strcmp ( ast_get_switch_data ( i ) , data ) & &
( ! registrar | | ! strcmp ( ast_get_switch_registrar ( i ) , registrar ) ) ) {
2006-04-19 08:52:15 +00:00
/* found, remove from list */
(closes issue #12960)
Reported by: mnicholson
Spent most of the day on this bug, and the
solution was so simple. Just had to find and
understand the problem.
The problem was, that the routine to copy
the existing switches, includes, and ignorepats
from the old context to the new one, wasn't
getting called when the context is already
existent. (In other words, if AEL is adding
a new context to the mix, they get copied,
but if pbx_config already defined a context,
then the copy wasn't happening. This made
no sense, so I moved the call to copy the
includes & etc, no matter the case.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@131129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-15 23:36:19 +00:00
ast_verb ( 3 , " Removing switch '%s' from context '%s; registrar=%s' \n " , sw , ast_get_context_name ( con ) , registrar ) ;
2016-07-16 00:28:16 +00:00
AST_VECTOR_REMOVE_ORDERED ( & con - > alts , idx ) ;
/* free switch and return */
sw_free ( i ) ;
2006-04-19 08:52:15 +00:00
ret = 0 ;
break ;
2001-09-28 21:20:52 +00:00
}
}
2006-05-08 11:20:19 +00:00
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2006-05-08 11:20:19 +00:00
2006-04-19 08:52:15 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2011-07-08 01:26:01 +00:00
/*! \note This function will lock conlock. */
2004-10-03 04:19:59 +00:00
int ast_context_remove_extension ( const char * context , const char * extension , int priority , const char * registrar )
2008-07-04 16:06:34 +00:00
{
2013-10-25 20:51:13 +00:00
return ast_context_remove_extension_callerid ( context , extension , priority , NULL , AST_EXT_MATCHCID_ANY , registrar ) ;
2008-07-04 16:06:34 +00:00
}
2008-08-10 20:23:50 +00:00
int ast_context_remove_extension_callerid ( const char * context , const char * extension , int priority , const char * callerid , int matchcallerid , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2005-12-26 21:38:50 +00:00
int ret = - 1 ; /* default error return */
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-19 08:52:15 +00:00
if ( c ) { /* ... remove extension ... */
2011-07-08 01:26:01 +00:00
ret = ast_context_remove_extension_callerid2 ( c , extension , priority , callerid ,
matchcallerid , registrar , 0 ) ;
2006-04-19 08:52:15 +00:00
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2011-07-08 01:26:01 +00:00
2005-12-26 21:38:50 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2005-11-14 19:00:38 +00:00
/*!
* \ brief This functionc locks given context , search for the right extension and
2001-09-28 21:20:52 +00:00
* fires out all peer in this extensions with given priority . If priority
* is set to 0 , all peers are removed . After that , unlock context and
* return .
2005-11-14 19:00:38 +00:00
* \ note When do you want to call this function , make sure that & conlock is locked ,
* because some process can handle with your * con context before you lock
* it .
*
2001-09-28 21:20:52 +00:00
*/
2008-06-16 20:43:46 +00:00
int ast_context_remove_extension2 ( struct ast_context * con , const char * extension , int priority , const char * registrar , int already_locked )
2008-07-04 16:06:34 +00:00
{
2013-10-25 20:51:13 +00:00
return ast_context_remove_extension_callerid2 ( con , extension , priority , NULL , AST_EXT_MATCHCID_ANY , registrar , already_locked ) ;
2008-07-04 16:06:34 +00:00
}
2008-08-10 20:23:50 +00:00
int ast_context_remove_extension_callerid2 ( struct ast_context * con , const char * extension , int priority , const char * callerid , int matchcallerid , const char * registrar , int already_locked )
2001-09-28 21:20:52 +00:00
{
struct ast_exten * exten , * prev_exten = NULL ;
2006-05-09 08:31:42 +00:00
struct ast_exten * peer ;
2007-11-21 20:38:00 +00:00
struct ast_exten ex , * exten2 , * exten3 ;
char dummy_name [ 1024 ] ;
2016-07-28 19:10:04 +00:00
char dummy_cid [ 1024 ] ;
2008-07-04 16:06:34 +00:00
struct ast_exten * previous_peer = NULL ;
struct ast_exten * next_peer = NULL ;
int found = 0 ;
2001-09-28 21:20:52 +00:00
2008-06-16 20:43:46 +00:00
if ( ! already_locked )
ast_wrlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
2007-11-21 01:09:47 +00:00
# ifdef NEED_DEBUG
2008-08-10 20:23:50 +00:00
ast_verb ( 3 , " Removing %s/%s/%d%s%s from trees, registrar=%s \n " , con - > name , extension , priority , matchcallerid ? " / " : " " , matchcallerid ? callerid : " " , registrar ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
# endif
# ifdef CONTEXT_DEBUG
check_contexts ( __FILE__ , __LINE__ ) ;
2007-11-21 01:09:47 +00:00
# endif
2007-11-21 20:38:00 +00:00
/* find this particular extension */
ex . exten = dummy_name ;
2016-07-28 19:10:04 +00:00
ext_strncpy ( dummy_name , extension , sizeof ( dummy_name ) , 1 ) ;
2013-10-25 20:51:13 +00:00
ex . matchcid = matchcallerid ;
2016-07-28 19:10:04 +00:00
if ( callerid ) {
ex . cidmatch = dummy_cid ;
ext_strncpy ( dummy_cid , callerid , sizeof ( dummy_cid ) , 1 ) ;
} else {
ex . cidmatch = NULL ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
exten = ast_hashtab_lookup ( con - > root_table , & ex ) ;
2007-11-21 20:38:00 +00:00
if ( exten ) {
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( priority = = 0 ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
exten2 = ast_hashtab_remove_this_object ( con - > root_table , exten ) ;
2007-11-21 20:38:00 +00:00
if ( ! exten2 )
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_log ( LOG_ERROR , " Trying to delete the exten %s from context %s, but could not remove from the root_table \n " , extension , con - > name ) ;
2007-11-21 20:38:00 +00:00
if ( con - > pattern_tree ) {
2007-11-19 22:55:38 +00:00
struct match_char * x = add_exten_to_pattern_tree ( con , exten , 1 ) ;
2009-03-11 00:28:28 +00:00
2007-11-16 23:33:32 +00:00
if ( x - > exten ) { /* this test for safety purposes */
x - > deleted = 1 ; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
x - > exten = 0 ; /* get rid of what will become a bad pointer */
} else {
ast_log ( LOG_WARNING , " Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension \n " ) ;
}
2007-11-21 20:38:00 +00:00
}
} else {
ex . priority = priority ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
exten2 = ast_hashtab_lookup ( exten - > peer_table , & ex ) ;
2007-11-21 20:38:00 +00:00
if ( exten2 ) {
if ( exten2 - > label ) { /* if this exten has a label, remove that, too */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
exten3 = ast_hashtab_remove_this_object ( exten - > peer_label_table , exten2 ) ;
2016-07-28 19:10:04 +00:00
if ( ! exten3 ) {
ast_log ( LOG_ERROR , " Did not remove this priority label (%d/%s) "
" from the peer_label_table of context %s, extension %s! \n " ,
priority , exten2 - > label , con - > name , exten2 - > name ) ;
}
2007-11-21 20:38:00 +00:00
}
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
exten3 = ast_hashtab_remove_this_object ( exten - > peer_table , exten2 ) ;
2016-07-28 19:10:04 +00:00
if ( ! exten3 ) {
ast_log ( LOG_ERROR , " Did not remove this priority (%d) from the "
" peer_table of context %s, extension %s! \n " ,
priority , con - > name , exten2 - > name ) ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( exten2 = = exten & & exten2 - > peer ) {
exten2 = ast_hashtab_remove_this_object ( con - > root_table , exten ) ;
ast_hashtab_insert_immediate ( con - > root_table , exten2 - > peer ) ;
}
if ( ast_hashtab_size ( exten - > peer_table ) = = 0 ) {
2007-11-21 20:38:00 +00:00
/* well, if the last priority of an exten is to be removed,
then , the extension is removed , too ! */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
exten3 = ast_hashtab_remove_this_object ( con - > root_table , exten ) ;
2016-07-28 19:10:04 +00:00
if ( ! exten3 ) {
ast_log ( LOG_ERROR , " Did not remove this exten (%s) from the "
" context root_table (%s) (priority %d) \n " ,
exten - > name , con - > name , priority ) ;
}
2007-11-21 20:38:00 +00:00
if ( con - > pattern_tree ) {
2007-11-19 22:55:38 +00:00
struct match_char * x = add_exten_to_pattern_tree ( con , exten , 1 ) ;
2007-11-17 17:46:36 +00:00
if ( x - > exten ) { /* this test for safety purposes */
x - > deleted = 1 ; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
x - > exten = 0 ; /* get rid of what will become a bad pointer */
}
}
2007-11-16 23:33:32 +00:00
}
2007-11-21 20:38:00 +00:00
} else {
ast_log ( LOG_ERROR , " Could not find priority %d of exten %s in context %s! \n " ,
2016-07-28 19:10:04 +00:00
priority , exten - > name , con - > name ) ;
2007-11-16 23:33:32 +00:00
}
}
2007-11-21 20:38:00 +00:00
} else {
/* hmmm? this exten is not in this pattern tree? */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_log ( LOG_WARNING , " Cannot find extension %s in root_table in context %s \n " ,
2007-11-21 20:38:00 +00:00
extension , con - > name ) ;
}
2007-11-21 01:09:47 +00:00
# ifdef NEED_DEBUG
2007-11-21 20:38:00 +00:00
if ( con - > pattern_tree ) {
2007-11-21 01:09:47 +00:00
ast_log ( LOG_NOTICE , " match char tree after exten removal: \n " ) ;
log_match_char_tree ( con - > pattern_tree , " " ) ;
2007-11-16 23:33:32 +00:00
}
2007-11-21 20:38:00 +00:00
# endif
2007-11-16 23:33:32 +00:00
2008-07-04 16:06:34 +00:00
/* scan the extension list to find first matching extension-registrar */
2006-05-09 08:31:42 +00:00
for ( exten = con - > root ; exten ; prev_exten = exten , exten = exten - > next ) {
2016-07-28 19:10:04 +00:00
if ( ! strcmp ( exten - > exten , ex . exten ) & &
2016-08-12 04:30:27 +00:00
( ! matchcallerid | |
( ! ast_strlen_zero ( ex . cidmatch ) & & ! ast_strlen_zero ( exten - > cidmatch ) & & ! strcmp ( exten - > cidmatch , ex . cidmatch ) ) | |
( ast_strlen_zero ( ex . cidmatch ) & & ast_strlen_zero ( exten - > cidmatch ) ) ) ) {
2006-05-09 08:31:42 +00:00
break ;
2016-08-12 04:30:27 +00:00
}
2006-05-09 08:31:42 +00:00
}
if ( ! exten ) {
/* we can't find right extension */
2008-06-16 20:43:46 +00:00
if ( ! already_locked )
ast_unlock_context ( con ) ;
2006-05-09 08:31:42 +00:00
return - 1 ;
}
2001-09-28 21:20:52 +00:00
2008-07-04 16:06:34 +00:00
/* scan the priority list to remove extension with exten->priority == priority */
for ( peer = exten , next_peer = exten - > peer ? exten - > peer : exten - > next ;
2016-07-28 19:10:04 +00:00
peer & & ! strcmp ( peer - > exten , ex . exten ) & &
2016-08-12 04:30:27 +00:00
( ! callerid | | ( ! matchcallerid & & ! peer - > matchcid ) | | ( matchcallerid & & peer - > matchcid & & ! strcmp ( peer - > cidmatch , ex . cidmatch ) ) ) ;
2008-07-04 16:06:34 +00:00
peer = next_peer , next_peer = next_peer ? ( next_peer - > peer ? next_peer - > peer : next_peer - > next ) : NULL ) {
2013-10-25 20:51:13 +00:00
2008-07-04 16:06:34 +00:00
if ( ( priority = = 0 | | peer - > priority = = priority ) & &
( ! registrar | | ! strcmp ( peer - > registrar , registrar ) ) ) {
found = 1 ;
/* we are first priority extension? */
if ( ! previous_peer ) {
/*
* We are first in the priority chain , so must update the extension chain .
* The next node is either the next priority or the next extension
*/
struct ast_exten * next_node = peer - > peer ? peer - > peer : peer - > next ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( peer - > peer ) {
/* move the peer_table and peer_label_table down to the next peer, if
it is there */
peer - > peer - > peer_table = peer - > peer_table ;
peer - > peer - > peer_label_table = peer - > peer_label_table ;
peer - > peer_table = NULL ;
peer - > peer_label_table = NULL ;
}
2008-07-04 16:06:34 +00:00
if ( ! prev_exten ) { /* change the root... */
con - > root = next_node ;
} else {
prev_exten - > next = next_node ; /* unlink */
}
if ( peer - > peer ) { /* update the new head of the pri list */
peer - > peer - > next = peer - > next ;
}
} else { /* easy, we are not first priority in extension */
previous_peer - > peer = peer - > peer ;
2007-11-17 17:46:36 +00:00
}
2001-09-28 21:20:52 +00:00
2013-10-25 20:51:13 +00:00
2008-07-04 16:06:34 +00:00
/* now, free whole priority extension */
destroy_exten ( peer ) ;
} else {
previous_peer = peer ;
}
2001-09-28 21:20:52 +00:00
}
2008-06-16 20:43:46 +00:00
if ( ! already_locked )
ast_unlock_context ( con ) ;
2008-07-04 16:06:34 +00:00
return found ? 0 : - 1 ;
2001-09-28 21:20:52 +00:00
}
2006-08-14 03:24:06 +00:00
/*!
* \ note This function locks contexts list by & conlist , searches for the right context
* structure , and locks the macrolock mutex in that context .
* macrolock is used to limit a macro to be executed by one call at a time .
2012-08-30 14:23:28 +00:00
* \ param context The context
2006-08-14 03:24:06 +00:00
*/
int ast_context_lockmacro ( const char * context )
{
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2006-08-14 03:24:06 +00:00
int ret = - 1 ;
2009-02-18 06:00:40 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
if ( c ) {
ast_unlock_contexts ( ) ;
2006-08-14 03:24:06 +00:00
2011-07-08 01:26:01 +00:00
/* if we found context, lock macrolock */
2006-08-14 03:24:06 +00:00
ret = ast_mutex_lock ( & c - > macrolock ) ;
2009-03-11 00:28:28 +00:00
}
2006-08-14 03:24:06 +00:00
return ret ;
}
/*!
* \ note This function locks contexts list by & conlist , searches for the right context
* structure , and unlocks the macrolock mutex in that context .
* macrolock is used to limit a macro to be executed by one call at a time .
2012-08-30 14:23:28 +00:00
* \ param context The context
2006-08-14 03:24:06 +00:00
*/
int ast_context_unlockmacro ( const char * context )
{
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2006-08-14 03:24:06 +00:00
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
if ( c ) {
ast_unlock_contexts ( ) ;
2006-08-14 03:24:06 +00:00
2011-07-08 01:26:01 +00:00
/* if we found context, unlock macrolock */
2006-08-14 03:24:06 +00:00
ret = ast_mutex_unlock ( & c - > macrolock ) ;
2009-03-11 00:28:28 +00:00
}
2006-08-14 03:24:06 +00:00
return ret ;
}
2001-09-28 21:20:52 +00:00
/*
* Help for CLI commands . . .
*/
2006-10-26 17:52:15 +00:00
/*! \brief handle_show_hints: CLI support for listing registered dial plan hints */
2007-09-18 22:43:45 +00:00
static char * handle_show_hints ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
2005-02-21 06:31:01 +00:00
{
struct ast_hint * hint ;
int num = 0 ;
2005-08-27 23:55:14 +00:00
int watchers ;
2010-11-30 09:49:25 +00:00
struct ao2_iterator i ;
2014-06-10 22:31:04 +00:00
char buf [ AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2 ] ;
2005-02-21 06:31:01 +00:00
2007-09-18 22:43:45 +00:00
switch ( cmd ) {
case CLI_INIT :
e - > command = " core show hints " ;
2009-03-11 00:28:28 +00:00
e - > usage =
2007-09-18 22:43:45 +00:00
" Usage: core show hints \n "
2014-06-12 21:27:02 +00:00
" List registered hints. \n "
" Hint details are shown in five columns. In order from left to right, they are: \n "
" 1. Hint extension URI. \n "
" 2. List of mapped device or presence state identifiers. \n "
" 3. Current extension state. The aggregate of mapped device states. \n "
" 4. Current presence state for the mapped presence state provider. \n "
" 5. Watchers - number of subscriptions and other entities watching this hint. \n " ;
2007-09-18 22:43:45 +00:00
return NULL ;
case CLI_GENERATE :
2009-03-11 00:28:28 +00:00
return NULL ;
2007-09-18 22:43:45 +00:00
}
2010-11-30 09:49:25 +00:00
if ( ao2_container_count ( hints ) = = 0 ) {
2007-09-18 22:43:45 +00:00
ast_cli ( a - > fd , " There are no registered dialplan hints \n " ) ;
return CLI_SUCCESS ;
2005-02-21 06:31:01 +00:00
}
/* ... we have hints ... */
2007-09-18 22:43:45 +00:00
ast_cli ( a - > fd , " \n -= Registered Asterisk Dial Plan Hints =- \n " ) ;
2010-11-30 09:49:25 +00:00
i = ao2_iterator_init ( hints , 0 ) ;
2011-07-22 21:15:28 +00:00
for ( ; ( hint = ao2_iterator_next ( & i ) ) ; ao2_ref ( hint , - 1 ) ) {
2011-07-22 20:46:36 +00:00
ao2_lock ( hint ) ;
if ( ! hint - > exten ) {
/* The extension has already been destroyed */
ao2_unlock ( hint ) ;
continue ;
}
2011-01-18 20:40:59 +00:00
watchers = ao2_container_count ( hint - > callbacks ) ;
2015-09-02 17:41:10 +00:00
snprintf ( buf , sizeof ( buf ) , " %s@%s " ,
2006-03-28 22:09:38 +00:00
ast_get_extension_name ( hint - > exten ) ,
2014-06-10 22:31:04 +00:00
ast_get_context_name ( ast_get_extension_context ( hint - > exten ) ) ) ;
ast_cli ( a - > fd , " %-20.20s: %-20.20s State:%-15.15s Presence:%-15.15s Watchers %2d \n " ,
buf ,
2006-03-28 22:09:38 +00:00
ast_get_extension_app ( hint - > exten ) ,
2014-06-10 22:31:04 +00:00
ast_extension_state2str ( hint - > laststate ) ,
2014-06-11 20:22:23 +00:00
ast_presence_state2str ( hint - > last_presence_state ) ,
2014-06-10 22:31:04 +00:00
watchers ) ;
2011-07-22 20:46:36 +00:00
ao2_unlock ( hint ) ;
2005-02-21 06:31:01 +00:00
num + + ;
}
2010-11-30 09:49:25 +00:00
ao2_iterator_destroy ( & i ) ;
2011-07-08 01:26:01 +00:00
2007-09-18 22:43:45 +00:00
ast_cli ( a - > fd , " ---------------- \n " ) ;
ast_cli ( a - > fd , " - %d hints registered \n " , num ) ;
return CLI_SUCCESS ;
2005-02-21 06:31:01 +00:00
}
2007-12-04 15:07:53 +00:00
/*! \brief autocomplete for CLI command 'core show hint' */
static char * complete_core_show_hint ( const char * line , const char * word , int pos , int state )
{
struct ast_hint * hint ;
char * ret = NULL ;
int which = 0 ;
int wordlen ;
2010-11-30 09:49:25 +00:00
struct ao2_iterator i ;
2007-12-04 15:07:53 +00:00
if ( pos ! = 3 )
return NULL ;
2009-03-11 00:28:28 +00:00
2007-12-04 15:07:53 +00:00
wordlen = strlen ( word ) ;
/* walk through all hints */
2010-11-30 09:49:25 +00:00
i = ao2_iterator_init ( hints , 0 ) ;
2011-07-22 21:15:28 +00:00
for ( ; ( hint = ao2_iterator_next ( & i ) ) ; ao2_ref ( hint , - 1 ) ) {
2010-11-30 09:49:25 +00:00
ao2_lock ( hint ) ;
2011-07-22 20:46:36 +00:00
if ( ! hint - > exten ) {
/* The extension has already been destroyed */
ao2_unlock ( hint ) ;
continue ;
}
if ( ! strncasecmp ( word , ast_get_extension_name ( hint - > exten ) , wordlen ) & & + + which > state ) {
2007-12-04 15:07:53 +00:00
ret = ast_strdup ( ast_get_extension_name ( hint - > exten ) ) ;
2010-11-30 09:49:25 +00:00
ao2_unlock ( hint ) ;
2011-07-22 20:46:36 +00:00
ao2_ref ( hint , - 1 ) ;
2007-12-04 15:07:53 +00:00
break ;
}
2011-07-22 20:46:36 +00:00
ao2_unlock ( hint ) ;
2007-12-04 15:07:53 +00:00
}
2010-11-30 09:49:25 +00:00
ao2_iterator_destroy ( & i ) ;
2007-12-04 15:07:53 +00:00
2008-03-04 23:04:29 +00:00
return ret ;
2007-12-04 15:07:53 +00:00
}
/*! \brief handle_show_hint: CLI support for listing registered dial plan hint */
static char * handle_show_hint ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
struct ast_hint * hint ;
int watchers ;
int num = 0 , extenlen ;
2010-11-30 09:49:25 +00:00
struct ao2_iterator i ;
2014-06-11 20:22:23 +00:00
char buf [ AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2 ] ;
2007-12-04 15:07:53 +00:00
switch ( cmd ) {
case CLI_INIT :
e - > command = " core show hint " ;
e - > usage =
" Usage: core show hint <exten> \n "
2014-06-12 21:27:02 +00:00
" List registered hint. \n "
" Hint details are shown in five columns. In order from left to right, they are: \n "
" 1. Hint extension URI. \n "
" 2. List of mapped device or presence state identifiers. \n "
" 3. Current extension state. The aggregate of mapped device states. \n "
" 4. Current presence state for the mapped presence state provider. \n "
" 5. Watchers - number of subscriptions and other entities watching this hint. \n " ;
2007-12-04 15:07:53 +00:00
return NULL ;
case CLI_GENERATE :
return complete_core_show_hint ( a - > line , a - > word , a - > pos , a - > n ) ;
}
if ( a - > argc < 4 )
return CLI_SHOWUSAGE ;
2010-11-30 09:49:25 +00:00
if ( ao2_container_count ( hints ) = = 0 ) {
2007-12-04 15:07:53 +00:00
ast_cli ( a - > fd , " There are no registered dialplan hints \n " ) ;
return CLI_SUCCESS ;
}
2010-11-30 09:49:25 +00:00
2007-12-04 15:07:53 +00:00
extenlen = strlen ( a - > argv [ 3 ] ) ;
2010-11-30 09:49:25 +00:00
i = ao2_iterator_init ( hints , 0 ) ;
2011-07-22 21:15:28 +00:00
for ( ; ( hint = ao2_iterator_next ( & i ) ) ; ao2_ref ( hint , - 1 ) ) {
2010-11-30 09:49:25 +00:00
ao2_lock ( hint ) ;
2011-07-22 20:46:36 +00:00
if ( ! hint - > exten ) {
/* The extension has already been destroyed */
ao2_unlock ( hint ) ;
continue ;
}
if ( ! strncasecmp ( ast_get_extension_name ( hint - > exten ) , a - > argv [ 3 ] , extenlen ) ) {
2011-01-18 20:40:59 +00:00
watchers = ao2_container_count ( hint - > callbacks ) ;
2014-06-11 20:22:23 +00:00
sprintf ( buf , " %s@%s " ,
2007-12-04 15:07:53 +00:00
ast_get_extension_name ( hint - > exten ) ,
2014-06-11 20:22:23 +00:00
ast_get_context_name ( ast_get_extension_context ( hint - > exten ) ) ) ;
ast_cli ( a - > fd , " %-20.20s: %-20.20s State:%-15.15s Presence:%-15.15s Watchers %2d \n " ,
buf ,
2007-12-04 15:07:53 +00:00
ast_get_extension_app ( hint - > exten ) ,
2014-06-11 20:22:23 +00:00
ast_extension_state2str ( hint - > laststate ) ,
ast_presence_state2str ( hint - > last_presence_state ) ,
watchers ) ;
2007-12-04 15:07:53 +00:00
num + + ;
}
2011-07-22 20:46:36 +00:00
ao2_unlock ( hint ) ;
2007-12-04 15:07:53 +00:00
}
2010-11-30 09:49:25 +00:00
ao2_iterator_destroy ( & i ) ;
2007-12-04 15:07:53 +00:00
if ( ! num )
ast_cli ( a - > fd , " No hints matching extension %s \n " , a - > argv [ 3 ] ) ;
else
ast_cli ( a - > fd , " %d hint%s matching extension %s \n " , num , ( num ! = 1 ? " s " : " " ) , a - > argv [ 3 ] ) ;
return CLI_SUCCESS ;
}
2013-08-16 07:18:51 +00:00
#if 0
/* This code can be used to test if the system survives running out of memory.
* It might be an idea to put this in only if ENABLE_AUTODESTRUCT_TESTS is enabled .
*
* If you want to test this , these Linux sysctl flags might be appropriate :
* vm . overcommit_memory = 2
* vm . swappiness = 0
*
* < @ Corydon76 - home > I envision ' core eat disk space ' and ' core eat file descriptors ' now
* < @ mjordan > egads
* < @ mjordan > it ' s literally the ' big red ' auto - destruct button
* < @ mjordan > if you were wondering who even builds such a thing . . . . well , now you know
* . . .
* < @ Corydon76 - home > What about if they lived only if you defined TEST_FRAMEWORK ? Shouldn ' t have those on production machines
* < @ mjordan > I think accompanied with an update to one of our README files that " no, really, TEST_FRAMEWORK isn't for you " , I ' d be fine
*/
static char * handle_eat_memory ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
void * * blocks ;
int blocks_pos = 0 ;
const int blocks_max = 50000 ;
long long int allocated = 0 ;
int sizes [ ] = {
100 * 1024 * 1024 ,
100 * 1024 ,
2 * 1024 ,
400 ,
0
} ;
int i ;
switch ( cmd ) {
case CLI_INIT :
/* To do: add method to free memory again? 5 minutes? */
e - > command = " core eat memory " ;
e - > usage =
" Usage: core eat memory \n "
" Eats all available memory so you can test if the system survives \n " ;
return NULL ;
case CLI_GENERATE :
return NULL ;
}
blocks = ast_malloc ( sizeof ( void * ) * blocks_max ) ;
if ( ! blocks ) {
ast_log ( LOG_ERROR , " Already out of mem? \n " ) ;
return CLI_SUCCESS ;
}
for ( i = 0 ; sizes [ i ] ; + + i ) {
int alloc_size = sizes [ i ] ;
ast_log ( LOG_WARNING , " Allocating %d sized blocks (got %d blocks already) \n " , alloc_size , blocks_pos ) ;
while ( 1 ) {
void * block ;
if ( blocks_pos > = blocks_max ) {
ast_log ( LOG_ERROR , " Memory buffer too small? Run me again :) \n " ) ;
break ;
}
block = ast_malloc ( alloc_size ) ;
if ( ! block ) {
break ;
}
blocks [ blocks_pos + + ] = block ;
allocated + = alloc_size ;
}
}
/* No freeing of the mem! */
ast_log ( LOG_WARNING , " Allocated %lld bytes total! \n " , allocated ) ;
return CLI_SUCCESS ;
}
# endif
2001-09-28 21:20:52 +00:00
/*
* ' show dialplan ' CLI command implementation functions . . .
*/
2006-01-18 22:17:31 +00:00
static char * complete_show_dialplan_context ( const char * line , const char * word , int pos ,
2001-09-28 21:20:52 +00:00
int state )
{
2005-12-26 21:38:50 +00:00
struct ast_context * c = NULL ;
char * ret = NULL ;
2001-09-28 21:20:52 +00:00
int which = 0 ;
2005-12-24 06:23:36 +00:00
int wordlen ;
2001-09-28 21:20:52 +00:00
2003-04-28 04:18:47 +00:00
/* we are do completion of [exten@]context on second position only */
2005-12-24 06:23:36 +00:00
if ( pos ! = 2 )
return NULL ;
2001-09-28 21:20:52 +00:00
2007-02-28 20:46:01 +00:00
ast_rdlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
2005-12-24 06:23:36 +00:00
wordlen = strlen ( word ) ;
2006-03-29 16:51:51 +00:00
/* walk through all contexts and return the n-th match */
2005-12-26 21:38:50 +00:00
while ( ( c = ast_walk_contexts ( c ) ) ) {
2006-03-29 16:51:51 +00:00
if ( ! strncasecmp ( word , ast_get_context_name ( c ) , wordlen ) & & + + which > state ) {
ret = ast_strdup ( ast_get_context_name ( c ) ) ;
break ;
2001-04-27 15:07:56 +00:00
}
}
2001-09-28 21:20:52 +00:00
ast_unlock_contexts ( ) ;
2006-05-08 11:20:19 +00:00
2005-12-26 21:38:50 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2006-10-30 21:18:39 +00:00
/*! \brief Counters for the show dialplan manager command */
2005-01-09 20:28:47 +00:00
struct dialplan_counters {
2006-10-30 21:18:39 +00:00
int total_items ;
2005-01-09 20:28:47 +00:00
int total_context ;
int total_exten ;
int total_prio ;
int context_existence ;
int extension_existence ;
} ;
2006-05-08 21:49:22 +00:00
/*! \brief helper function to print an extension */
static void print_ext ( struct ast_exten * e , char * buf , int buflen )
{
int prio = ast_get_extension_priority ( e ) ;
if ( prio = = PRIORITY_HINT ) {
snprintf ( buf , buflen , " hint: %s " ,
ast_get_extension_app ( e ) ) ;
} else {
snprintf ( buf , buflen , " %d. %s(%s) " ,
prio , ast_get_extension_app ( e ) ,
2007-09-17 02:02:09 +00:00
( ! ast_strlen_zero ( ast_get_extension_app_data ( e ) ) ? ( char * ) ast_get_extension_app_data ( e ) : " " ) ) ;
2006-05-08 21:49:22 +00:00
}
}
2016-12-19 21:03:52 +00:00
/*! \brief Writes CLI output of a single extension for show dialplan */
static void show_dialplan_helper_extension_output ( int fd , char * buf1 , char * buf2 , struct ast_exten * exten )
{
if ( ast_get_extension_registrar_file ( exten ) ) {
ast_cli ( fd , " %-17s %-45s [%s:%d] \n " ,
buf1 , buf2 ,
ast_get_extension_registrar_file ( exten ) ,
ast_get_extension_registrar_line ( exten ) ) ;
return ;
}
ast_cli ( fd , " %-17s %-45s [%s] \n " ,
buf1 , buf2 , ast_get_extension_registrar ( exten ) ) ;
}
2006-05-08 21:49:22 +00:00
/* XXX not verified */
2016-07-14 18:51:42 +00:00
static int show_dialplan_helper ( int fd , const char * context , const char * exten , struct dialplan_counters * dpc , const struct ast_include * rinclude , int includecount , const char * includes [ ] )
2001-09-28 21:20:52 +00:00
{
2005-12-26 21:38:50 +00:00
struct ast_context * c = NULL ;
2005-12-24 06:23:36 +00:00
int res = 0 , old_total_exten = dpc - > total_exten ;
2001-09-28 21:20:52 +00:00
2007-02-28 20:46:01 +00:00
ast_rdlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
/* walk all contexts ... */
2005-12-26 21:38:50 +00:00
while ( ( c = ast_walk_contexts ( c ) ) ) {
2016-07-14 18:51:42 +00:00
int idx ;
2006-05-08 21:49:22 +00:00
struct ast_exten * e ;
2014-05-29 18:51:41 +00:00
# ifndef LOW_MEMORY
char buf [ 1024 ] , buf2 [ 1024 ] ;
# else
2006-05-08 21:49:22 +00:00
char buf [ 256 ] , buf2 [ 256 ] ;
2014-05-29 18:51:41 +00:00
# endif
2006-05-08 21:49:22 +00:00
int context_info_printed = 0 ;
if ( context & & strcmp ( ast_get_context_name ( c ) , context ) )
continue ; /* skip this one, name doesn't match */
dpc - > context_existence = 1 ;
2007-02-28 20:46:01 +00:00
ast_rdlock_context ( c ) ;
2006-05-08 21:49:22 +00:00
/* are we looking for exten too? if yes, we print context
* only if we find our extension .
* Otherwise print context even if empty ?
* XXX i am not sure how the rinclude is handled .
* I think it ought to go inside .
*/
if ( ! exten ) {
dpc - > total_context + + ;
ast_cli ( fd , " [ Context '%s' created by '%s' ] \n " ,
ast_get_context_name ( c ) , ast_get_context_registrar ( c ) ) ;
2016-03-28 16:31:29 +00:00
if ( c - > autohints ) {
ast_cli ( fd , " Autohints support enabled \n " ) ;
}
2006-05-08 21:49:22 +00:00
context_info_printed = 1 ;
}
/* walk extensions ... */
e = NULL ;
while ( ( e = ast_walk_context_extensions ( c , e ) ) ) {
struct ast_exten * p ;
if ( exten & & ! ast_extension_match ( ast_get_extension_name ( e ) , exten ) )
continue ; /* skip, extension match failed */
dpc - > extension_existence = 1 ;
2006-05-09 08:03:52 +00:00
/* may we print context info? */
2006-05-08 21:49:22 +00:00
if ( ! context_info_printed ) {
dpc - > total_context + + ;
if ( rinclude ) { /* TODO Print more info about rinclude */
ast_cli ( fd , " [ Included context '%s' created by '%s' ] \n " ,
ast_get_context_name ( c ) , ast_get_context_registrar ( c ) ) ;
} else {
2001-09-28 21:20:52 +00:00
ast_cli ( fd , " [ Context '%s' created by '%s' ] \n " ,
ast_get_context_name ( c ) , ast_get_context_registrar ( c ) ) ;
2016-03-28 16:31:29 +00:00
if ( c - > autohints ) {
ast_cli ( fd , " Autohints support enabled \n " ) ;
}
2001-09-28 21:20:52 +00:00
}
2006-05-08 21:49:22 +00:00
context_info_printed = 1 ;
}
dpc - > total_prio + + ;
2001-09-28 21:20:52 +00:00
2006-05-09 08:03:52 +00:00
/* write extension name and first peer */
2013-10-25 20:51:13 +00:00
if ( e - > matchcid = = AST_EXT_MATCHCID_ON )
2006-11-08 18:26:52 +00:00
snprintf ( buf , sizeof ( buf ) , " '%s' (CID match '%s') => " , ast_get_extension_name ( e ) , e - > cidmatch ) ;
else
snprintf ( buf , sizeof ( buf ) , " '%s' => " , ast_get_extension_name ( e ) ) ;
2001-09-28 21:20:52 +00:00
2006-05-08 21:49:22 +00:00
print_ext ( e , buf2 , sizeof ( buf2 ) ) ;
2001-09-28 21:20:52 +00:00
2016-12-19 21:03:52 +00:00
show_dialplan_helper_extension_output ( fd , buf , buf2 , e ) ;
2001-09-28 21:20:52 +00:00
2006-05-08 21:49:22 +00:00
dpc - > total_exten + + ;
/* walk next extension peers */
p = e ; /* skip the first one, we already got it */
while ( ( p = ast_walk_extension_priorities ( e , p ) ) ) {
const char * el = ast_get_extension_label ( p ) ;
dpc - > total_prio + + ;
if ( el )
snprintf ( buf , sizeof ( buf ) , " [%s] " , el ) ;
else
buf [ 0 ] = ' \0 ' ;
print_ext ( p , buf2 , sizeof ( buf2 ) ) ;
2001-09-28 21:20:52 +00:00
2016-12-19 21:03:52 +00:00
show_dialplan_helper_extension_output ( fd , buf , buf2 , p ) ;
2006-05-08 21:49:22 +00:00
}
}
2001-09-28 21:20:52 +00:00
2006-05-08 21:49:22 +00:00
/* walk included and write info ... */
2016-07-14 18:51:42 +00:00
for ( idx = 0 ; idx < ast_context_includes_count ( c ) ; idx + + ) {
const struct ast_include * i = ast_context_includes_get ( c , idx ) ;
2006-05-08 21:49:22 +00:00
snprintf ( buf , sizeof ( buf ) , " '%s' " , ast_get_include_name ( i ) ) ;
if ( exten ) {
/* Check all includes for the requested extension */
if ( includecount > = AST_PBX_MAX_STACK ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_log ( LOG_WARNING , " Maximum include depth exceeded! \n " ) ;
2006-05-08 21:49:22 +00:00
} else {
2008-02-11 18:27:47 +00:00
int dupe = 0 ;
2006-05-08 21:49:22 +00:00
int x ;
2008-02-11 18:27:47 +00:00
for ( x = 0 ; x < includecount ; x + + ) {
2006-05-08 21:49:22 +00:00
if ( ! strcasecmp ( includes [ x ] , ast_get_include_name ( i ) ) ) {
dupe + + ;
break ;
2005-09-24 14:19:00 +00:00
}
2001-09-28 21:20:52 +00:00
}
2006-05-08 21:49:22 +00:00
if ( ! dupe ) {
2006-05-09 08:16:07 +00:00
includes [ includecount ] = ast_get_include_name ( i ) ;
2006-05-08 21:49:22 +00:00
show_dialplan_helper ( fd , ast_get_include_name ( i ) , exten , dpc , i , includecount + 1 , includes ) ;
} else {
ast_log ( LOG_WARNING , " Avoiding circular include of %s within %s \n " , ast_get_include_name ( i ) , context ) ;
2001-09-28 21:20:52 +00:00
}
}
2006-05-08 21:49:22 +00:00
} else {
ast_cli ( fd , " Include => %-45s [%s] \n " ,
buf , ast_get_include_registrar ( i ) ) ;
}
}
2001-09-28 21:20:52 +00:00
2006-05-08 21:49:22 +00:00
/* walk ignore patterns and write info ... */
2016-07-15 07:59:48 +00:00
for ( idx = 0 ; idx < ast_context_ignorepats_count ( c ) ; idx + + ) {
const struct ast_ignorepat * ip = ast_context_ignorepats_get ( c , idx ) ;
2006-05-08 21:49:22 +00:00
const char * ipname = ast_get_ignorepat_name ( ip ) ;
char ignorepat [ AST_MAX_EXTENSION ] ;
2016-07-15 07:59:48 +00:00
2006-05-08 21:49:22 +00:00
snprintf ( buf , sizeof ( buf ) , " '%s' " , ipname ) ;
snprintf ( ignorepat , sizeof ( ignorepat ) , " _%s. " , ipname ) ;
if ( ! exten | | ast_extension_match ( ignorepat , exten ) ) {
ast_cli ( fd , " Ignore pattern => %-45s [%s] \n " ,
buf , ast_get_ignorepat_registrar ( ip ) ) ;
}
}
if ( ! rinclude ) {
2016-07-16 00:28:16 +00:00
for ( idx = 0 ; idx < ast_context_switches_count ( c ) ; idx + + ) {
const struct ast_sw * sw = ast_context_switches_get ( c , idx ) ;
2006-05-08 21:49:22 +00:00
snprintf ( buf , sizeof ( buf ) , " '%s/%s' " ,
ast_get_switch_name ( sw ) ,
ast_get_switch_data ( sw ) ) ;
ast_cli ( fd , " Alt. Switch => %-45s [%s] \n " ,
2006-05-09 08:03:52 +00:00
buf , ast_get_switch_registrar ( sw ) ) ;
2006-05-08 21:49:22 +00:00
}
2001-04-27 15:07:56 +00:00
}
2009-03-11 00:28:28 +00:00
2008-10-13 17:14:38 +00:00
ast_unlock_context ( c ) ;
/* if we print something in context, make an empty line */
if ( context_info_printed )
2009-02-20 23:02:35 +00:00
ast_cli ( fd , " \n " ) ;
2008-10-13 17:14:38 +00:00
}
ast_unlock_contexts ( ) ;
return ( dpc - > total_exten = = old_total_exten ) ? - 1 : res ;
}
static int show_debug_helper ( int fd , const char * context , const char * exten , struct dialplan_counters * dpc , struct ast_include * rinclude , int includecount , const char * includes [ ] )
{
struct ast_context * c = NULL ;
int res = 0 , old_total_exten = dpc - > total_exten ;
2009-02-20 23:02:35 +00:00
ast_cli ( fd , " \n In-mem exten Trie for Fast Extension Pattern Matching: \n \n " ) ;
2008-10-13 17:14:38 +00:00
2009-02-20 23:02:35 +00:00
ast_cli ( fd , " \n Explanation: Node Contents Format = <char(s) to match>:<pattern?>:<specif>:[matched extension] \n " ) ;
ast_cli ( fd , " Where <char(s) to match> is a set of chars, any one of which should match the current character \n " ) ;
ast_cli ( fd , " <pattern?>: Y if this a pattern match (eg. _XZN[5-7]), N otherwise \n " ) ;
ast_cli ( fd , " <specif>: an assigned 'exactness' number for this matching char. The lower the number, the more exact the match \n " ) ;
ast_cli ( fd , " [matched exten]: If all chars matched to this point, which extension this matches. In form: EXTEN:<exten string> \n " ) ;
ast_cli ( fd , " In general, you match a trie node to a string character, from left to right. All possible matching chars \n " ) ;
ast_cli ( fd , " are in a string vertically, separated by an unbroken string of '+' characters. \n \n " ) ;
2008-10-13 17:14:38 +00:00
ast_rdlock_contexts ( ) ;
/* walk all contexts ... */
while ( ( c = ast_walk_contexts ( c ) ) ) {
int context_info_printed = 0 ;
if ( context & & strcmp ( ast_get_context_name ( c ) , context ) )
continue ; /* skip this one, name doesn't match */
dpc - > context_existence = 1 ;
2012-05-10 18:35:14 +00:00
if ( ! c - > pattern_tree ) {
/* Ignore check_return warning from Coverity for ast_exists_extension below */
2008-10-13 17:14:38 +00:00
ast_exists_extension ( NULL , c - > name , " s " , 1 , " " ) ; /* do this to force the trie to built, if it is not already */
2012-05-10 18:35:14 +00:00
}
2008-10-13 17:14:38 +00:00
ast_rdlock_context ( c ) ;
dpc - > total_context + + ;
ast_cli ( fd , " [ Context '%s' created by '%s' ] \n " ,
ast_get_context_name ( c ) , ast_get_context_registrar ( c ) ) ;
context_info_printed = 1 ;
2009-03-11 00:28:28 +00:00
2008-10-13 17:14:38 +00:00
if ( c - > pattern_tree )
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
{
2007-11-21 20:38:00 +00:00
cli_match_char_tree ( c - > pattern_tree , " " , fd ) ;
2008-10-13 17:14:38 +00:00
} else {
2009-02-20 23:02:35 +00:00
ast_cli ( fd , " \n No Pattern Trie present. Perhaps the context is empty...or there is trouble... \n \n " ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2006-05-08 21:49:22 +00:00
ast_unlock_context ( c ) ;
/* if we print something in context, make an empty line */
if ( context_info_printed )
2009-02-20 23:02:35 +00:00
ast_cli ( fd , " \n " ) ;
2001-04-27 15:07:56 +00:00
}
2001-09-28 21:20:52 +00:00
ast_unlock_contexts ( ) ;
2006-04-14 22:48:05 +00:00
return ( dpc - > total_exten = = old_total_exten ) ? - 1 : res ;
2005-01-09 20:28:47 +00:00
}
2007-09-18 22:43:45 +00:00
static char * handle_show_dialplan ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
2005-01-09 20:28:47 +00:00
{
char * exten = NULL , * context = NULL ;
/* Variables used for different counters */
struct dialplan_counters counters ;
2006-05-09 08:16:07 +00:00
const char * incstack [ AST_PBX_MAX_STACK ] ;
2007-09-18 22:43:45 +00:00
switch ( cmd ) {
case CLI_INIT :
e - > command = " dialplan show " ;
2009-03-11 00:28:28 +00:00
e - > usage =
2008-02-08 21:26:32 +00:00
" Usage: dialplan show [[exten@]context] \n "
2007-09-18 22:43:45 +00:00
" Show dialplan \n " ;
return NULL ;
2009-03-11 00:28:28 +00:00
case CLI_GENERATE :
2007-09-18 22:43:45 +00:00
return complete_show_dialplan_context ( a - > line , a - > word , a - > pos , a - > n ) ;
}
2005-01-09 20:28:47 +00:00
memset ( & counters , 0 , sizeof ( counters ) ) ;
2007-09-18 22:43:45 +00:00
if ( a - > argc ! = 2 & & a - > argc ! = 3 )
return CLI_SHOWUSAGE ;
2005-01-09 20:28:47 +00:00
/* we obtain [exten@]context? if yes, split them ... */
2007-09-18 22:43:45 +00:00
if ( a - > argc = = 3 ) {
if ( strchr ( a - > argv [ 2 ] , ' @ ' ) ) { /* split into exten & context */
context = ast_strdupa ( a - > argv [ 2 ] ) ;
2006-05-09 07:49:17 +00:00
exten = strsep ( & context , " @ " ) ;
/* change empty strings to NULL */
2005-04-01 19:56:35 +00:00
if ( ast_strlen_zero ( exten ) )
exten = NULL ;
2006-05-09 07:49:17 +00:00
} else { /* no '@' char, only context given */
2009-05-21 21:13:09 +00:00
context = ast_strdupa ( a - > argv [ 2 ] ) ;
2005-01-09 20:28:47 +00:00
}
2006-05-09 07:49:17 +00:00
if ( ast_strlen_zero ( context ) )
context = NULL ;
2005-01-09 20:28:47 +00:00
}
2006-05-09 07:49:17 +00:00
/* else Show complete dial plan, context and exten are NULL */
2007-09-18 22:43:45 +00:00
show_dialplan_helper ( a - > fd , context , exten , & counters , NULL , 0 , incstack ) ;
2005-01-09 20:28:47 +00:00
2001-09-28 21:20:52 +00:00
/* check for input failure and throw some error messages */
2005-01-09 20:28:47 +00:00
if ( context & & ! counters . context_existence ) {
2007-09-18 22:43:45 +00:00
ast_cli ( a - > fd , " There is no existence of '%s' context \n " , context ) ;
return CLI_FAILURE ;
2001-09-28 21:20:52 +00:00
}
2005-01-09 20:28:47 +00:00
if ( exten & & ! counters . extension_existence ) {
2001-09-28 21:20:52 +00:00
if ( context )
2007-09-18 22:43:45 +00:00
ast_cli ( a - > fd , " There is no existence of %s@%s extension \n " ,
2001-09-28 21:20:52 +00:00
exten , context ) ;
else
2007-09-18 22:43:45 +00:00
ast_cli ( a - > fd ,
2001-09-28 21:20:52 +00:00
" There is no existence of '%s' extension in all contexts \n " ,
exten ) ;
2007-09-18 22:43:45 +00:00
return CLI_FAILURE ;
2001-09-28 21:20:52 +00:00
}
2005-01-09 20:28:47 +00:00
2007-09-18 22:43:45 +00:00
ast_cli ( a - > fd , " -= %d %s (%d %s) in %d %s. =- \n " ,
2005-09-16 18:11:00 +00:00
counters . total_exten , counters . total_exten = = 1 ? " extension " : " extensions " ,
counters . total_prio , counters . total_prio = = 1 ? " priority " : " priorities " ,
counters . total_context , counters . total_context = = 1 ? " context " : " contexts " ) ;
2005-01-09 20:28:47 +00:00
2001-09-28 21:20:52 +00:00
/* everything ok */
2007-09-18 22:43:45 +00:00
return CLI_SUCCESS ;
2001-04-27 15:07:56 +00:00
}
2008-10-13 17:14:38 +00:00
/*! \brief Send ack once */
static char * handle_debug_dialplan ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
char * exten = NULL , * context = NULL ;
/* Variables used for different counters */
struct dialplan_counters counters ;
const char * incstack [ AST_PBX_MAX_STACK ] ;
switch ( cmd ) {
case CLI_INIT :
e - > command = " dialplan debug " ;
2009-03-11 00:28:28 +00:00
e - > usage =
2008-10-13 17:14:38 +00:00
" Usage: dialplan debug [context] \n "
" Show dialplan context Trie(s). Usually only useful to folks debugging the deep internals of the fast pattern matcher \n " ;
return NULL ;
2009-03-11 00:28:28 +00:00
case CLI_GENERATE :
2008-10-13 17:14:38 +00:00
return complete_show_dialplan_context ( a - > line , a - > word , a - > pos , a - > n ) ;
}
memset ( & counters , 0 , sizeof ( counters ) ) ;
if ( a - > argc ! = 2 & & a - > argc ! = 3 )
return CLI_SHOWUSAGE ;
/* we obtain [exten@]context? if yes, split them ... */
/* note: we ignore the exten totally here .... */
if ( a - > argc = = 3 ) {
if ( strchr ( a - > argv [ 2 ] , ' @ ' ) ) { /* split into exten & context */
context = ast_strdupa ( a - > argv [ 2 ] ) ;
exten = strsep ( & context , " @ " ) ;
/* change empty strings to NULL */
if ( ast_strlen_zero ( exten ) )
exten = NULL ;
} else { /* no '@' char, only context given */
2009-05-21 21:13:09 +00:00
context = ast_strdupa ( a - > argv [ 2 ] ) ;
2008-10-13 17:14:38 +00:00
}
if ( ast_strlen_zero ( context ) )
context = NULL ;
}
/* else Show complete dial plan, context and exten are NULL */
show_debug_helper ( a - > fd , context , exten , & counters , NULL , 0 , incstack ) ;
/* check for input failure and throw some error messages */
if ( context & & ! counters . context_existence ) {
ast_cli ( a - > fd , " There is no existence of '%s' context \n " , context ) ;
return CLI_FAILURE ;
}
ast_cli ( a - > fd , " -= %d %s. =- \n " ,
counters . total_context , counters . total_context = = 1 ? " context " : " contexts " ) ;
/* everything ok */
return CLI_SUCCESS ;
}
2006-10-30 21:18:39 +00:00
/*! \brief Send ack once */
2007-01-05 22:43:18 +00:00
static void manager_dpsendack ( struct mansession * s , const struct message * m )
2006-10-30 21:18:39 +00:00
{
2015-01-12 18:09:27 +00:00
astman_send_listack ( s , m , " DialPlan list will follow " , " start " ) ;
2006-10-30 21:18:39 +00:00
}
2006-12-13 22:54:41 +00:00
/*! \brief Show dialplan extensions
* XXX this function is similar but not exactly the same as the CLI ' s
* show dialplan . Must check whether the difference is intentional or not .
*/
2007-01-05 22:43:18 +00:00
static int manager_show_dialplan_helper ( struct mansession * s , const struct message * m ,
const char * actionidtext , const char * context ,
const char * exten , struct dialplan_counters * dpc ,
2016-08-29 12:07:38 +00:00
const struct ast_include * rinclude ,
int includecount , const char * includes [ ] )
2006-10-30 21:18:39 +00:00
{
struct ast_context * c ;
2008-02-11 18:27:47 +00:00
int res = 0 , old_total_exten = dpc - > total_exten ;
2006-10-30 21:18:39 +00:00
if ( ast_strlen_zero ( exten ) )
exten = NULL ;
if ( ast_strlen_zero ( context ) )
context = NULL ;
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Context: -%s- Extension: -%s- \n " , context , exten ) ;
2006-10-30 21:18:39 +00:00
/* try to lock contexts */
2007-02-28 20:46:01 +00:00
if ( ast_rdlock_contexts ( ) ) {
2008-07-15 18:25:34 +00:00
astman_send_error ( s , m , " Failed to lock contexts " ) ;
2006-10-30 21:18:39 +00:00
ast_log ( LOG_WARNING , " Failed to lock contexts list for manager: listdialplan \n " ) ;
return - 1 ;
}
2006-12-13 22:54:41 +00:00
c = NULL ; /* walk all contexts ... */
while ( ( c = ast_walk_contexts ( c ) ) ) {
2016-07-14 18:51:42 +00:00
int idx ;
2006-12-13 22:54:41 +00:00
struct ast_exten * e ;
if ( context & & strcmp ( ast_get_context_name ( c ) , context ) ! = 0 )
continue ; /* not the name we want */
dpc - > context_existence = 1 ;
2012-09-05 19:08:15 +00:00
dpc - > total_context + + ;
2006-10-30 21:18:39 +00:00
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Found Context: %s \n " , ast_get_context_name ( c ) ) ;
2006-12-13 22:54:41 +00:00
2007-02-28 20:46:01 +00:00
if ( ast_rdlock_context ( c ) ) { /* failed to lock */
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Failed to lock context \n " ) ;
2006-12-13 22:54:41 +00:00
continue ;
}
2006-10-30 21:18:39 +00:00
2006-12-13 22:54:41 +00:00
/* XXX note- an empty context is not printed */
e = NULL ; /* walk extensions in context */
while ( ( e = ast_walk_context_extensions ( c , e ) ) ) {
struct ast_exten * p ;
2006-10-30 21:18:39 +00:00
2006-12-13 22:54:41 +00:00
/* looking for extension? is this our extension? */
if ( exten & & ! ast_extension_match ( ast_get_extension_name ( e ) , exten ) ) {
/* not the one we are looking for, continue */
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Skipping extension %s \n " , ast_get_extension_name ( e ) ) ;
2006-12-13 22:54:41 +00:00
continue ;
}
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Found Extension: %s \n " , ast_get_extension_name ( e ) ) ;
2006-12-13 22:54:41 +00:00
dpc - > extension_existence = 1 ;
dpc - > total_exten + + ;
p = NULL ; /* walk next extension peers */
while ( ( p = ast_walk_extension_priorities ( e , p ) ) ) {
int prio = ast_get_extension_priority ( p ) ;
dpc - > total_prio + + ;
2006-12-13 23:08:02 +00:00
if ( ! dpc - > total_items + + )
manager_dpsendack ( s , m ) ;
2006-12-13 22:54:41 +00:00
astman_append ( s , " Event: ListDialplan \r \n %s " , actionidtext ) ;
astman_append ( s , " Context: %s \r \n Extension: %s \r \n " , ast_get_context_name ( c ) , ast_get_extension_name ( e ) ) ;
/* XXX maybe make this conditional, if p != e ? */
if ( ast_get_extension_label ( p ) )
astman_append ( s , " ExtensionLabel: %s \r \n " , ast_get_extension_label ( p ) ) ;
if ( prio = = PRIORITY_HINT ) {
astman_append ( s , " Priority: hint \r \n Application: %s \r \n " , ast_get_extension_app ( p ) ) ;
} else {
astman_append ( s , " Priority: %d \r \n Application: %s \r \n AppData: %s \r \n " , prio , ast_get_extension_app ( p ) , ( char * ) ast_get_extension_app_data ( p ) ) ;
2006-10-30 21:18:39 +00:00
}
2006-12-13 22:54:41 +00:00
astman_append ( s , " Registrar: %s \r \n \r \n " , ast_get_extension_registrar ( e ) ) ;
}
}
2006-10-30 21:18:39 +00:00
2016-07-14 18:51:42 +00:00
for ( idx = 0 ; idx < ast_context_includes_count ( c ) ; idx + + ) {
const struct ast_include * i = ast_context_includes_get ( c , idx ) ;
2006-12-13 22:54:41 +00:00
if ( exten ) {
/* Check all includes for the requested extension */
2016-08-29 12:07:38 +00:00
if ( includecount > = AST_PBX_MAX_STACK ) {
ast_log ( LOG_WARNING , " Maximum include depth exceeded! \n " ) ;
} else {
int dupe = 0 ;
int x ;
for ( x = 0 ; x < includecount ; x + + ) {
if ( ! strcasecmp ( includes [ x ] , ast_get_include_name ( i ) ) ) {
dupe + + ;
break ;
}
}
if ( ! dupe ) {
includes [ includecount ] = ast_get_include_name ( i ) ;
manager_show_dialplan_helper ( s , m , actionidtext , ast_get_include_name ( i ) , exten , dpc , i , includecount + 1 , includes ) ;
} else {
ast_log ( LOG_WARNING , " Avoiding circular include of %s within %s \n " , ast_get_include_name ( i ) , context ) ;
}
}
2006-12-13 22:54:41 +00:00
} else {
2006-12-13 23:08:02 +00:00
if ( ! dpc - > total_items + + )
manager_dpsendack ( s , m ) ;
2006-12-13 22:54:41 +00:00
astman_append ( s , " Event: ListDialplan \r \n %s " , actionidtext ) ;
astman_append ( s , " Context: %s \r \n IncludeContext: %s \r \n Registrar: %s \r \n " , ast_get_context_name ( c ) , ast_get_include_name ( i ) , ast_get_include_registrar ( i ) ) ;
astman_append ( s , " \r \n " ) ;
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Found Included context: %s \n " , ast_get_include_name ( i ) ) ;
2006-10-30 21:18:39 +00:00
}
}
2006-12-13 22:54:41 +00:00
2016-07-15 07:59:48 +00:00
for ( idx = 0 ; idx < ast_context_ignorepats_count ( c ) ; idx + + ) {
const struct ast_ignorepat * ip = ast_context_ignorepats_get ( c , idx ) ;
2006-12-13 22:54:41 +00:00
const char * ipname = ast_get_ignorepat_name ( ip ) ;
char ignorepat [ AST_MAX_EXTENSION ] ;
snprintf ( ignorepat , sizeof ( ignorepat ) , " _%s. " , ipname ) ;
if ( ! exten | | ast_extension_match ( ignorepat , exten ) ) {
2006-12-13 23:08:02 +00:00
if ( ! dpc - > total_items + + )
manager_dpsendack ( s , m ) ;
2006-12-13 22:54:41 +00:00
astman_append ( s , " Event: ListDialplan \r \n %s " , actionidtext ) ;
astman_append ( s , " Context: %s \r \n IgnorePattern: %s \r \n Registrar: %s \r \n " , ast_get_context_name ( c ) , ipname , ast_get_ignorepat_registrar ( ip ) ) ;
astman_append ( s , " \r \n " ) ;
}
}
if ( ! rinclude ) {
2016-07-16 00:28:16 +00:00
for ( idx = 0 ; idx < ast_context_switches_count ( c ) ; idx + + ) {
const struct ast_sw * sw = ast_context_switches_get ( c , idx ) ;
2006-12-13 23:08:02 +00:00
if ( ! dpc - > total_items + + )
manager_dpsendack ( s , m ) ;
2006-12-13 22:54:41 +00:00
astman_append ( s , " Event: ListDialplan \r \n %s " , actionidtext ) ;
2011-02-04 16:55:39 +00:00
astman_append ( s , " Context: %s \r \n Switch: %s/%s \r \n Registrar: %s \r \n " , ast_get_context_name ( c ) , ast_get_switch_name ( sw ) , ast_get_switch_data ( sw ) , ast_get_switch_registrar ( sw ) ) ;
2006-12-13 22:54:41 +00:00
astman_append ( s , " \r \n " ) ;
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Found Switch : %s \n " , ast_get_switch_name ( sw ) ) ;
2006-12-13 22:54:41 +00:00
}
}
ast_unlock_context ( c ) ;
}
2006-10-30 21:18:39 +00:00
ast_unlock_contexts ( ) ;
if ( dpc - > total_exten = = old_total_exten ) {
2007-06-12 16:13:45 +00:00
ast_debug ( 3 , " manager_show_dialplan: Found nothing new \n " ) ;
2006-10-30 21:18:39 +00:00
/* Nothing new under the sun */
return - 1 ;
} else {
return res ;
}
}
/*! \brief Manager listing of dial plan */
2007-01-05 22:43:18 +00:00
static int manager_show_dialplan ( struct mansession * s , const struct message * m )
2006-10-30 21:18:39 +00:00
{
2007-01-05 22:43:18 +00:00
const char * exten , * context ;
const char * id = astman_get_header ( m , " ActionID " ) ;
2016-08-29 12:07:38 +00:00
const char * incstack [ AST_PBX_MAX_STACK ] ;
2006-10-30 21:18:39 +00:00
char idtext [ 256 ] ;
/* Variables used for different counters */
struct dialplan_counters counters ;
2007-06-13 17:06:53 +00:00
if ( ! ast_strlen_zero ( id ) )
2006-10-30 21:18:39 +00:00
snprintf ( idtext , sizeof ( idtext ) , " ActionID: %s \r \n " , id ) ;
2006-12-13 22:54:41 +00:00
else
idtext [ 0 ] = ' \0 ' ;
2006-10-30 21:18:39 +00:00
memset ( & counters , 0 , sizeof ( counters ) ) ;
exten = astman_get_header ( m , " Extension " ) ;
context = astman_get_header ( m , " Context " ) ;
2009-03-11 00:28:28 +00:00
2016-08-29 12:07:38 +00:00
manager_show_dialplan_helper ( s , m , idtext , context , exten , & counters , NULL , 0 , incstack ) ;
2006-10-30 21:18:39 +00:00
2012-11-12 20:46:51 +00:00
if ( ! ast_strlen_zero ( context ) & & ! counters . context_existence ) {
2006-10-30 21:18:39 +00:00
char errorbuf [ BUFSIZ ] ;
2009-03-11 00:28:28 +00:00
2008-07-15 18:25:34 +00:00
snprintf ( errorbuf , sizeof ( errorbuf ) , " Did not find context %s " , context ) ;
2006-10-30 21:18:39 +00:00
astman_send_error ( s , m , errorbuf ) ;
return 0 ;
}
2012-11-12 20:46:51 +00:00
if ( ! ast_strlen_zero ( exten ) & & ! counters . extension_existence ) {
2006-10-30 21:18:39 +00:00
char errorbuf [ BUFSIZ ] ;
2012-11-12 20:46:51 +00:00
if ( ! ast_strlen_zero ( context ) )
2008-07-15 18:25:34 +00:00
snprintf ( errorbuf , sizeof ( errorbuf ) , " Did not find extension %s@%s " , exten , context ) ;
2006-10-30 21:18:39 +00:00
else
2008-07-15 18:25:34 +00:00
snprintf ( errorbuf , sizeof ( errorbuf ) , " Did not find extension %s in any context " , exten ) ;
2006-10-30 21:18:39 +00:00
astman_send_error ( s , m , errorbuf ) ;
return 0 ;
}
2012-11-12 20:46:51 +00:00
if ( ! counters . total_items ) {
manager_dpsendack ( s , m ) ;
}
2015-01-09 18:16:54 +00:00
astman_send_list_complete_start ( s , m , " ShowDialPlanComplete " , counters . total_items ) ;
astman_append ( s ,
2006-10-30 21:18:39 +00:00
" ListExtensions: %d \r \n "
2009-03-11 00:28:28 +00:00
" ListPriorities: %d \r \n "
2015-01-09 18:16:54 +00:00
" ListContexts: %d \r \n " ,
counters . total_exten , counters . total_prio , counters . total_context ) ;
astman_send_list_complete_end ( s ) ;
2006-10-30 21:18:39 +00:00
/* everything ok */
return 0 ;
}
2009-07-02 16:03:44 +00:00
# ifdef AST_DEVMODE
static char * handle_show_device2extenstate ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
struct ast_devstate_aggregate agg ;
int i , j , exten , combined ;
switch ( cmd ) {
case CLI_INIT :
e - > command = " core show device2extenstate " ;
e - > usage =
" Usage: core show device2extenstate \n "
" Lists device state to extension state combinations. \n " ;
case CLI_GENERATE :
return NULL ;
}
for ( i = 0 ; i < AST_DEVICE_TOTAL ; i + + ) {
for ( j = 0 ; j < AST_DEVICE_TOTAL ; j + + ) {
ast_devstate_aggregate_init ( & agg ) ;
ast_devstate_aggregate_add ( & agg , i ) ;
ast_devstate_aggregate_add ( & agg , j ) ;
combined = ast_devstate_aggregate_result ( & agg ) ;
exten = ast_devstate_to_extenstate ( combined ) ;
ast_cli ( a - > fd , " \n Exten:%14s CombinedDevice:%12s Dev1:%12s Dev2:%12s " , ast_extension_state2str ( exten ) , ast_devstate_str ( combined ) , ast_devstate_str ( j ) , ast_devstate_str ( i ) ) ;
}
}
ast_cli ( a - > fd , " \n " ) ;
return CLI_SUCCESS ;
}
# endif
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
static char * handle_set_extenpatternmatchnew ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
int oldval = 0 ;
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
switch ( cmd ) {
case CLI_INIT :
2007-11-26 16:24:27 +00:00
e - > command = " dialplan set extenpatternmatchnew true " ;
2009-03-11 00:28:28 +00:00
e - > usage =
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
" Usage: dialplan set extenpatternmatchnew true|false \n "
" Use the NEW extension pattern matching algorithm, true or false. \n " ;
return NULL ;
case CLI_GENERATE :
2009-03-11 00:28:28 +00:00
return NULL ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
}
if ( a - > argc ! = 4 )
return CLI_SHOWUSAGE ;
oldval = pbx_set_extenpatternmatchnew ( 1 ) ;
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( oldval )
ast_cli ( a - > fd , " \n -- Still using the NEW pattern match algorithm for extension names in the dialplan. \n " ) ;
else
ast_cli ( a - > fd , " \n -- Switched to using the NEW pattern match algorithm for extension names in the dialplan. \n " ) ;
return CLI_SUCCESS ;
}
static char * handle_unset_extenpatternmatchnew ( struct ast_cli_entry * e , int cmd , struct ast_cli_args * a )
{
int oldval = 0 ;
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
switch ( cmd ) {
case CLI_INIT :
2007-11-26 16:24:27 +00:00
e - > command = " dialplan set extenpatternmatchnew false " ;
2009-03-11 00:28:28 +00:00
e - > usage =
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
" Usage: dialplan set extenpatternmatchnew true|false \n "
" Use the NEW extension pattern matching algorithm, true or false. \n " ;
return NULL ;
case CLI_GENERATE :
2009-03-11 00:28:28 +00:00
return NULL ;
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
}
if ( a - > argc ! = 4 )
return CLI_SHOWUSAGE ;
oldval = pbx_set_extenpatternmatchnew ( 0 ) ;
2009-03-11 00:28:28 +00:00
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
if ( ! oldval )
ast_cli ( a - > fd , " \n -- Still using the OLD pattern match algorithm for extension names in the dialplan. \n " ) ;
else
ast_cli ( a - > fd , " \n -- Switched to using the OLD pattern match algorithm for extension names in the dialplan. \n " ) ;
return CLI_SUCCESS ;
}
2001-09-28 21:20:52 +00:00
/*
* CLI entries for upper commands . . .
*/
2005-06-03 03:09:20 +00:00
static struct ast_cli_entry pbx_cli [ ] = {
2013-08-16 07:18:51 +00:00
#if 0
AST_CLI_DEFINE ( handle_eat_memory , " Eats all available memory " ) ,
# endif
2007-10-22 20:05:18 +00:00
AST_CLI_DEFINE ( handle_show_hints , " Show dialplan hints " ) ,
2007-12-04 15:07:53 +00:00
AST_CLI_DEFINE ( handle_show_hint , " Show dialplan hint " ) ,
2009-07-02 16:03:44 +00:00
# ifdef AST_DEVMODE
AST_CLI_DEFINE ( handle_show_device2extenstate , " Show expected exten state from multiple device states " ) ,
# endif
2007-10-22 20:05:18 +00:00
AST_CLI_DEFINE ( handle_show_dialplan , " Show dialplan " ) ,
2008-10-13 17:14:38 +00:00
AST_CLI_DEFINE ( handle_debug_dialplan , " Show fast extension pattern matching data structures " ) ,
closes issue #11363; where the pattern _20x. buried in an included context, didn't match 2012; There were a small set of problems to fix: 1. I needed NOT to score patterns unless you are at the end of the data string. 2. Capital N,X,Z and small n,x,z are OK in patterns. I canonicalize the patterns in the trie to caps. 3. When a pattern ends with dot or exclamation, CANMATCH/MATCHMORE should always report this pattern, no matter the length. With this commit, I also supplied the wish of Luigi, where the user can select which pattern matching algorithm to use, the old (legacy) pattern matcher, or the new, trie based matcher. The OLD matcher is the default. A new [general] section variable, extenpatternmatchnew, is added to the extensions.conf, and the example config has it set to false. If true, the new matcher is used. In all other respects, the context/exten structs are the same; the tries and hashtabs are formed, but in the new mode the tries are not used. A new CLI command 'dialplan set extenpatternmatch true/false' is provided to allow switching at run time. I beg users that are forced to return to the old matcher to please report the reason in the bug tracker. Measured the speed benefit of the new matcher against an impossibly large context with 10,000 extensions: the new matcher is 374 times faster.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-24 21:00:26 +00:00
AST_CLI_DEFINE ( handle_unset_extenpatternmatchnew , " Use the Old extension pattern matching algorithm. " ) ,
AST_CLI_DEFINE ( handle_set_extenpatternmatchnew , " Use the New extension pattern matching algorithm. " ) ,
2005-05-05 05:39:33 +00:00
} ;
2016-01-05 01:46:25 +00:00
void unreference_cached_app ( struct ast_app * app )
2006-09-28 22:49:55 +00:00
{
struct ast_context * context = NULL ;
struct ast_exten * eroot = NULL , * e = NULL ;
2007-02-28 20:46:01 +00:00
ast_rdlock_contexts ( ) ;
2006-09-28 22:49:55 +00:00
while ( ( context = ast_walk_contexts ( context ) ) ) {
while ( ( eroot = ast_walk_context_extensions ( context , eroot ) ) ) {
while ( ( e = ast_walk_extension_priorities ( eroot , e ) ) ) {
if ( e - > cached_app = = app )
e - > cached_app = NULL ;
}
}
}
ast_unlock_contexts ( ) ;
return ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
struct ast_context * ast_context_find_or_create ( struct ast_context * * extcontexts , struct ast_hashtab * exttable , const char * name , const char * registrar )
1999-12-04 20:45:45 +00:00
{
2003-07-14 15:35:21 +00:00
struct ast_context * tmp , * * local_contexts ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
struct fake_context search ;
2006-05-10 20:44:28 +00:00
int length = sizeof ( struct ast_context ) + strlen ( name ) + 1 ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( ! contexts_table ) {
2011-08-09 23:17:13 +00:00
/* Protect creation of contexts_table from reentrancy. */
ast_wrlock_contexts ( ) ;
if ( ! contexts_table ) {
contexts_table = ast_hashtab_create ( 17 ,
ast_hashtab_compare_contexts ,
ast_hashtab_resize_java ,
ast_hashtab_newsize_java ,
ast_hashtab_hash_contexts ,
0 ) ;
}
ast_unlock_contexts ( ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2009-03-11 00:28:28 +00:00
2009-02-18 06:00:40 +00:00
ast_copy_string ( search . name , name , sizeof ( search . name ) ) ;
2003-07-14 15:35:21 +00:00
if ( ! extcontexts ) {
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
ast_rdlock_contexts ( ) ;
2006-05-10 20:44:28 +00:00
local_contexts = & contexts ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
tmp = ast_hashtab_lookup ( contexts_table , & search ) ;
if ( tmp ) {
tmp - > refcount + + ;
2015-06-08 15:09:57 +00:00
ast_unlock_contexts ( ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
return tmp ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */
2003-07-14 15:35:21 +00:00
local_contexts = extcontexts ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
tmp = ast_hashtab_lookup ( exttable , & search ) ;
if ( tmp ) {
tmp - > refcount + + ;
return tmp ;
1999-12-04 20:45:45 +00:00
}
}
2009-03-11 00:28:28 +00:00
2006-03-29 19:54:41 +00:00
if ( ( tmp = ast_calloc ( 1 , length ) ) ) {
2007-02-28 20:46:01 +00:00
ast_rwlock_init ( & tmp - > lock ) ;
2006-08-14 03:24:06 +00:00
ast_mutex_init ( & tmp - > macrolock ) ;
2004-10-03 04:19:59 +00:00
strcpy ( tmp - > name , name ) ;
1999-12-04 20:45:45 +00:00
tmp - > root = NULL ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
tmp - > root_table = NULL ;
2008-07-11 22:03:19 +00:00
tmp - > registrar = ast_strdup ( registrar ) ;
2016-07-14 18:51:42 +00:00
AST_VECTOR_INIT ( & tmp - > includes , 0 ) ;
2016-07-15 07:59:48 +00:00
AST_VECTOR_INIT ( & tmp - > ignorepats , 0 ) ;
2016-07-16 00:28:16 +00:00
AST_VECTOR_INIT ( & tmp - > alts , 0 ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
tmp - > refcount = 1 ;
} else {
ast_log ( LOG_ERROR , " Danger! We failed to allocate a context for %s! \n " , name ) ;
2015-06-08 15:09:57 +00:00
if ( ! extcontexts ) {
ast_unlock_contexts ( ) ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
return NULL ;
2006-03-29 19:54:41 +00:00
}
2009-03-11 00:28:28 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
if ( ! extcontexts ) {
tmp - > next = * local_contexts ;
* local_contexts = tmp ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( contexts_table , tmp ) ; /*put this context into the tree */
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2010-08-12 18:04:19 +00:00
ast_verb ( 3 , " Registered extension context '%s'; registrar: %s \n " , tmp - > name , registrar ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else {
tmp - > next = * local_contexts ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( exttable )
ast_hashtab_insert_immediate ( exttable , tmp ) ; /*put this context into the tree */
2009-03-11 00:28:28 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
* local_contexts = tmp ;
2010-08-12 18:04:19 +00:00
ast_verb ( 3 , " Registered extension context '%s'; registrar: %s \n " , tmp - > name , registrar ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
1999-12-04 20:45:45 +00:00
return tmp ;
}
2016-03-28 16:31:29 +00:00
void ast_context_set_autohints ( struct ast_context * con , int enabled )
{
con - > autohints = enabled ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
void __ast_context_destroy ( struct ast_context * list , struct ast_hashtab * contexttab , struct ast_context * con , const char * registrar ) ;
2003-07-14 15:35:21 +00:00
2005-08-27 23:55:14 +00:00
struct store_hint {
char * context ;
char * exten ;
2008-03-19 04:32:13 +00:00
AST_LIST_HEAD_NOLOCK ( , ast_state_cb ) callbacks ;
2005-08-27 23:55:14 +00:00
int laststate ;
2012-06-04 20:26:12 +00:00
int last_presence_state ;
char * last_presence_subtype ;
char * last_presence_message ;
2005-08-27 23:55:14 +00:00
AST_LIST_ENTRY ( store_hint ) list ;
char data [ 1 ] ;
} ;
2011-12-23 02:35:13 +00:00
AST_LIST_HEAD_NOLOCK ( store_hints , store_hint ) ;
2005-08-27 23:55:14 +00:00
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
static void context_merge_incls_swits_igps_other_registrars ( struct ast_context * new , struct ast_context * old , const char * registrar )
{
2016-07-14 18:51:42 +00:00
int idx ;
2009-03-11 00:28:28 +00:00
(closes issue #12960)
Reported by: mnicholson
Spent most of the day on this bug, and the
solution was so simple. Just had to find and
understand the problem.
The problem was, that the routine to copy
the existing switches, includes, and ignorepats
from the old context to the new one, wasn't
getting called when the context is already
existent. (In other words, if AEL is adding
a new context to the mix, they get copied,
but if pbx_config already defined a context,
then the copy wasn't happening. This made
no sense, so I moved the call to copy the
includes & etc, no matter the case.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@131129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-15 23:36:19 +00:00
ast_verb ( 3 , " merging incls/swits/igpats from old(%s) to new(%s) context, registrar = %s \n " , ast_get_context_name ( old ) , ast_get_context_name ( new ) , registrar ) ;
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
/* copy in the includes, switches, and ignorepats */
/* walk through includes */
2016-07-14 18:51:42 +00:00
for ( idx = 0 ; idx < ast_context_includes_count ( old ) ; idx + + ) {
const struct ast_include * i = ast_context_includes_get ( old , idx ) ;
if ( ! strcmp ( ast_get_include_registrar ( i ) , registrar ) ) {
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
continue ; /* not mine */
2016-07-14 18:51:42 +00:00
}
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
ast_context_add_include2 ( new , ast_get_include_name ( i ) , ast_get_include_registrar ( i ) ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
/* walk through switches */
2016-07-16 00:28:16 +00:00
for ( idx = 0 ; idx < ast_context_switches_count ( old ) ; idx + + ) {
const struct ast_sw * sw = ast_context_switches_get ( old , idx ) ;
if ( ! strcmp ( ast_get_switch_registrar ( sw ) , registrar ) ) {
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
continue ; /* not mine */
2016-07-16 00:28:16 +00:00
}
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
ast_context_add_switch2 ( new , ast_get_switch_name ( sw ) , ast_get_switch_data ( sw ) , ast_get_switch_eval ( sw ) , ast_get_switch_registrar ( sw ) ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
/* walk thru ignorepats ... */
2016-07-15 07:59:48 +00:00
for ( idx = 0 ; idx < ast_context_ignorepats_count ( old ) ; idx + + ) {
const struct ast_ignorepat * ip = ast_context_ignorepats_get ( old , idx ) ;
if ( strcmp ( ast_get_ignorepat_registrar ( ip ) , registrar ) = = 0 ) {
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
continue ; /* not mine */
2016-07-15 07:59:48 +00:00
}
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
ast_context_add_ignorepat2 ( new , ast_get_ignorepat_name ( ip ) , ast_get_ignorepat_registrar ( ip ) ) ;
}
}
2016-03-28 16:31:29 +00:00
/*! Set up an autohint placeholder in the hints container */
static void context_table_create_autohints ( struct ast_hashtab * table )
{
struct ast_context * con ;
struct ast_hashtab_iter * iter ;
/* Remove all autohints as the below iteration will recreate them */
ao2_callback ( autohints , OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE , NULL , NULL ) ;
iter = ast_hashtab_start_traversal ( table ) ;
while ( ( con = ast_hashtab_next ( iter ) ) ) {
size_t name_len = strlen ( con - > name ) + 1 ;
size_t registrar_len = strlen ( con - > registrar ) + 1 ;
struct ast_autohint * autohint ;
if ( ! con - > autohints ) {
continue ;
}
autohint = ao2_alloc_options ( sizeof ( * autohint ) + name_len + registrar_len , NULL , AO2_ALLOC_OPT_LOCK_NOLOCK ) ;
if ( ! autohint ) {
continue ;
}
ast_copy_string ( autohint - > context , con - > name , name_len ) ;
autohint - > registrar = autohint - > context + name_len ;
ast_copy_string ( autohint - > registrar , con - > registrar , registrar_len ) ;
ao2_link ( autohints , autohint ) ;
ao2_ref ( autohint , - 1 ) ;
ast_verb ( 3 , " Enabled autohints support on context '%s' \n " , con - > name ) ;
}
ast_hashtab_end_traversal ( iter ) ;
}
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
/* the purpose of this routine is to duplicate a context, with all its substructure,
except for any extens that have a matching registrar */
static void context_merge ( struct ast_context * * extcontexts , struct ast_hashtab * exttable , struct ast_context * context , const char * registrar )
{
struct ast_context * new = ast_hashtab_lookup ( exttable , context ) ; /* is there a match in the new set? */
struct ast_exten * exten_item , * prio_item , * new_exten_item , * new_prio_item ;
struct ast_hashtab_iter * exten_iter ;
struct ast_hashtab_iter * prio_iter ;
int insert_count = 0 ;
2008-07-23 22:03:48 +00:00
int first = 1 ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
/* We'll traverse all the extensions/prios, and see which are not registrar'd with
the current registrar , and copy them to the new context . If the new context does not
exist , we ' ll create it " on demand " . If no items are in this context to copy , then we ' ll
only create the empty matching context if the old one meets the criteria */
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( context - > root_table ) {
exten_iter = ast_hashtab_start_traversal ( context - > root_table ) ;
while ( ( exten_item = ast_hashtab_next ( exten_iter ) ) ) {
if ( new ) {
new_exten_item = ast_hashtab_lookup ( new - > root_table , exten_item ) ;
} else {
new_exten_item = NULL ;
}
prio_iter = ast_hashtab_start_traversal ( exten_item - > peer_table ) ;
while ( ( prio_item = ast_hashtab_next ( prio_iter ) ) ) {
int res1 ;
2008-07-23 22:03:48 +00:00
char * dupdstr ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( new_exten_item ) {
new_prio_item = ast_hashtab_lookup ( new_exten_item - > peer_table , prio_item ) ;
} else {
new_prio_item = NULL ;
}
if ( strcmp ( prio_item - > registrar , registrar ) = = 0 ) {
continue ;
}
/* make sure the new context exists, so we have somewhere to stick this exten/prio */
if ( ! new ) {
new = ast_context_find_or_create ( extcontexts , exttable , context - > name , prio_item - > registrar ) ; /* a new context created via priority from a different context in the old dialplan, gets its registrar from the prio's registrar */
2016-03-28 16:31:29 +00:00
if ( new ) {
new - > autohints = context - > autohints ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
}
(closes issue #12960)
Reported by: mnicholson
Spent most of the day on this bug, and the
solution was so simple. Just had to find and
understand the problem.
The problem was, that the routine to copy
the existing switches, includes, and ignorepats
from the old context to the new one, wasn't
getting called when the context is already
existent. (In other words, if AEL is adding
a new context to the mix, they get copied,
but if pbx_config already defined a context,
then the copy wasn't happening. This made
no sense, so I moved the call to copy the
includes & etc, no matter the case.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@131129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-15 23:36:19 +00:00
/* copy in the includes, switches, and ignorepats */
2008-07-23 22:03:48 +00:00
if ( first ) { /* but, only need to do this once */
context_merge_incls_swits_igps_other_registrars ( new , context , registrar ) ;
first = 0 ;
}
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( ! new ) {
ast_log ( LOG_ERROR , " Could not allocate a new context for %s in merge_and_delete! Danger! \n " , context - > name ) ;
2012-05-18 14:43:44 +00:00
ast_hashtab_end_traversal ( prio_iter ) ;
ast_hashtab_end_traversal ( exten_iter ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
return ; /* no sense continuing. */
}
/* we will not replace existing entries in the new context with stuff from the old context.
but , if this is because of some sort of registrar conflict , we ought to say something . . . */
2009-03-11 00:28:28 +00:00
2008-07-23 22:03:48 +00:00
dupdstr = ast_strdup ( prio_item - > data ) ;
2009-03-11 00:28:28 +00:00
2016-07-28 19:10:04 +00:00
res1 = ast_add_extension2 ( new , 0 , prio_item - > name , prio_item - > priority , prio_item - > label ,
2016-12-19 21:03:52 +00:00
prio_item - > matchcid ? prio_item - > cidmatch : NULL , prio_item - > app , dupdstr , ast_free_ptr , prio_item - > registrar ,
prio_item - > registrar_file , prio_item - > registrar_line ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( ! res1 & & new_exten_item & & new_prio_item ) {
ast_verb ( 3 , " Dropping old dialplan item %s/%s/%d [%s(%s)] (registrar=%s) due to conflict with new dialplan \n " ,
2016-07-28 19:10:04 +00:00
context - > name , prio_item - > name , prio_item - > priority , prio_item - > app , ( char * ) prio_item - > data , prio_item - > registrar ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
} else {
2008-07-23 22:03:48 +00:00
/* we do NOT pass the priority data from the old to the new -- we pass a copy of it, so no changes to the current dialplan take place,
and no double frees take place , either ! */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
insert_count + + ;
}
}
ast_hashtab_end_traversal ( prio_iter ) ;
}
ast_hashtab_end_traversal ( exten_iter ) ;
pbx_lua: fix regression with global sym export and context clash by pbx_config.
ASTERISK-23818 (lua contexts being overwritten by contexts of the same name in
pbx_config) surfaced because pbx_lua, having the AST_MODFLAG_GLOBAL_SYMBOLS
set, was always force loaded before pbx_config. Since I couldn't find any
reason for pbx_lua to export it's symbols to the rest of Asterisk, I simply
changed the flag to AST_MODFLAG_DEFAULT. Problem solved. What I didn't
realize was that the symbols need to be exported not because Asterisk needs
them but because any external Lua modules like luasql.mysql need the base
Lua language APIs exported (ASTERISK-17279).
Back to ASTERISK-23818... It looks like there's an issue in pbx.c where
context_merge was only merging includes, switches and ignore patterns if
the context was already existing AND has extensions, or if the context was
brand new. If pbx_lua is loaded before pbx_config, the context will exist
BUT pbx_lua, being implemented as a switch, will never place extensions in
it, just the switch statement. The result is that when pbx_config loads,
it never merges the switch statement created by pbx_lua into the final
context.
This patch sets pbx_lua's modflag back to AST_MODFLAG_GLOBAL_SYMBOLS and adds
an "else if" in context_merge that catches the case where an existing context
has includes, switchs or ingore patterns but no actual extensions.
ASTERISK-23818 #close
Reported by: Dennis Guse
Reported by: Timo Teräs
Tested by: George Joseph
Review: https://reviewboard.asterisk.org/r/3891/
........
Merged revisions 420146 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 420147 from http://svn.asterisk.org/svn/asterisk/branches/11
........
Merged revisions 420148 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@420149 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-08-06 16:12:26 +00:00
} else if ( new ) {
/* If the context existed but had no extensions, we still want to merge
* the includes , switches and ignore patterns .
*/
context_merge_incls_swits_igps_other_registrars ( new , context , registrar ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
}
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( ! insert_count & & ! new & & ( strcmp ( context - > registrar , registrar ) ! = 0 | |
( strcmp ( context - > registrar , registrar ) = = 0 & & context - > refcount > 1 ) ) ) {
/* we could have given it the registrar of the other module who incremented the refcount,
but that ' s not available , so we give it the registrar we know about */
new = ast_context_find_or_create ( extcontexts , exttable , context - > name , context - > registrar ) ;
2009-03-11 00:28:28 +00:00
2016-03-28 16:31:29 +00:00
if ( new ) {
new - > autohints = context - > autohints ;
}
(closes issue #12238)
Reported by: mvanbaak
Tested by: murf, mvanbaak
Due to a bug that occurred when merge_contexts_and_delete scanned the "old" or existing contexts, and found a context
that doesn't exist in the new set, yet owned by a different registrar. The context is created in the new set, with the
old registrar, and and all the priorities and extens that have a different registrar are copied into it. But, not the
includes, ignorepats, and switches. I added code to do this immediately after the context is created.
This still leaves a logical hole in the code. If you define a context in two places, (eg. in extensions.conf and also
in extensions.ael), and they both have includes, but different in composition, no new context will be generated, and
therefore the 'old' includes, switches, and ignorepats will not be copied. I'd have added code to simply add any non-duplicates
into the 'new' context that had a different registrar, but there is one big complication: includes, and switches are definitely
order dependent. (ignorepats I'm not sure about). And we'll have to develop some sort of policy about how we
merge order dependent lists, especially if the intersection of the two sets is empty. (in other words, they do not have any
elements in common). Do the new go first, or the old? I've elected to punt this issue until a user complains. Hopefully,
this is pretty rare thing.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@109169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-17 17:47:36 +00:00
/* copy in the includes, switches, and ignorepats */
context_merge_incls_swits_igps_other_registrars ( new , context , registrar ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
}
}
2006-05-09 07:49:17 +00:00
/* XXX this does not check that multiple contexts are merged */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
void ast_merge_contexts_and_delete ( struct ast_context * * extcontexts , struct ast_hashtab * exttable , const char * registrar )
2005-08-27 23:55:14 +00:00
{
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
double ft ;
2011-07-08 01:26:01 +00:00
struct ast_context * tmp ;
struct ast_context * oldcontextslist ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
struct ast_hashtab * oldtable ;
2011-12-23 02:35:13 +00:00
struct store_hints hints_stored = AST_LIST_HEAD_NOLOCK_INIT_VALUE ;
struct store_hints hints_removed = AST_LIST_HEAD_NOLOCK_INIT_VALUE ;
2011-07-22 20:46:36 +00:00
struct store_hint * saved_hint ;
2005-08-27 23:55:14 +00:00
struct ast_hint * hint ;
struct ast_exten * exten ;
int length ;
2008-03-19 15:45:49 +00:00
struct ast_state_cb * thiscb ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
struct ast_hashtab_iter * iter ;
2010-11-30 09:49:25 +00:00
struct ao2_iterator i ;
2011-07-08 01:26:01 +00:00
struct timeval begintime ;
struct timeval writelocktime ;
struct timeval endlocktime ;
struct timeval enddeltime ;
2009-03-11 00:28:28 +00:00
2011-07-08 01:26:01 +00:00
/*
* It is very important that this function hold the hints
* container lock _and_ the conlock during its operation ; not
* only do we need to ensure that the list of contexts and
* extensions does not change , but also that no hint callbacks
* ( watchers ) are added or removed during the merge / delete
* process
*
* In addition , the locks _must_ be taken in this order , because
* there are already other code paths that use this order
*/
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
begintime = ast_tvnow ( ) ;
2011-07-22 20:46:36 +00:00
ast_mutex_lock ( & context_merge_lock ) ; /* Serialize ast_merge_contexts_and_delete */
2011-08-09 23:17:13 +00:00
ast_wrlock_contexts ( ) ;
2014-02-16 03:25:15 +00:00
if ( ! contexts_table ) {
2016-03-28 16:31:29 +00:00
/* Create any autohint contexts */
context_table_create_autohints ( exttable ) ;
2014-02-16 03:25:15 +00:00
/* Well, that's odd. There are no contexts. */
contexts_table = exttable ;
contexts = * extcontexts ;
ast_unlock_contexts ( ) ;
ast_mutex_unlock ( & context_merge_lock ) ;
return ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
iter = ast_hashtab_start_traversal ( contexts_table ) ;
2008-03-19 15:45:49 +00:00
while ( ( tmp = ast_hashtab_next ( iter ) ) ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
context_merge ( extcontexts , exttable , tmp , registrar ) ;
}
ast_hashtab_end_traversal ( iter ) ;
2009-03-11 00:28:28 +00:00
2010-11-30 09:49:25 +00:00
ao2_lock ( hints ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
writelocktime = ast_tvnow ( ) ;
2006-03-31 18:28:52 +00:00
2010-01-05 19:29:47 +00:00
/* preserve all watchers for hints */
2010-11-30 09:49:25 +00:00
i = ao2_iterator_init ( hints , AO2_ITERATOR_DONTLOCK ) ;
2011-07-22 21:15:28 +00:00
for ( ; ( hint = ao2_iterator_next ( & i ) ) ; ao2_ref ( hint , - 1 ) ) {
2011-01-18 20:40:59 +00:00
if ( ao2_container_count ( hint - > callbacks ) ) {
2011-07-22 20:46:36 +00:00
ao2_lock ( hint ) ;
if ( ! hint - > exten ) {
/* The extension has already been destroyed. (Should never happen here) */
ao2_unlock ( hint ) ;
2005-08-27 23:55:14 +00:00
continue ;
2010-11-30 09:49:25 +00:00
}
2011-07-22 20:46:36 +00:00
length = strlen ( hint - > exten - > exten ) + strlen ( hint - > exten - > parent - > name ) + 2
+ sizeof ( * saved_hint ) ;
if ( ! ( saved_hint = ast_calloc ( 1 , length ) ) ) {
2010-11-30 09:49:25 +00:00
ao2_unlock ( hint ) ;
continue ;
}
2011-07-22 20:46:36 +00:00
/* This removes all the callbacks from the hint into saved_hint. */
2011-01-18 20:40:59 +00:00
while ( ( thiscb = ao2_callback ( hint - > callbacks , OBJ_UNLINK , NULL , NULL ) ) ) {
2011-07-22 20:46:36 +00:00
AST_LIST_INSERT_TAIL ( & saved_hint - > callbacks , thiscb , entry ) ;
/*
* We intentionally do not unref thiscb to account for the
* non - ao2 reference in saved_hint - > callbacks
*/
2011-01-18 20:40:59 +00:00
}
2011-07-22 20:46:36 +00:00
saved_hint - > laststate = hint - > laststate ;
saved_hint - > context = saved_hint - > data ;
strcpy ( saved_hint - > data , hint - > exten - > parent - > name ) ;
saved_hint - > exten = saved_hint - > data + strlen ( saved_hint - > context ) + 1 ;
strcpy ( saved_hint - > exten , hint - > exten - > exten ) ;
2012-06-04 20:26:12 +00:00
if ( hint - > last_presence_subtype ) {
saved_hint - > last_presence_subtype = ast_strdup ( hint - > last_presence_subtype ) ;
}
if ( hint - > last_presence_message ) {
saved_hint - > last_presence_message = ast_strdup ( hint - > last_presence_message ) ;
}
saved_hint - > last_presence_state = hint - > last_presence_state ;
2010-11-30 09:49:25 +00:00
ao2_unlock ( hint ) ;
2011-12-23 02:35:13 +00:00
AST_LIST_INSERT_HEAD ( & hints_stored , saved_hint , list ) ;
2005-08-27 23:55:14 +00:00
}
}
2012-01-27 18:47:16 +00:00
ao2_iterator_destroy ( & i ) ;
2005-08-27 23:55:14 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
/* save the old table and list */
oldtable = contexts_table ;
oldcontextslist = contexts ;
2005-08-27 23:55:14 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
/* move in the new table and list */
contexts_table = exttable ;
contexts = * extcontexts ;
2009-03-11 00:28:28 +00:00
2011-07-22 20:46:36 +00:00
/*
* Restore the watchers for hints that can be found ; notify
* those that cannot be restored .
*/
2011-12-23 02:35:13 +00:00
while ( ( saved_hint = AST_LIST_REMOVE_HEAD ( & hints_stored , list ) ) ) {
2007-12-31 23:44:45 +00:00
struct pbx_find_info q = { . stacklen = 0 } ;
2011-07-22 20:46:36 +00:00
exten = pbx_find_extension ( NULL , NULL , & q , saved_hint - > context , saved_hint - > exten ,
PRIORITY_HINT , NULL , " " , E_MATCH ) ;
/*
* If this is a pattern , dynamically create a new extension for this
2008-03-19 16:54:12 +00:00
* 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 ] = = ' _ ' ) {
2011-07-22 20:46:36 +00:00
ast_add_extension_nolock ( exten - > parent - > name , 0 , saved_hint - > exten ,
PRIORITY_HINT , NULL , 0 , exten - > app , ast_strdup ( exten - > data ) , ast_free_ptr ,
exten - > registrar ) ;
2008-10-30 00:45:47 +00:00
/* rwlocks are not recursive locks */
2011-07-22 20:46:36 +00:00
exten = ast_hint_extension_nolock ( NULL , saved_hint - > context ,
saved_hint - > exten ) ;
2008-03-19 16:54:12 +00:00
}
2011-07-22 20:46:36 +00:00
/* Find the hint in the hints container */
hint = exten ? ao2_find ( hints , exten , 0 ) : NULL ;
if ( ! hint ) {
2011-12-23 02:35:13 +00:00
/*
* Notify watchers of this removed hint later when we aren ' t
* encumberd by so many locks .
*/
AST_LIST_INSERT_HEAD ( & hints_removed , saved_hint , list ) ;
2005-08-27 23:55:14 +00:00
} else {
2010-11-30 09:49:25 +00:00
ao2_lock ( hint ) ;
2011-07-22 20:46:36 +00:00
while ( ( thiscb = AST_LIST_REMOVE_HEAD ( & saved_hint - > callbacks , entry ) ) ) {
2011-01-18 20:40:59 +00:00
ao2_link ( hint - > callbacks , thiscb ) ;
2011-07-22 20:46:36 +00:00
/* Ref that we added when putting into saved_hint->callbacks */
ao2_ref ( thiscb , - 1 ) ;
2011-01-18 20:40:59 +00:00
}
2011-07-22 20:46:36 +00:00
hint - > laststate = saved_hint - > laststate ;
2012-06-04 20:26:12 +00:00
hint - > last_presence_state = saved_hint - > last_presence_state ;
hint - > last_presence_subtype = saved_hint - > last_presence_subtype ;
hint - > last_presence_message = saved_hint - > last_presence_message ;
2010-11-30 09:49:25 +00:00
ao2_unlock ( hint ) ;
ao2_ref ( hint , - 1 ) ;
2012-06-04 20:26:12 +00:00
/*
* The free of saved_hint - > last_presence_subtype and
* saved_hint - > last_presence_message is not necessary here .
*/
2011-12-23 02:35:13 +00:00
ast_free ( saved_hint ) ;
2010-11-30 09:49:25 +00:00
}
2005-08-27 23:55:14 +00:00
}
2016-03-28 16:31:29 +00:00
/* Create all applicable autohint contexts */
context_table_create_autohints ( contexts_table ) ;
2010-11-30 09:49:25 +00:00
ao2_unlock ( hints ) ;
2007-02-28 20:46:01 +00:00
ast_unlock_contexts ( ) ;
2011-12-23 02:35:13 +00:00
/*
* Notify watchers of all removed hints with the same lock
2013-04-16 15:33:59 +00:00
* environment as device_state_cb ( ) .
2011-12-23 02:35:13 +00:00
*/
while ( ( saved_hint = AST_LIST_REMOVE_HEAD ( & hints_removed , list ) ) ) {
/* this hint has been removed, notify the watchers */
while ( ( thiscb = AST_LIST_REMOVE_HEAD ( & saved_hint - > callbacks , entry ) ) ) {
2012-06-04 20:26:12 +00:00
execute_state_callback ( thiscb - > change_cb ,
saved_hint - > context ,
saved_hint - > exten ,
thiscb - > data ,
AST_HINT_UPDATE_DEVICE ,
2012-08-09 14:52:16 +00:00
NULL ,
2012-06-04 20:26:12 +00:00
NULL ) ;
2011-12-23 02:35:13 +00:00
/* Ref that we added when putting into saved_hint->callbacks */
ao2_ref ( thiscb , - 1 ) ;
}
2012-06-04 20:26:12 +00:00
ast_free ( saved_hint - > last_presence_subtype ) ;
ast_free ( saved_hint - > last_presence_message ) ;
2011-12-23 02:35:13 +00:00
ast_free ( saved_hint ) ;
}
2011-07-22 20:46:36 +00:00
ast_mutex_unlock ( & context_merge_lock ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
endlocktime = ast_tvnow ( ) ;
2009-03-11 00:28:28 +00:00
2011-07-08 01:26:01 +00:00
/*
* The old list and hashtab no longer are relevant , delete them
* while the rest of asterisk is now freely using the new stuff
* instead .
*/
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_destroy ( oldtable , NULL ) ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
for ( tmp = oldcontextslist ; tmp ; ) {
struct ast_context * next ; /* next starting point */
2011-07-08 01:26:01 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
next = tmp - > next ;
__ast_internal_context_destroy ( tmp ) ;
tmp = next ;
}
enddeltime = ast_tvnow ( ) ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ft = ast_tvdiff_us ( writelocktime , begintime ) ;
ft / = 1000000.0 ;
ast_verb ( 3 , " Time to scan old dialplan and merge leftovers back into the new: %8.6f sec \n " , ft ) ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ft = ast_tvdiff_us ( endlocktime , writelocktime ) ;
ft / = 1000000.0 ;
ast_verb ( 3 , " Time to restore hints and swap in new dialplan: %8.6f sec \n " , ft ) ;
ft = ast_tvdiff_us ( enddeltime , endlocktime ) ;
ft / = 1000000.0 ;
ast_verb ( 3 , " Time to delete the old dialplan: %8.6f sec \n " , ft ) ;
ft = ast_tvdiff_us ( enddeltime , begintime ) ;
ft / = 1000000.0 ;
ast_verb ( 3 , " Total time merge_contexts_delete: %8.6f sec \n " , ft ) ;
2003-07-14 15:35:21 +00:00
}
2001-09-28 21:20:52 +00:00
/*
* errno values
* EBUSY - can ' t lock
2003-04-23 19:13:35 +00:00
* ENOENT - no existence of context
2001-09-28 21:20:52 +00:00
*/
2004-10-03 04:19:59 +00:00
int ast_context_add_include ( const char * context , const char * include , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2006-04-19 08:52:15 +00:00
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-19 08:52:15 +00:00
if ( c ) {
ret = ast_context_add_include2 ( c , include , registrar ) ;
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2006-04-19 08:52:15 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
/*
* errno values
* ENOMEM - out of memory
* EBUSY - can ' t lock
* EEXIST - already included
* EINVAL - there is no existence of context for inclusion
*/
2004-10-03 04:19:59 +00:00
int ast_context_add_include2 ( struct ast_context * con , const char * value ,
const char * registrar )
2001-09-28 21:20:52 +00:00
{
struct ast_include * new_include ;
2016-07-14 18:51:42 +00:00
int idx ;
2001-09-28 21:20:52 +00:00
/* allocate new include structure ... */
2016-07-14 18:51:42 +00:00
new_include = include_alloc ( value , registrar ) ;
if ( ! new_include ) {
2001-09-28 21:20:52 +00:00
return - 1 ;
2002-06-21 01:40:13 +00:00
}
2001-09-28 21:20:52 +00:00
2007-02-28 20:46:01 +00:00
ast_wrlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
/* ... go to last include and check if context is already included too... */
2016-07-14 18:51:42 +00:00
for ( idx = 0 ; idx < ast_context_includes_count ( con ) ; idx + + ) {
const struct ast_include * i = ast_context_includes_get ( con , idx ) ;
if ( ! strcasecmp ( ast_get_include_name ( i ) , ast_get_include_name ( new_include ) ) ) {
2016-07-14 07:40:26 +00:00
include_free ( new_include ) ;
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
errno = EEXIST ;
return - 1 ;
}
}
/* ... include new context into context list, unlock, return */
2017-11-06 21:16:35 +00:00
if ( AST_VECTOR_APPEND ( & con - > includes , new_include ) ) {
include_free ( new_include ) ;
ast_unlock_context ( con ) ;
return - 1 ;
}
2016-07-14 18:51:42 +00:00
ast_verb ( 3 , " Including context '%s' in context '%s' \n " ,
ast_get_include_name ( new_include ) , ast_get_context_name ( con ) ) ;
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
return 0 ;
}
/*
* errno values
* EBUSY - can ' t lock
2003-04-23 19:13:35 +00:00
* ENOENT - no existence of context
2001-09-28 21:20:52 +00:00
*/
2005-01-13 05:14:56 +00:00
int ast_context_add_switch ( const char * context , const char * sw , const char * data , int eval , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2006-04-21 11:30:02 +00:00
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-21 11:30:02 +00:00
if ( c ) { /* found, add switch to this context */
ret = ast_context_add_switch2 ( c , sw , data , eval , registrar ) ;
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2006-04-21 11:30:02 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
/*
* errno values
* ENOMEM - out of memory
* EBUSY - can ' t lock
* EEXIST - already included
* EINVAL - there is no existence of context for inclusion
*/
2004-10-03 04:19:59 +00:00
int ast_context_add_switch2 ( struct ast_context * con , const char * value ,
2005-01-13 05:14:56 +00:00
const char * data , int eval , const char * registrar )
2001-03-30 18:47:35 +00:00
{
2016-07-16 00:28:16 +00:00
int idx ;
2001-09-28 21:20:52 +00:00
struct ast_sw * new_sw ;
/* allocate new sw structure ... */
2016-07-16 00:28:16 +00:00
if ( ! ( new_sw = sw_alloc ( value , data , eval , registrar ) ) ) {
2001-03-30 18:47:35 +00:00
return - 1 ;
2005-01-13 05:14:56 +00:00
}
2001-09-28 21:20:52 +00:00
/* ... try to lock this context ... */
2007-02-28 20:46:01 +00:00
ast_wrlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
/* ... go to last sw and check if context is already swd too... */
2016-07-16 00:28:16 +00:00
for ( idx = 0 ; idx < ast_context_switches_count ( con ) ; idx + + ) {
const struct ast_sw * i = ast_context_switches_get ( con , idx ) ;
if ( ! strcasecmp ( ast_get_switch_name ( i ) , ast_get_switch_name ( new_sw ) ) & &
! strcasecmp ( ast_get_switch_data ( i ) , ast_get_switch_data ( new_sw ) ) ) {
sw_free ( new_sw ) ;
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
errno = EEXIST ;
return - 1 ;
}
}
/* ... sw new context into context list, unlock, return */
2017-11-06 21:16:35 +00:00
if ( AST_VECTOR_APPEND ( & con - > alts , new_sw ) ) {
sw_free ( new_sw ) ;
ast_unlock_context ( con ) ;
return - 1 ;
}
2006-05-09 08:03:52 +00:00
2016-07-16 00:28:16 +00:00
ast_verb ( 3 , " Including switch '%s/%s' in context '%s' \n " ,
ast_get_switch_name ( new_sw ) , ast_get_switch_data ( new_sw ) , ast_get_context_name ( con ) ) ;
2006-05-08 11:20:19 +00:00
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
return 0 ;
}
/*
* EBUSY - can ' t lock
2003-04-23 19:13:35 +00:00
* ENOENT - there is not context existence
2001-09-28 21:20:52 +00:00
*/
2004-10-03 04:19:59 +00:00
int ast_context_remove_ignorepat ( const char * context , const char * ignorepat , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2006-04-19 08:52:15 +00:00
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-19 08:52:15 +00:00
if ( c ) {
ret = ast_context_remove_ignorepat2 ( c , ignorepat , registrar ) ;
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2006-04-19 08:52:15 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_context_remove_ignorepat2 ( struct ast_context * con , const char * ignorepat , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2016-07-15 07:59:48 +00:00
int idx ;
2001-09-28 21:20:52 +00:00
2007-02-28 20:46:01 +00:00
ast_wrlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
2016-07-15 07:59:48 +00:00
for ( idx = 0 ; idx < ast_context_ignorepats_count ( con ) ; idx + + ) {
struct ast_ignorepat * ip = AST_VECTOR_GET ( & con - > ignorepats , idx ) ;
if ( ! strcmp ( ast_get_ignorepat_name ( ip ) , ignorepat ) & &
( ! registrar | | ( registrar = = ast_get_ignorepat_registrar ( ip ) ) ) ) {
AST_VECTOR_REMOVE_ORDERED ( & con - > ignorepats , idx ) ;
ignorepat_free ( ip ) ;
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
return 0 ;
}
}
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2001-09-28 21:20:52 +00:00
errno = EINVAL ;
return - 1 ;
}
/*
* EBUSY - can ' t lock
2003-04-23 19:13:35 +00:00
* ENOENT - there is no existence of context
2001-09-28 21:20:52 +00:00
*/
2006-04-19 08:52:15 +00:00
int ast_context_add_ignorepat ( const char * context , const char * value , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2006-04-19 08:52:15 +00:00
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-19 08:52:15 +00:00
if ( c ) {
ret = ast_context_add_ignorepat2 ( c , value , registrar ) ;
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2006-04-19 08:52:15 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_context_add_ignorepat2 ( struct ast_context * con , const char * value , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2016-07-15 07:59:48 +00:00
struct ast_ignorepat * ignorepat = ignorepat_alloc ( value , registrar ) ;
int idx ;
if ( ! ignorepat ) {
2001-09-28 21:20:52 +00:00
return - 1 ;
2016-07-15 07:59:48 +00:00
}
2007-02-28 20:46:01 +00:00
ast_wrlock_context ( con ) ;
2016-07-15 07:59:48 +00:00
for ( idx = 0 ; idx < ast_context_ignorepats_count ( con ) ; idx + + ) {
const struct ast_ignorepat * i = ast_context_ignorepats_get ( con , idx ) ;
if ( ! strcasecmp ( ast_get_ignorepat_name ( i ) , value ) ) {
2001-03-30 18:47:35 +00:00
/* Already there */
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2016-07-15 07:59:48 +00:00
ignorepat_free ( ignorepat ) ;
2001-09-28 21:20:52 +00:00
errno = EEXIST ;
return - 1 ;
2001-03-30 18:47:35 +00:00
}
}
2017-11-06 21:16:35 +00:00
if ( AST_VECTOR_APPEND ( & con - > ignorepats , ignorepat ) ) {
ignorepat_free ( ignorepat ) ;
ast_unlock_context ( con ) ;
return - 1 ;
}
2007-02-28 20:46:01 +00:00
ast_unlock_context ( con ) ;
2006-05-09 08:03:52 +00:00
2016-07-15 07:59:48 +00:00
return 0 ;
2001-03-30 18:47:35 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_ignore_pattern ( const char * context , const char * pattern )
2001-09-28 21:20:52 +00:00
{
2015-06-08 15:09:57 +00:00
int ret = 0 ;
struct ast_context * con ;
2011-07-08 01:26:01 +00:00
2015-06-08 15:09:57 +00:00
ast_rdlock_contexts ( ) ;
con = ast_context_find ( context ) ;
2001-09-28 21:20:52 +00:00
if ( con ) {
2016-07-15 07:59:48 +00:00
int idx ;
2011-07-08 01:26:01 +00:00
2016-07-15 07:59:48 +00:00
for ( idx = 0 ; idx < ast_context_ignorepats_count ( con ) ; idx + + ) {
const struct ast_ignorepat * pat = ast_context_ignorepats_get ( con , idx ) ;
if ( ast_extension_match ( ast_get_ignorepat_name ( pat ) , pattern ) ) {
2015-06-08 15:09:57 +00:00
ret = 1 ;
break ;
}
2001-09-28 21:20:52 +00:00
}
2006-05-09 08:03:52 +00:00
}
2015-06-08 15:09:57 +00:00
ast_unlock_contexts ( ) ;
2006-05-08 22:47:03 +00:00
2015-06-08 15:09:57 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2009-02-18 15:35:26 +00:00
/*
* ast_add_extension_nolock - - use only in situations where the conlock is already held
* ENOENT - no existence of context
*
*/
static int ast_add_extension_nolock ( const char * context , int replace , const char * extension ,
int priority , const char * label , const char * callerid ,
const char * application , void * data , void ( * datad ) ( void * ) , const char * registrar )
{
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2009-02-18 15:35:26 +00:00
2011-07-08 01:26:01 +00:00
c = find_context ( context ) ;
2009-02-18 15:35:26 +00:00
if ( c ) {
ret = ast_add_extension2_lockopt ( c , replace , extension , priority , label , callerid ,
2016-12-19 21:03:52 +00:00
application , data , datad , registrar , NULL , 0 , 1 ) ;
2009-02-18 15:35:26 +00:00
}
2009-03-11 00:28:28 +00:00
2009-02-18 15:35:26 +00:00
return ret ;
}
2001-09-28 21:20:52 +00:00
/*
* EBUSY - can ' t lock
2003-04-23 19:13:35 +00:00
* ENOENT - no existence of context
2001-09-28 21:20:52 +00:00
*
*/
2006-04-19 08:52:15 +00:00
int ast_add_extension ( const char * context , int replace , const char * extension ,
int priority , const char * label , const char * callerid ,
2004-10-03 04:19:59 +00:00
const char * application , void * data , void ( * datad ) ( void * ) , const char * registrar )
2001-09-28 21:20:52 +00:00
{
2006-04-19 08:52:15 +00:00
int ret = - 1 ;
2011-07-08 01:26:01 +00:00
struct ast_context * c ;
2001-09-28 21:20:52 +00:00
2011-07-08 01:26:01 +00:00
c = find_context_locked ( context ) ;
2006-04-19 08:52:15 +00:00
if ( c ) {
ret = ast_add_extension2 ( c , replace , extension , priority , label , callerid ,
2016-12-19 21:03:52 +00:00
application , data , datad , registrar , NULL , 0 ) ;
2006-04-19 08:52:15 +00:00
ast_unlock_contexts ( ) ;
2001-09-28 21:20:52 +00:00
}
2009-03-11 00:28:28 +00:00
2006-04-19 08:52:15 +00:00
return ret ;
2001-09-28 21:20:52 +00:00
}
2005-04-29 15:04:26 +00:00
int ast_explicit_goto ( struct ast_channel * chan , const char * context , const char * exten , int priority )
{
if ( ! chan )
return - 1 ;
2007-11-28 00:24:19 +00:00
ast_channel_lock ( chan ) ;
2005-10-26 18:54:24 +00:00
if ( ! ast_strlen_zero ( context ) )
2012-02-13 17:27:06 +00:00
ast_channel_context_set ( chan , context ) ;
2005-10-26 18:54:24 +00:00
if ( ! ast_strlen_zero ( exten ) )
2012-02-13 17:27:06 +00:00
ast_channel_exten_set ( chan , exten ) ;
2008-02-05 20:51:50 +00:00
if ( priority > - 1 ) {
/* see flag description in channel.h for explanation */
2012-03-13 18:20:34 +00:00
if ( ast_test_flag ( ast_channel_flags ( chan ) , AST_FLAG_IN_AUTOLOOP ) ) {
2012-04-20 16:04:37 +00:00
- - priority ;
2012-02-20 23:43:27 +00:00
}
2012-04-20 16:04:37 +00:00
ast_channel_priority_set ( chan , priority ) ;
2008-02-05 20:51:50 +00:00
}
2006-05-09 08:03:52 +00:00
2007-11-28 00:24:19 +00:00
ast_channel_unlock ( chan ) ;
2005-04-29 15:04:26 +00:00
return 0 ;
2004-11-23 20:25:02 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_async_goto ( struct ast_channel * chan , const char * context , const char * exten , int priority )
2002-09-11 17:09:48 +00:00
{
2013-05-28 14:45:31 +00:00
struct ast_channel * newchan ;
2005-04-29 15:04:26 +00:00
2006-04-29 14:50:18 +00:00
ast_channel_lock ( chan ) ;
2013-05-21 18:00:22 +00:00
/* Channels in a bridge or running a PBX can be sent directly to the specified destination */
if ( ast_channel_is_bridged ( chan ) | | ast_channel_pbx ( chan ) ) {
if ( ast_test_flag ( ast_channel_flags ( chan ) , AST_FLAG_IN_AUTOLOOP ) ) {
priority + = 1 ;
}
ast_explicit_goto ( chan , context , exten , priority ) ;
2002-09-11 17:09:48 +00:00
ast_softhangup_nolock ( chan , AST_SOFTHANGUP_ASYNCGOTO ) ;
2011-06-21 20:15:41 +00:00
ast_channel_unlock ( chan ) ;
2013-05-28 14:45:31 +00:00
return 0 ;
2011-06-21 20:15:41 +00:00
}
ast_channel_unlock ( chan ) ;
2013-05-28 14:45:31 +00:00
/* Otherwise, we need to gain control of the channel first */
newchan = ast_channel_yank ( chan ) ;
if ( ! newchan ) {
ast_log ( LOG_WARNING , " Unable to gain control of channel %s \n " , ast_channel_name ( chan ) ) ;
2011-06-21 20:15:41 +00:00
return - 1 ;
}
2013-05-28 14:45:31 +00:00
ast_explicit_goto ( newchan , context , exten , priority ) ;
if ( ast_pbx_start ( newchan ) ) {
ast_hangup ( newchan ) ;
ast_log ( LOG_WARNING , " Unable to start PBX on %s \n " , ast_channel_name ( newchan ) ) ;
return - 1 ;
2002-09-11 17:09:48 +00:00
}
2011-06-21 20:15:41 +00:00
2013-05-28 14:45:31 +00:00
return 0 ;
2002-09-11 17:09:48 +00:00
}
2004-10-03 04:19:59 +00:00
int ast_async_goto_by_name ( const char * channame , const char * context , const char * exten , int priority )
2002-09-11 17:09:48 +00:00
{
struct ast_channel * chan ;
2004-05-20 16:30:10 +00:00
int res = - 1 ;
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
if ( ( chan = ast_channel_get_by_name ( channame ) ) ) {
2004-05-20 16:30:10 +00:00
res = ast_async_goto ( chan , context , exten , priority ) ;
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
chan = ast_channel_unref ( chan ) ;
2004-05-20 16:30:10 +00:00
}
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
2004-05-20 16:30:10 +00:00
return res ;
2002-09-11 17:09:48 +00:00
}
2017-03-14 21:16:23 +00:00
/*!
* \ internal
* \ brief Copy a string skipping whitespace and optionally dashes .
*
* \ param dst Destination buffer to copy src string .
* \ param src Null terminated string to copy .
* \ param dst_size Number of bytes in the dst buffer .
* \ param nofluf Nonzero if ' - ' chars are not copied .
*
* \ return Number of bytes written to dst including null terminator .
*/
static unsigned int ext_strncpy ( char * dst , const char * src , size_t dst_size , int nofluff )
2001-09-28 21:20:52 +00:00
{
2017-03-14 21:16:23 +00:00
unsigned int count ;
unsigned int insquares ;
unsigned int is_pattern ;
2004-07-17 02:25:53 +00:00
2017-03-14 21:16:23 +00:00
if ( ! dst_size - - ) {
/* There really is no dst buffer */
return 0 ;
}
count = 0 ;
insquares = 0 ;
is_pattern = * src = = ' _ ' ;
while ( * src & & count < dst_size ) {
2008-11-21 23:33:22 +00:00
if ( * src = = ' [ ' ) {
2017-03-14 21:16:23 +00:00
if ( is_pattern ) {
insquares = 1 ;
}
2008-11-21 23:33:22 +00:00
} else if ( * src = = ' ] ' ) {
insquares = 0 ;
} else if ( * src = = ' ' & & ! insquares ) {
2017-03-14 21:16:23 +00:00
+ + src ;
2008-11-21 23:33:22 +00:00
continue ;
2016-07-28 19:10:04 +00:00
} else if ( * src = = ' - ' & & ! insquares & & nofluff ) {
2017-03-14 21:16:23 +00:00
+ + src ;
2016-07-28 19:10:04 +00:00
continue ;
2001-09-28 21:20:52 +00:00
}
2017-03-14 21:16:23 +00:00
* dst + + = * src + + ;
+ + count ;
2001-09-28 21:20:52 +00:00
}
* dst = ' \0 ' ;
2004-12-19 17:16:39 +00:00
2017-03-14 21:16:23 +00:00
return count + 1 ;
2001-09-28 21:20:52 +00:00
}
2009-03-11 00:28:28 +00:00
/*!
2007-08-07 23:04:01 +00:00
* \ brief add the extension in the priority chain .
* \ retval 0 on success .
* \ retval - 1 on failure .
*/
2011-07-08 01:26:01 +00:00
static int add_priority ( struct ast_context * con , struct ast_exten * tmp ,
2006-05-09 08:31:42 +00:00
struct ast_exten * el , struct ast_exten * e , int replace )
{
struct ast_exten * ep ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
struct ast_exten * eh = e ;
2011-12-05 15:04:12 +00:00
int repeated_label = 0 ; /* Track if this label is a repeat, assume no. */
2006-05-09 08:31:42 +00:00
for ( ep = NULL ; e ; ep = e , e = e - > peer ) {
2011-12-05 15:04:12 +00:00
if ( e - > label & & tmp - > label & & e - > priority ! = tmp - > priority & & ! strcmp ( e - > label , tmp - > label ) ) {
2016-07-28 19:10:04 +00:00
if ( strcmp ( e - > name , tmp - > name ) ) {
2012-11-28 00:13:10 +00:00
ast_log ( LOG_WARNING ,
" Extension '%s' priority %d in '%s', label '%s' already in use at aliased extension '%s' priority %d \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , con - > name , tmp - > label , e - > name , e - > priority ) ;
2012-11-28 00:13:10 +00:00
} else {
ast_log ( LOG_WARNING ,
" Extension '%s' priority %d in '%s', label '%s' already in use at priority %d \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , con - > name , tmp - > label , e - > priority ) ;
2012-11-28 00:13:10 +00:00
}
2011-12-05 15:04:12 +00:00
repeated_label = 1 ;
}
if ( e - > priority > = tmp - > priority ) {
2006-05-09 08:31:42 +00:00
break ;
2011-12-05 15:04:12 +00:00
}
2006-05-09 08:31:42 +00:00
}
2011-12-05 15:04:12 +00:00
if ( repeated_label ) { /* Discard the label since it's a repeat. */
tmp - > label = NULL ;
}
2006-05-09 08:31:42 +00:00
if ( ! e ) { /* go at the end, and ep is surely set because the list is not empty */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( eh - > peer_table , tmp ) ;
2009-03-11 00:28:28 +00:00
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( tmp - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( eh - > peer_label_table , tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
2006-05-09 08:31:42 +00:00
ep - > peer = tmp ;
return 0 ; /* success */
}
if ( e - > priority = = tmp - > priority ) {
/* Can't have something exactly the same. Is this a
replacement ? If so , replace , otherwise , bonk . */
if ( ! replace ) {
2016-07-28 19:10:04 +00:00
if ( strcmp ( e - > name , tmp - > name ) ) {
2012-11-28 00:13:10 +00:00
ast_log ( LOG_WARNING ,
" Unable to register extension '%s' priority %d in '%s', already in use by aliased extension '%s' \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , con - > name , e - > name ) ;
2012-11-28 00:13:10 +00:00
} else {
ast_log ( LOG_WARNING ,
" Unable to register extension '%s' priority %d in '%s', already in use \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , con - > name ) ;
2012-11-28 00:13:10 +00:00
}
2009-03-11 00:28:28 +00:00
2006-05-09 08:31:42 +00:00
return - 1 ;
}
/* we are replacing e, so copy the link fields and then update
* whoever pointed to e to point to us
*/
tmp - > next = e - > next ; /* not meaningful if we are not first in the peer list */
tmp - > peer = e - > peer ; /* always meaningful */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
if ( ep ) { /* We're in the peer list, just insert ourselves */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( eh - > peer_table , e ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( e - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( eh - > peer_label_table , e ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( eh - > peer_table , tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( tmp - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( eh - > peer_label_table , tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
2009-03-11 00:28:28 +00:00
2006-05-09 08:31:42 +00:00
ep - > peer = tmp ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else if ( el ) { /* We're the first extension. Take over e's functions */
2007-11-21 01:09:47 +00:00
struct match_char * x = add_exten_to_pattern_tree ( con , e , 1 ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
tmp - > peer_table = e - > peer_table ;
tmp - > peer_label_table = e - > peer_label_table ;
ast_hashtab_remove_object_via_lookup ( tmp - > peer_table , e ) ;
ast_hashtab_insert_safe ( tmp - > peer_table , tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( e - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( tmp - > peer_label_table , e ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
if ( tmp - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( tmp - > peer_label_table , tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( con - > root_table , e ) ;
ast_hashtab_insert_safe ( con - > root_table , tmp ) ;
2006-05-09 08:31:42 +00:00
el - > next = tmp ;
2007-11-21 01:09:47 +00:00
/* The pattern trie points to this exten; replace the pointer,
and all will be well */
2008-04-22 21:57:57 +00:00
if ( x ) { /* if the trie isn't formed yet, don't sweat this */
if ( x - > exten ) { /* this test for safety purposes */
x - > exten = tmp ; /* replace what would become a bad pointer */
} else {
ast_log ( LOG_ERROR , " Trying to delete an exten from a context, but the pattern tree node returned isn't an extension \n " ) ;
}
2007-11-21 01:09:47 +00:00
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else { /* We're the very first extension. */
2007-11-21 01:09:47 +00:00
struct match_char * x = add_exten_to_pattern_tree ( con , e , 1 ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( con - > root_table , e ) ;
ast_hashtab_insert_safe ( con - > root_table , tmp ) ;
tmp - > peer_table = e - > peer_table ;
tmp - > peer_label_table = e - > peer_label_table ;
ast_hashtab_remove_object_via_lookup ( tmp - > peer_table , e ) ;
ast_hashtab_insert_safe ( tmp - > peer_table , tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( e - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( tmp - > peer_label_table , e ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
if ( tmp - > label ) {
ast_hashtab_insert_safe ( tmp - > peer_label_table , tmp ) ;
}
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( con - > root_table , e ) ;
ast_hashtab_insert_safe ( con - > root_table , tmp ) ;
2009-03-11 00:28:28 +00:00
con - > root = tmp ;
2007-11-21 01:09:47 +00:00
/* The pattern trie points to this exten; replace the pointer,
and all will be well */
2008-04-22 21:57:57 +00:00
if ( x ) { /* if the trie isn't formed yet; no problem */
if ( x - > exten ) { /* this test for safety purposes */
x - > exten = tmp ; /* replace what would become a bad pointer */
} else {
ast_log ( LOG_ERROR , " Trying to delete an exten from a context, but the pattern tree node returned isn't an extension \n " ) ;
}
2007-11-21 01:09:47 +00:00
}
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2006-05-09 08:31:42 +00:00
if ( tmp - > priority = = PRIORITY_HINT )
ast_change_hint ( e , tmp ) ;
/* Destroy the old one */
2007-01-06 00:28:16 +00:00
if ( e - > datad )
e - > datad ( e - > data ) ;
2007-06-06 21:20:11 +00:00
ast_free ( e ) ;
2006-05-09 08:31:42 +00:00
} else { /* Slip ourselves in just before e */
tmp - > peer = e ;
tmp - > next = e - > next ; /* extension chain, or NULL if e is not the first extension */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
if ( ep ) { /* Easy enough, we're just in the peer list */
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( tmp - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( eh - > peer_label_table , tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( eh - > peer_table , tmp ) ;
2006-05-09 08:31:42 +00:00
ep - > peer = tmp ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else { /* we are the first in some peer list, so link in the ext list */
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
tmp - > peer_table = e - > peer_table ;
tmp - > peer_label_table = e - > peer_label_table ;
e - > peer_table = 0 ;
e - > peer_label_table = 0 ;
ast_hashtab_insert_safe ( tmp - > peer_table , tmp ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
if ( tmp - > label ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( tmp - > peer_label_table , tmp ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_remove_object_via_lookup ( con - > root_table , e ) ;
ast_hashtab_insert_safe ( con - > root_table , tmp ) ;
2006-05-09 08:31:42 +00:00
if ( el )
el - > next = tmp ; /* in the middle... */
else
con - > root = tmp ; /* ... or at the head */
e - > next = NULL ; /* e is no more at the head, so e->next must be reset */
}
/* And immediately return success. */
2009-02-18 15:35:26 +00:00
if ( tmp - > priority = = PRIORITY_HINT ) {
2011-07-08 01:26:01 +00:00
ast_add_hint ( tmp ) ;
2009-02-18 15:35:26 +00:00
}
2006-05-09 08:31:42 +00:00
}
return 0 ;
}
2006-05-08 15:32:53 +00:00
/*! \brief
* Main interface to add extensions to the list for out context .
*
* We sort extensions in order of matching preference , so that we can
* stop the search as soon as we find a suitable match .
* This ordering also takes care of wildcards such as ' . ' ( meaning
* " one or more of any character " ) and ' ! ' ( which is ' earlymatch ' ,
* meaning " zero or more of any character " but also impacts the
* return value from CANMATCH and EARLYMATCH .
2006-05-09 08:03:52 +00:00
*
2006-05-08 15:32:53 +00:00
* The extension match rules defined in the devmeeting 2006.05 .05 are
* quite simple : WE SELECT THE LONGEST MATCH .
* In detail , " longest " means the number of matched characters in
* the extension . In case of ties ( e . g . _XXX and 333 ) in the length
* of a pattern , we give priority to entries with the smallest cardinality
* ( e . g , [ 5 - 9 ] comes before [ 2 - 8 ] before the former has only 5 elements ,
* while the latter has 7 , etc .
* In case of same cardinality , the first element in the range counts .
* If we still have a tie , any final ' ! ' will make this as a possibly
* less specific pattern .
*
2001-09-28 21:20:52 +00:00
* EBUSY - can ' t lock
* EEXIST - extension with the same priority exist and no replace is set
*
*/
1999-12-04 20:45:45 +00:00
int ast_add_extension2 ( struct ast_context * con ,
2006-05-08 15:32:53 +00:00
int replace , const char * extension , int priority , const char * label , const char * callerid ,
const char * application , void * data , void ( * datad ) ( void * ) ,
2016-12-19 21:03:52 +00:00
const char * registrar , const char * registrar_file , int registrar_line )
2009-02-18 15:35:26 +00:00
{
2011-07-08 01:26:01 +00:00
return ast_add_extension2_lockopt ( con , replace , extension , priority , label , callerid ,
2016-12-19 21:03:52 +00:00
application , data , datad , registrar , registrar_file , registrar_line , 1 ) ;
2009-02-18 15:35:26 +00:00
}
2013-06-07 16:07:18 +00:00
int ast_add_extension2_nolock ( struct ast_context * con ,
int replace , const char * extension , int priority , const char * label , const char * callerid ,
const char * application , void * data , void ( * datad ) ( void * ) ,
2016-12-19 21:03:52 +00:00
const char * registrar , const char * registrar_file , int registrar_line )
2013-06-07 16:07:18 +00:00
{
return ast_add_extension2_lockopt ( con , replace , extension , priority , label , callerid ,
2016-12-19 21:03:52 +00:00
application , data , datad , registrar , registrar_file , registrar_line , 0 ) ;
2013-06-07 16:07:18 +00:00
}
2011-07-08 01:26:01 +00:00
/*!
* \ brief Same as ast_add_extension2 ( ) but controls the context locking .
*
* \ details
* Does all the work of ast_add_extension2 , but adds an arg to
* determine if context locking should be done .
2009-02-18 15:35:26 +00:00
*/
static int ast_add_extension2_lockopt ( struct ast_context * con ,
int replace , const char * extension , int priority , const char * label , const char * callerid ,
const char * application , void * data , void ( * datad ) ( void * ) ,
2016-12-19 21:03:52 +00:00
const char * registrar , const char * registrar_file , int registrar_line , int lock_context )
1999-12-04 20:45:45 +00:00
{
/*
2006-05-09 18:34:30 +00:00
* Sort extensions ( or patterns ) according to the rules indicated above .
* These are implemented by the function ext_cmp ( ) ) .
* All priorities for the same ext / pattern / cid are kept in a list ,
* using the ' peer ' field as a link field . .
1999-12-04 20:45:45 +00:00
*/
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
struct ast_exten * tmp , * tmp2 , * e , * el = NULL ;
1999-12-04 20:45:45 +00:00
int res ;
2004-10-03 04:19:59 +00:00
int length ;
char * p ;
This commits the performance mods that give the priority processing engine in the pbx, a 25-30% speed boost. The two updates used, are, first, to merge the ast_exists_extension() and the ast_spawn_extension() where they are called sequentially in a loop in the code, into a slightly upgraded version of ast_spawn_extension(), with a few extra args; and, second, I modified the substitute_variables_helper_full, so it zeroes out the byte after the evaluated string instead of demanding you pre-zero the buffer; I also went thru the code and removed the code that zeroed this buffer before every call to the substitute_variables_helper_full. The first fix provides about a 9% speedup, and the second the rest. These figures come from the 'PIPS' benchmark I describe in blogs, conf. reports, etc.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-01 22:26:51 +00:00
char expand_buf [ VAR_BUF_SIZE ] ;
2007-11-15 16:30:13 +00:00
struct ast_exten dummy_exten = { 0 } ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
char dummy_name [ 1024 ] ;
2016-07-28 19:10:04 +00:00
int exten_fluff ;
int callerid_fluff ;
2005-12-07 20:47:59 +00:00
(closes issue #13202)
Reported by: falves11
Tested by: murf
falves11 ==
The changes I introduce here seem to clear up the problem
for me. However, if they do not for you, please reopen this
bug, and we'll keep digging.
The root of this problem seems to be a subtle memory corruption
introduced when creating an extension with an empty extension
name. While valgrind cannot detect it outside of DEBUG_MALLOC
mode, when compiled with DEBUG_MALLOC, this is certain death.
The code in main/features.c is a puzzle to me. On the initial
module load, the code is attempting to add the parking extension
before the features.conf file has even been opened!
I just wrapped the offending call with an if() that will not
try to add the extension if the extension name is empty. THis
seems to solve the corruption, and let the "memory show allocations"
work as one would expect.
But, really, adding an extension with an empty name is a seriously
bad thing to allow, as it will mess up all the pattern matching
algorithms, etc. So, I added a statement to the add_extension2 code to return
a -1 if this is attempted.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@135265 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-08-02 04:51:29 +00:00
if ( ast_strlen_zero ( extension ) ) {
ast_log ( LOG_ERROR , " You have to be kidding-- add exten '' to context %s? Figure out a name and call me back. Action ignored. \n " ,
con - > name ) ;
return - 1 ;
}
2009-03-11 00:28:28 +00:00
2008-03-19 16:54:12 +00:00
/* If we are adding a hint evalulate in variables and global variables */
2012-11-12 20:18:47 +00:00
if ( priority = = PRIORITY_HINT & & strstr ( application , " ${ " ) & & extension [ 0 ] ! = ' _ ' ) {
2016-07-27 22:17:53 +00:00
int inhibited ;
2009-06-26 15:28:53 +00:00
struct ast_channel * c = ast_dummy_channel_alloc ( ) ;
2011-09-26 19:40:12 +00:00
if ( c ) {
2012-02-13 17:27:06 +00:00
ast_channel_exten_set ( c , extension ) ;
ast_channel_context_set ( c , con - > name ) ;
2011-09-26 19:40:12 +00:00
}
2016-07-27 22:17:53 +00:00
/*
* We can allow dangerous functions when adding a hint since
* altering dialplan is itself a privileged activity . Otherwise ,
* we could never execute dangerous functions .
*/
inhibited = ast_thread_inhibit_escalations_swap ( 0 ) ;
2009-05-13 00:13:43 +00:00
pbx_substitute_variables_helper ( c , application , expand_buf , sizeof ( expand_buf ) ) ;
2016-07-27 22:17:53 +00:00
if ( 0 < inhibited ) {
ast_thread_inhibit_escalations ( ) ;
}
2008-12-10 23:01:14 +00:00
application = expand_buf ;
2011-09-26 19:40:12 +00:00
if ( c ) {
ast_channel_unref ( c ) ;
}
2005-12-07 20:47:59 +00:00
}
2016-07-28 19:10:04 +00:00
exten_fluff = ext_fluff_count ( extension ) ;
callerid_fluff = callerid ? ext_fluff_count ( callerid ) : 0 ;
2004-10-03 04:19:59 +00:00
length = sizeof ( struct ast_exten ) ;
length + = strlen ( extension ) + 1 ;
2016-07-28 19:10:04 +00:00
if ( exten_fluff ) {
length + = strlen ( extension ) + 1 - exten_fluff ;
}
2004-10-03 04:19:59 +00:00
length + = strlen ( application ) + 1 ;
2016-07-28 19:10:04 +00:00
if ( label ) {
2004-10-03 04:19:59 +00:00
length + = strlen ( label ) + 1 ;
2016-07-28 19:10:04 +00:00
}
if ( callerid ) {
2004-10-03 04:19:59 +00:00
length + = strlen ( callerid ) + 1 ;
2016-07-28 19:10:04 +00:00
if ( callerid_fluff ) {
length + = strlen ( callerid ) + 1 - callerid_fluff ;
}
} else {
2006-04-21 12:12:42 +00:00
length + + ; /* just the '\0' */
2016-07-28 19:10:04 +00:00
}
2016-12-19 21:03:52 +00:00
if ( registrar_file ) {
length + = strlen ( registrar_file ) + 1 ;
}
2004-07-17 02:25:53 +00:00
1999-12-04 20:45:45 +00:00
/* Be optimistic: Build the extension structure first */
2006-03-29 19:54:41 +00:00
if ( ! ( tmp = ast_calloc ( 1 , length ) ) )
1999-12-04 20:45:45 +00:00
return - 1 ;
2006-05-09 07:49:17 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( ast_strlen_zero ( label ) ) /* let's turn empty labels to a null ptr */
label = 0 ;
2006-03-29 19:54:41 +00:00
/* use p as dst in assignments, as the fields are const char * */
p = tmp - > stuff ;
if ( label ) {
tmp - > label = p ;
strcpy ( p , label ) ;
p + = strlen ( label ) + 1 ;
}
2016-07-28 19:10:04 +00:00
tmp - > name = p ;
2017-03-14 21:16:23 +00:00
p + = ext_strncpy ( p , extension , strlen ( extension ) + 1 , 0 ) ;
2016-07-28 19:10:04 +00:00
if ( exten_fluff ) {
tmp - > exten = p ;
2017-03-14 21:16:23 +00:00
p + = ext_strncpy ( p , extension , strlen ( extension ) + 1 - exten_fluff , 1 ) ;
2016-07-28 19:10:04 +00:00
} else {
/* no fluff, we don't need a copy. */
tmp - > exten = tmp - > name ;
}
2006-03-29 19:54:41 +00:00
tmp - > priority = priority ;
2016-07-28 19:10:04 +00:00
tmp - > cidmatch_display = tmp - > cidmatch = p ; /* but use p for assignments below */
2010-01-12 19:58:00 +00:00
/* Blank callerid and NULL callerid are two SEPARATE things. Do NOT confuse the two!!! */
if ( callerid ) {
2017-03-14 21:16:23 +00:00
p + = ext_strncpy ( p , callerid , strlen ( callerid ) + 1 , 0 ) ;
2016-07-28 19:10:04 +00:00
if ( callerid_fluff ) {
tmp - > cidmatch = p ;
2017-03-14 21:16:23 +00:00
p + = ext_strncpy ( p , callerid , strlen ( callerid ) + 1 - callerid_fluff , 1 ) ;
2016-07-28 19:10:04 +00:00
}
2013-10-25 20:51:13 +00:00
tmp - > matchcid = AST_EXT_MATCHCID_ON ;
2006-03-29 19:54:41 +00:00
} else {
* p + + = ' \0 ' ;
2013-10-25 20:51:13 +00:00
tmp - > matchcid = AST_EXT_MATCHCID_OFF ;
2006-03-29 19:54:41 +00:00
}
2016-12-19 21:03:52 +00:00
if ( registrar_file ) {
tmp - > registrar_file = p ;
strcpy ( p , registrar_file ) ;
p + = strlen ( registrar_file ) + 1 ;
} else {
tmp - > registrar_file = NULL ;
}
2006-03-29 19:54:41 +00:00
tmp - > app = p ;
strcpy ( p , application ) ;
tmp - > parent = con ;
tmp - > data = data ;
tmp - > datad = datad ;
tmp - > registrar = registrar ;
2016-12-19 21:03:52 +00:00
tmp - > registrar_line = registrar_line ;
2006-05-09 08:03:52 +00:00
2011-07-08 01:26:01 +00:00
if ( lock_context ) {
2009-02-18 15:35:26 +00:00
ast_wrlock_context ( con ) ;
}
2009-03-11 00:28:28 +00:00
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
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 . */
2016-07-28 19:10:04 +00:00
ext_strncpy ( dummy_name , tmp - > exten , sizeof ( dummy_name ) , 1 ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
dummy_exten . exten = dummy_name ;
2013-10-25 20:51:13 +00:00
dummy_exten . matchcid = AST_EXT_MATCHCID_OFF ;
2007-11-15 16:30:13 +00:00
dummy_exten . cidmatch = 0 ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
tmp2 = ast_hashtab_lookup ( con - > root_table , & dummy_exten ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
if ( ! tmp2 ) {
/* hmmm, not in the trie; */
2007-11-19 22:55:38 +00:00
add_exten_to_pattern_tree ( con , tmp , 0 ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( con - > root_table , tmp ) ; /* for the sake of completeness */
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
}
2006-05-10 07:13:23 +00:00
res = 0 ; /* some compilers will think it is uninitialized otherwise */
2006-05-09 06:04:45 +00:00
for ( e = con - > root ; e ; el = e , e = e - > next ) { /* scan the extension list */
2008-11-21 23:14:11 +00:00
res = ext_cmp ( e - > exten , tmp - > exten ) ;
2006-05-09 06:04:45 +00:00
if ( res = = 0 ) { /* extension match, now look at cidmatch */
2013-10-25 20:51:13 +00:00
if ( e - > matchcid = = AST_EXT_MATCHCID_OFF & & tmp - > matchcid = = AST_EXT_MATCHCID_OFF )
2001-09-28 21:20:52 +00:00
res = 0 ;
2013-10-25 20:51:13 +00:00
else if ( tmp - > matchcid = = AST_EXT_MATCHCID_ON & & e - > matchcid = = AST_EXT_MATCHCID_OFF )
2001-09-28 21:20:52 +00:00
res = 1 ;
2013-10-25 20:51:13 +00:00
else if ( e - > matchcid = = AST_EXT_MATCHCID_ON & & tmp - > matchcid = = AST_EXT_MATCHCID_OFF )
2001-09-28 21:20:52 +00:00
res = - 1 ;
else
2009-09-16 18:06:42 +00:00
res = ext_cmp ( e - > cidmatch , tmp - > cidmatch ) ;
2001-09-28 21:20:52 +00:00
}
2006-05-09 08:31:42 +00:00
if ( res > = 0 )
break ;
}
2011-07-08 01:26:01 +00:00
if ( e & & res = = 0 ) { /* exact match, insert in the priority chain */
res = add_priority ( con , tmp , el , e , replace ) ;
2014-11-12 16:13:15 +00:00
if ( res < 0 ) {
if ( con - > pattern_tree ) {
struct match_char * x = add_exten_to_pattern_tree ( con , tmp , 1 ) ;
if ( x - > exten ) {
x - > deleted = 1 ;
x - > exten = 0 ;
}
ast_hashtab_remove_this_object ( con - > root_table , tmp ) ;
}
if ( tmp - > datad ) {
tmp - > datad ( tmp - > data ) ;
/* if you free this, null it out */
tmp - > data = NULL ;
}
ast_free ( tmp ) ;
}
2011-07-08 01:26:01 +00:00
if ( lock_context ) {
2009-02-18 15:35:26 +00:00
ast_unlock_context ( con ) ;
}
2006-05-10 22:14:56 +00:00
if ( res < 0 ) {
2014-07-03 17:20:00 +00:00
errno = EEXIST ;
return - 1 ;
2006-05-10 22:14:56 +00:00
}
} else {
/*
* not an exact match , this is the first entry with this pattern ,
* so insert in the main list right before ' e ' ( if any )
*/
tmp - > next = e ;
2016-07-22 03:34:46 +00:00
tmp - > peer_table = ast_hashtab_create ( 13 ,
hashtab_compare_exten_numbers ,
ast_hashtab_resize_java ,
ast_hashtab_newsize_java ,
hashtab_hash_priority ,
0 ) ;
tmp - > peer_label_table = ast_hashtab_create ( 7 ,
hashtab_compare_exten_labels ,
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
ast_hashtab_resize_java ,
ast_hashtab_newsize_java ,
2016-07-22 03:34:46 +00:00
hashtab_hash_labels ,
2007-11-15 16:30:13 +00:00
0 ) ;
2016-07-22 03:34:46 +00:00
if ( el ) { /* there is another exten already in this context */
el - > next = tmp ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
} else { /* this is the first exten in this context */
2016-07-22 03:34:46 +00:00
if ( ! con - > root_table ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
con - > root_table = ast_hashtab_create ( 27 ,
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
hashtab_compare_extens ,
ast_hashtab_resize_java ,
ast_hashtab_newsize_java ,
hashtab_hash_extens ,
2007-11-15 16:30:13 +00:00
0 ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
2016-07-22 03:34:46 +00:00
con - > root = tmp ;
}
if ( label ) {
ast_hashtab_insert_safe ( tmp - > peer_label_table , tmp ) ;
This is the perhaps the biggest, boldest, most daring change I've ever committed to trunk. Forgive me in advance any disruption this may cause, and please, report any problems via the bugtracker. The upside is that this can speed up large dialplans by 20 times (or more). Context, extension, and priority matching are all fairly constant-time searches. I introduce here my hashtables (hashtabs), and a regression for them. I would have used the ast_obj2 tables, but mine are resizeable, and don't need the object destruction capability. The hashtab stuff is well tested and stable. I introduce a data structure, a trie, for extension pattern matching, in which knowledge of all patterns is accumulated, and all matches can be found via a single traversal of the tree. This is per-context. The trie is formed on the first lookup attempt, and stored in the context for future lookups. Destruction routines are in place for hashtabs and the pattern match trie. You can see the contents of the pattern match trie by using the 'dialplan show' cli command when 'core set debug' has been done to put it in debug mode. The pattern tree traversal only traverses those parts of the tree that are interesting. It uses a scoreboard sort of approach to find the best match. The speed of the traversal is more a function of the length of the pattern than the number of patterns in the tree. The tree also contains the CID matching patterns. See the source code comments for details on how everything works. I believe the approach general enough that any issues that might come up involving fine points in the pattern matching algorithm, can be solved by just tweaking things. We shall see. The current pattern matcher is fairly involved, and replicating every nuance of it is difficult. If you find and report problems, I will try to resolve than as quickly as I can. The trie and hashtabs are added to the existing context and exten structs, and none of the old machinery has been removed for the sake of the multitude of functions that use them. In the future, we can (maybe) weed out the linked lists and save some space.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-09 16:00:22 +00:00
}
2016-07-22 03:34:46 +00:00
ast_hashtab_insert_safe ( tmp - > peer_table , tmp ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_hashtab_insert_safe ( con - > root_table , tmp ) ;
2016-07-22 03:34:46 +00:00
2011-07-08 01:26:01 +00:00
if ( lock_context ) {
2009-02-18 15:35:26 +00:00
ast_unlock_context ( con ) ;
}
if ( tmp - > priority = = PRIORITY_HINT ) {
2011-07-08 01:26:01 +00:00
ast_add_hint ( tmp ) ;
2009-02-18 15:35:26 +00:00
}
2006-05-10 22:14:56 +00:00
}
if ( option_debug ) {
2013-10-25 20:51:13 +00:00
if ( tmp - > matchcid = = AST_EXT_MATCHCID_ON ) {
2010-08-12 18:04:19 +00:00
ast_debug ( 1 , " Added extension '%s' priority %d (CID match '%s') to %s (%p) \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , tmp - > cidmatch_display , con - > name , con ) ;
2006-05-10 22:14:56 +00:00
} else {
2010-08-12 18:04:19 +00:00
ast_debug ( 1 , " Added extension '%s' priority %d to %s (%p) \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , con - > name , con ) ;
2006-05-10 22:14:56 +00:00
}
2006-09-19 16:23:45 +00:00
}
2007-07-23 14:21:41 +00:00
2013-10-25 20:51:13 +00:00
if ( tmp - > matchcid = = AST_EXT_MATCHCID_ON ) {
2010-08-12 16:48:54 +00:00
ast_verb ( 3 , " Added extension '%s' priority %d (CID match '%s') to %s \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , tmp - > cidmatch_display , con - > name ) ;
2007-07-23 14:21:41 +00:00
} else {
2010-08-12 16:48:54 +00:00
ast_verb ( 3 , " Added extension '%s' priority %d to %s \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , tmp - > priority , con - > name ) ;
1999-12-04 20:45:45 +00:00
}
2009-03-11 00:28:28 +00:00
2006-05-09 08:03:52 +00:00
return 0 ;
1999-12-04 20:45:45 +00:00
}
2013-05-18 19:47:24 +00:00
/*! \brief Structure which contains information about an outgoing dial */
struct pbx_outgoing {
/*! \brief Dialing structure being used */
struct ast_dial * dial ;
/*! \brief Condition for synchronous dialing */
ast_cond_t cond ;
/*! \brief Application to execute */
char app [ AST_MAX_APP ] ;
/*! \brief Application data to pass to application */
char * appdata ;
/*! \brief Dialplan context */
2005-07-10 23:49:57 +00:00
char context [ AST_MAX_CONTEXT ] ;
2013-05-18 19:47:24 +00:00
/*! \brief Dialplan extension */
2002-09-11 17:09:48 +00:00
char exten [ AST_MAX_EXTENSION ] ;
2013-05-18 19:47:24 +00:00
/*! \brief Dialplan priority */
2002-09-11 17:09:48 +00:00
int priority ;
2013-08-09 17:28:15 +00:00
/*! \brief Result of the dial operation when dialed is set */
int dial_res ;
2013-05-18 19:47:24 +00:00
/*! \brief Set when dialing is completed */
unsigned int dialed : 1 ;
2017-04-19 20:08:39 +00:00
/*! \brief Set if we've spawned a thread to do our work */
unsigned int in_separate_thread : 1 ;
2002-09-11 17:09:48 +00:00
} ;
2013-05-18 19:47:24 +00:00
/*! \brief Destructor for outgoing structure */
static void pbx_outgoing_destroy ( void * obj )
2002-09-11 17:09:48 +00:00
{
2013-05-18 19:47:24 +00:00
struct pbx_outgoing * outgoing = obj ;
2006-05-09 08:03:52 +00:00
2013-05-18 19:47:24 +00:00
if ( outgoing - > dial ) {
ast_dial_destroy ( outgoing - > dial ) ;
2012-06-26 21:45:22 +00:00
}
2013-05-18 19:47:24 +00:00
ast_cond_destroy ( & outgoing - > cond ) ;
2012-11-07 19:15:26 +00:00
2013-05-18 19:47:24 +00:00
ast_free ( outgoing - > appdata ) ;
}
/*! \brief Internal function which dials an outgoing leg and sends it to a provided extension or application */
static void * pbx_outgoing_exec ( void * data )
{
RAII_VAR ( struct pbx_outgoing * , outgoing , data , ao2_cleanup ) ;
2013-05-18 22:49:14 +00:00
enum ast_dial_result res ;
2013-05-18 19:47:24 +00:00
2013-05-18 22:49:14 +00:00
res = ast_dial_run ( outgoing - > dial , NULL , 0 ) ;
2017-04-19 20:08:39 +00:00
if ( outgoing - > in_separate_thread ) {
/* Notify anyone interested that dialing is complete */
ao2_lock ( outgoing ) ;
outgoing - > dial_res = res ;
outgoing - > dialed = 1 ;
ast_cond_signal ( & outgoing - > cond ) ;
ao2_unlock ( outgoing ) ;
} else {
/* We still need the dial result, but we don't need to lock */
outgoing - > dial_res = res ;
}
2013-05-18 19:47:24 +00:00
/* If the outgoing leg was not answered we can immediately return and go no further */
if ( res ! = AST_DIAL_RESULT_ANSWERED ) {
return NULL ;
2002-09-11 17:09:48 +00:00
}
2013-05-18 19:47:24 +00:00
if ( ! ast_strlen_zero ( outgoing - > app ) ) {
struct ast_app * app = pbx_findapp ( outgoing - > app ) ;
if ( app ) {
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
ast_verb ( 4 , " Launching %s(%s) on %s \n " , outgoing - > app , S_OR ( outgoing - > appdata , " " ) ,
2013-05-18 19:47:24 +00:00
ast_channel_name ( ast_dial_answered ( outgoing - > dial ) ) ) ;
pbx_exec ( ast_dial_answered ( outgoing - > dial ) , app , outgoing - > appdata ) ;
} else {
ast_log ( LOG_WARNING , " No such application '%s' \n " , outgoing - > app ) ;
}
} else {
struct ast_channel * answered = ast_dial_answered ( outgoing - > dial ) ;
if ( ! ast_strlen_zero ( outgoing - > context ) ) {
ast_channel_context_set ( answered , outgoing - > context ) ;
}
if ( ! ast_strlen_zero ( outgoing - > exten ) ) {
ast_channel_exten_set ( answered , outgoing - > exten ) ;
}
if ( outgoing - > priority > 0 ) {
ast_channel_priority_set ( answered , outgoing - > priority ) ;
2012-08-08 22:39:40 +00:00
}
2013-05-18 19:47:24 +00:00
if ( ast_pbx_run ( answered ) ) {
ast_log ( LOG_ERROR , " Failed to start PBX on %s \n " , ast_channel_name ( answered ) ) ;
2002-09-11 17:09:48 +00:00
} else {
2013-05-18 19:47:24 +00:00
/* PBX will have taken care of hanging up, so we steal the answered channel so dial doesn't do it */
ast_dial_answered_steal ( outgoing - > dial ) ;
2002-09-11 17:09:48 +00:00
}
}
2013-05-18 19:47:24 +00:00
2002-09-11 17:09:48 +00:00
return NULL ;
}
2013-05-18 19:47:24 +00:00
/*! \brief Internal dialing state callback which causes early media to trigger an answer */
static void pbx_outgoing_state_callback ( struct ast_dial * dial )
2004-10-15 17:51:37 +00:00
{
2013-05-18 19:47:24 +00:00
struct ast_channel * channel ;
2006-05-09 08:03:52 +00:00
2013-05-18 19:47:24 +00:00
if ( ast_dial_state ( dial ) ! = AST_DIAL_RESULT_PROGRESS ) {
return ;
}
2004-10-15 17:51:37 +00:00
2013-05-18 19:47:24 +00:00
if ( ! ( channel = ast_dial_get_channel ( dial , 0 ) ) ) {
return ;
2004-10-15 17:51:37 +00:00
}
2006-05-09 08:03:52 +00:00
2013-05-18 19:47:24 +00:00
ast_verb ( 4 , " Treating progress as answer on '%s' due to early media option \n " ,
ast_channel_name ( channel ) ) ;
2006-05-09 08:03:52 +00:00
2013-05-18 19:47:24 +00:00
ast_queue_control ( channel , AST_CONTROL_ANSWER ) ;
2004-10-15 17:51:37 +00:00
}
2014-04-18 16:44:48 +00:00
/*!
* \ brief Attempt to convert disconnect cause to old originate reason .
*
* \ todo XXX The old originate reasons need to be trashed and replaced
* with normal disconnect cause codes if the call was not answered .
* The internal consumers of the reason values would also need to be
* updated : app_originate , call files , and AMI OriginateResponse .
*/
static enum ast_control_frame_type pbx_dial_reason ( enum ast_dial_result dial_result , int cause )
{
enum ast_control_frame_type pbx_reason ;
if ( dial_result = = AST_DIAL_RESULT_ANSWERED ) {
/* Remote end answered. */
pbx_reason = AST_CONTROL_ANSWER ;
} else if ( dial_result = = AST_DIAL_RESULT_HANGUP ) {
/* Caller hungup */
pbx_reason = AST_CONTROL_HANGUP ;
} else {
switch ( cause ) {
case AST_CAUSE_USER_BUSY :
pbx_reason = AST_CONTROL_BUSY ;
break ;
case AST_CAUSE_CALL_REJECTED :
case AST_CAUSE_NETWORK_OUT_OF_ORDER :
case AST_CAUSE_DESTINATION_OUT_OF_ORDER :
case AST_CAUSE_NORMAL_TEMPORARY_FAILURE :
case AST_CAUSE_SWITCH_CONGESTION :
case AST_CAUSE_NORMAL_CIRCUIT_CONGESTION :
pbx_reason = AST_CONTROL_CONGESTION ;
break ;
case AST_CAUSE_ANSWERED_ELSEWHERE :
case AST_CAUSE_NO_ANSWER :
/* Remote end was ringing (but isn't anymore) */
pbx_reason = AST_CONTROL_RINGING ;
break ;
case AST_CAUSE_UNALLOCATED :
default :
/* Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?) */
pbx_reason = 0 ;
break ;
}
}
return pbx_reason ;
}
static int pbx_outgoing_attempt ( const char * type , struct ast_format_cap * cap ,
const char * addr , int timeout , const char * context , const char * exten , int priority ,
const char * app , const char * appdata , int * reason , int synchronous ,
const char * cid_num , const char * cid_name , struct ast_variable * vars ,
const char * account , struct ast_channel * * locked_channel , int early_media ,
2016-11-21 21:43:47 +00:00
const struct ast_assigned_ids * assignedids , const char * predial_callee )
2002-09-11 17:09:48 +00:00
{
2014-04-18 16:44:48 +00:00
RAII_VAR ( struct pbx_outgoing * , outgoing , NULL , ao2_cleanup ) ;
2013-05-18 19:47:24 +00:00
struct ast_channel * dialed ;
pthread_t thread ;
2016-11-21 21:43:47 +00:00
char tmp_cid_name [ 128 ] ;
char tmp_cid_num [ 128 ] ;
2005-07-15 23:24:51 +00:00
2014-04-18 16:44:48 +00:00
outgoing = ao2_alloc ( sizeof ( * outgoing ) , pbx_outgoing_destroy ) ;
2013-05-18 19:47:24 +00:00
if ( ! outgoing ) {
return - 1 ;
}
2014-04-18 16:44:48 +00:00
ast_cond_init ( & outgoing - > cond , NULL ) ;
2012-05-17 16:28:20 +00:00
2013-05-18 19:47:24 +00:00
if ( ! ast_strlen_zero ( app ) ) {
ast_copy_string ( outgoing - > app , app , sizeof ( outgoing - > app ) ) ;
outgoing - > appdata = ast_strdup ( appdata ) ;
} else {
ast_copy_string ( outgoing - > context , context , sizeof ( outgoing - > context ) ) ;
ast_copy_string ( outgoing - > exten , exten , sizeof ( outgoing - > exten ) ) ;
outgoing - > priority = priority ;
}
2012-05-17 16:28:20 +00:00
2013-05-18 19:47:24 +00:00
if ( ! ( outgoing - > dial = ast_dial_create ( ) ) ) {
return - 1 ;
}
2004-10-15 17:51:37 +00:00
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
if ( ast_dial_append ( outgoing - > dial , type , addr , assignedids ) ) {
2013-05-18 19:47:24 +00:00
return - 1 ;
}
2006-05-09 08:03:52 +00:00
2013-05-18 19:47:24 +00:00
ast_dial_set_global_timeout ( outgoing - > dial , timeout ) ;
2004-06-23 20:46:58 +00:00
2016-11-21 21:43:47 +00:00
if ( ! ast_strlen_zero ( predial_callee ) ) {
/* note casting to void * here to suppress compiler warning message (passing const to non-const function) */
ast_dial_option_global_enable ( outgoing - > dial , AST_DIAL_OPTION_PREDIAL , ( void * ) predial_callee ) ;
}
2013-05-18 19:47:24 +00:00
if ( ast_dial_prerun ( outgoing - > dial , NULL , cap ) ) {
2014-04-18 16:44:48 +00:00
if ( synchronous & & reason ) {
* reason = pbx_dial_reason ( AST_DIAL_RESULT_FAILED ,
ast_dial_reason ( outgoing - > dial , 0 ) ) ;
}
2013-05-18 19:47:24 +00:00
return - 1 ;
}
2006-05-09 08:03:52 +00:00
2013-05-18 19:47:24 +00:00
dialed = ast_dial_get_channel ( outgoing - > dial , 0 ) ;
2013-06-17 03:00:38 +00:00
if ( ! dialed ) {
return - 1 ;
}
2012-05-17 16:28:20 +00:00
2013-12-18 20:33:37 +00:00
ast_channel_lock ( dialed ) ;
2013-10-02 16:23:34 +00:00
if ( vars ) {
ast_set_variables ( dialed , vars ) ;
}
accountcode: Slightly change accountcode propagation.
The previous behavior was to simply set the accountcode of an outgoing
channel to the accountcode of the channel initiating the call. It was
done this way a long time ago to allow the accountcode set on the SIP/100
channel to be propagated to a local channel so the dialplan execution on
the Local;2 channel would have the SIP/100 accountcode available.
SIP/100 -> Local;1/Local;2 -> SIP/200
Propagating the SIP/100 accountcode to the local channels is very useful.
Without any dialplan manipulation, all channels in this call would have
the same accountcode.
Using dialplan, you can set a different accountcode on the SIP/200 channel
either by setting the accountcode on the Local;2 channel or by the Dial
application's b(pre-dial), M(macro) or U(gosub) options, or by the
FollowMe application's b(pre-dial) option, or by the Queue application's
macro or gosub options. Before Asterisk v12, the altered accountcode on
SIP/200 will remain until the local channels optimize out and the
accountcode would change to the SIP/100 accountcode.
Asterisk v1.8 attempted to add peeraccount support but ultimately had to
punt on the support. The peeraccount support was rendered useless because
of how the CDR code needed to unconditionally force the caller's
accountcode onto the peer channel's accountcode. The CEL events were thus
intentionally made to always use the channel's accountcode as the
peeraccount value.
With the arrival of Asterisk v12, the situation has improved somewhat so
peeraccount support can be made to work. Using the indicated example, the
the accountcode values become as follows when the peeraccount is set on
SIP/100 before calling SIP/200:
SIP/100 ---> Local;1 ---- Local;2 ---> SIP/200
acct: 100 \/ acct: 200 \/ acct: 100 \/ acct: 200
peer: 200 /\ peer: 100 /\ peer: 200 /\ peer: 100
If a channel already has an accountcode it can only change by the
following explicit user actions:
1) A channel originate method that can specify an accountcode to use.
2) The calling channel propagating its non-empty peeraccount or its
non-empty accountcode if the peeraccount was empty to the outgoing
channel's accountcode before initiating the dial. e.g., Dial and
FollowMe. The exception to this propagation method is Queue. Queue will
only propagate peeraccounts this way only if the outgoing channel does not
have an accountcode.
3) Dialplan using CHANNEL(accountcode).
4) Dialplan using CHANNEL(peeraccount) on the other end of a local
channel pair.
If a channel does not have an accountcode it can get one from the
following places:
1) The channel driver's configuration at channel creation.
2) Explicit user action as already indicated.
3) Entering a basic or stasis-mixing bridge from a peer channel's
peeraccount value.
You can specify the accountcode for an outgoing channel by setting the
CHANNEL(peeraccount) before using the Dial, FollowMe, and Queue
applications. Queue adds the wrinkle that it will not overwrite an
existing accountcode on the outgoing channel with the calling channels
values.
Accountcode and peeraccount values propagate to an outgoing channel before
dialing. Accountcodes also propagate when channels enter or leave a basic
or stasis-mixing bridge. The peeraccount value only makes sense for
mixing bridges with two channels; it is meaningless otherwise.
* Made peeraccount functional by changing accountcode propagation as
described above.
* Fixed CEL extracting the wrong ie value for the peeraccount. This was
done intentionally in Asterisk v1.8 when that version had to punt on
peeraccount.
* Fixed a few places dealing with accountcodes that were reading from
channels without the lock held.
AFS-65 #close
Review: https://reviewboard.asterisk.org/r/3601/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419520 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-24 22:48:38 +00:00
if ( ! ast_strlen_zero ( account ) ) {
ast_channel_stage_snapshot ( dialed ) ;
2013-06-17 03:00:38 +00:00
ast_channel_accountcode_set ( dialed , account ) ;
accountcode: Slightly change accountcode propagation.
The previous behavior was to simply set the accountcode of an outgoing
channel to the accountcode of the channel initiating the call. It was
done this way a long time ago to allow the accountcode set on the SIP/100
channel to be propagated to a local channel so the dialplan execution on
the Local;2 channel would have the SIP/100 accountcode available.
SIP/100 -> Local;1/Local;2 -> SIP/200
Propagating the SIP/100 accountcode to the local channels is very useful.
Without any dialplan manipulation, all channels in this call would have
the same accountcode.
Using dialplan, you can set a different accountcode on the SIP/200 channel
either by setting the accountcode on the Local;2 channel or by the Dial
application's b(pre-dial), M(macro) or U(gosub) options, or by the
FollowMe application's b(pre-dial) option, or by the Queue application's
macro or gosub options. Before Asterisk v12, the altered accountcode on
SIP/200 will remain until the local channels optimize out and the
accountcode would change to the SIP/100 accountcode.
Asterisk v1.8 attempted to add peeraccount support but ultimately had to
punt on the support. The peeraccount support was rendered useless because
of how the CDR code needed to unconditionally force the caller's
accountcode onto the peer channel's accountcode. The CEL events were thus
intentionally made to always use the channel's accountcode as the
peeraccount value.
With the arrival of Asterisk v12, the situation has improved somewhat so
peeraccount support can be made to work. Using the indicated example, the
the accountcode values become as follows when the peeraccount is set on
SIP/100 before calling SIP/200:
SIP/100 ---> Local;1 ---- Local;2 ---> SIP/200
acct: 100 \/ acct: 200 \/ acct: 100 \/ acct: 200
peer: 200 /\ peer: 100 /\ peer: 200 /\ peer: 100
If a channel already has an accountcode it can only change by the
following explicit user actions:
1) A channel originate method that can specify an accountcode to use.
2) The calling channel propagating its non-empty peeraccount or its
non-empty accountcode if the peeraccount was empty to the outgoing
channel's accountcode before initiating the dial. e.g., Dial and
FollowMe. The exception to this propagation method is Queue. Queue will
only propagate peeraccounts this way only if the outgoing channel does not
have an accountcode.
3) Dialplan using CHANNEL(accountcode).
4) Dialplan using CHANNEL(peeraccount) on the other end of a local
channel pair.
If a channel does not have an accountcode it can get one from the
following places:
1) The channel driver's configuration at channel creation.
2) Explicit user action as already indicated.
3) Entering a basic or stasis-mixing bridge from a peer channel's
peeraccount value.
You can specify the accountcode for an outgoing channel by setting the
CHANNEL(peeraccount) before using the Dial, FollowMe, and Queue
applications. Queue adds the wrinkle that it will not overwrite an
existing accountcode on the outgoing channel with the calling channels
values.
Accountcode and peeraccount values propagate to an outgoing channel before
dialing. Accountcodes also propagate when channels enter or leave a basic
or stasis-mixing bridge. The peeraccount value only makes sense for
mixing bridges with two channels; it is meaningless otherwise.
* Made peeraccount functional by changing accountcode propagation as
described above.
* Fixed CEL extracting the wrong ie value for the peeraccount. This was
done intentionally in Asterisk v1.8 when that version had to punt on
peeraccount.
* Fixed a few places dealing with accountcodes that were reading from
channels without the lock held.
AFS-65 #close
Review: https://reviewboard.asterisk.org/r/3601/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419520 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-24 22:48:38 +00:00
ast_channel_peeraccount_set ( dialed , account ) ;
ast_channel_stage_snapshot_done ( dialed ) ;
2002-09-11 17:09:48 +00:00
}
2013-06-17 03:00:38 +00:00
ast_set_flag ( ast_channel_flags ( dialed ) , AST_FLAG_ORIGINATED ) ;
2016-11-21 21:43:47 +00:00
if ( ! ast_strlen_zero ( predial_callee ) ) {
char * tmp = NULL ;
/*
* The predial sub routine may have set callerid so set this into the new channel
* Note . . . cid_num and cid_name parameters to this function will always be NULL if
* predial_callee is non - NULL so we are not overwriting anything here .
*/
tmp = S_COR ( ast_channel_caller ( dialed ) - > id . number . valid , ast_channel_caller ( dialed ) - > id . number . str , NULL ) ;
if ( tmp ) {
ast_copy_string ( tmp_cid_num , tmp , sizeof ( tmp_cid_num ) ) ;
cid_num = tmp_cid_num ;
}
tmp = S_COR ( ast_channel_caller ( dialed ) - > id . name . valid , ast_channel_caller ( dialed ) - > id . name . str , NULL ) ;
if ( tmp ) {
ast_copy_string ( tmp_cid_name , tmp , sizeof ( tmp_cid_name ) ) ;
cid_name = tmp_cid_name ;
}
}
2013-12-18 20:33:37 +00:00
ast_channel_unlock ( dialed ) ;
2012-05-17 16:28:20 +00:00
2013-10-02 20:31:02 +00:00
if ( ! ast_strlen_zero ( cid_num ) | | ! ast_strlen_zero ( cid_name ) ) {
2013-05-18 19:47:24 +00:00
struct ast_party_connected_line connected ;
2002-09-11 17:09:48 +00:00
2013-10-02 20:31:02 +00:00
/*
* It seems strange to set the CallerID on an outgoing call leg
* to whom we are calling , but this function ' s callers are doing
* various Originate methods . This call leg goes to the local
* user . Once the called party answers , the dialplan needs to
* be able to access the CallerID from the CALLERID function as
* if the called party had placed this call .
*/
2013-05-18 19:47:24 +00:00
ast_set_callerid ( dialed , cid_num , cid_name , cid_num ) ;
2003-02-02 19:04:14 +00:00
2013-10-02 20:31:02 +00:00
ast_party_connected_line_set_init ( & connected , ast_channel_connected ( dialed ) ) ;
if ( ! ast_strlen_zero ( cid_num ) ) {
connected . id . number . valid = 1 ;
connected . id . number . str = ( char * ) cid_num ;
connected . id . number . presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED ;
}
if ( ! ast_strlen_zero ( cid_name ) ) {
connected . id . name . valid = 1 ;
connected . id . name . str = ( char * ) cid_name ;
connected . id . name . presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED ;
}
2013-05-18 19:47:24 +00:00
ast_channel_set_connected_line ( dialed , & connected , NULL ) ;
}
2006-02-11 18:31:59 +00:00
2013-05-18 19:47:24 +00:00
if ( early_media ) {
2013-10-02 20:31:02 +00:00
ast_dial_set_state_callback ( outgoing - > dial , pbx_outgoing_state_callback ) ;
2013-05-18 19:47:24 +00:00
}
2012-05-17 16:28:20 +00:00
2014-04-18 16:44:48 +00:00
if ( locked_channel ) {
/*
* Keep a dialed channel ref since the caller wants
* the channel returned . We must get the ref before
* spawning off pbx_outgoing_exec ( ) .
*/
ast_channel_ref ( dialed ) ;
if ( ! synchronous ) {
/*
* Lock it now to hold off pbx_outgoing_exec ( ) in case the
* calling function needs the channel state / snapshot before
* dialing actually happens .
*/
ast_channel_lock ( dialed ) ;
}
2013-05-18 19:47:24 +00:00
}
2005-07-15 23:24:51 +00:00
2017-04-19 20:08:39 +00:00
/* This extra reference is dereferenced by pbx_outgoing_exec */
2013-05-18 19:47:24 +00:00
ao2_ref ( outgoing , + 1 ) ;
2017-04-19 20:08:39 +00:00
if ( synchronous = = AST_OUTGOING_WAIT_COMPLETE ) {
/*
* Because we are waiting until this is complete anyway , there is no
* sense in creating another thread that we will just need to wait
* for , so instead we commandeer the current thread .
*/
pbx_outgoing_exec ( outgoing ) ;
} else {
outgoing - > in_separate_thread = 1 ;
if ( ast_pthread_create_detached ( & thread , NULL , pbx_outgoing_exec , outgoing ) ) {
ast_log ( LOG_WARNING , " Unable to spawn dialing thread for '%s/%s' \n " , type , addr ) ;
ao2_ref ( outgoing , - 1 ) ;
if ( locked_channel ) {
if ( ! synchronous ) {
ast_channel_unlock ( dialed ) ;
}
ast_channel_unref ( dialed ) ;
2014-04-18 16:44:48 +00:00
}
2017-04-19 20:08:39 +00:00
return - 1 ;
2014-04-18 16:44:48 +00:00
}
2013-05-18 19:47:24 +00:00
2017-04-19 20:08:39 +00:00
if ( synchronous ) {
ao2_lock ( outgoing ) ;
/* Wait for dialing to complete */
while ( ! outgoing - > dialed ) {
2014-04-18 16:44:48 +00:00
ast_cond_wait ( & outgoing - > cond , ao2_object_get_lockaddr ( outgoing ) ) ;
}
2017-04-19 20:08:39 +00:00
ao2_unlock ( outgoing ) ;
2014-04-18 16:44:48 +00:00
}
2017-04-19 20:08:39 +00:00
}
2013-08-09 17:28:15 +00:00
2017-04-19 20:08:39 +00:00
if ( synchronous ) {
2014-04-18 16:44:48 +00:00
/* Determine the outcome of the dialing attempt up to it being answered. */
if ( reason ) {
* reason = pbx_dial_reason ( outgoing - > dial_res ,
ast_dial_reason ( outgoing - > dial , 0 ) ) ;
}
if ( outgoing - > dial_res ! = AST_DIAL_RESULT_ANSWERED ) {
/* The dial operation failed. */
if ( locked_channel ) {
ast_channel_unref ( dialed ) ;
2013-08-09 17:28:15 +00:00
}
2014-04-18 16:44:48 +00:00
return - 1 ;
2013-05-18 19:47:24 +00:00
}
2014-04-18 16:44:48 +00:00
if ( locked_channel ) {
ast_channel_lock ( dialed ) ;
2013-05-18 22:49:14 +00:00
}
2013-05-18 19:47:24 +00:00
}
2012-05-17 16:28:20 +00:00
2014-04-18 16:44:48 +00:00
if ( locked_channel ) {
* locked_channel = dialed ;
2013-05-18 19:47:24 +00:00
}
2014-04-18 16:44:48 +00:00
return 0 ;
}
2006-05-09 08:03:52 +00:00
2014-04-18 16:44:48 +00:00
int ast_pbx_outgoing_exten ( const char * type , struct ast_format_cap * cap , const char * addr ,
int timeout , const char * context , const char * exten , int priority , int * reason ,
int synchronous , const char * cid_num , const char * cid_name , struct ast_variable * vars ,
const char * account , struct ast_channel * * locked_channel , int early_media ,
const struct ast_assigned_ids * assignedids )
2016-11-21 21:43:47 +00:00
{
return ast_pbx_outgoing_exten_predial ( type , cap , addr , timeout , context , exten , priority , reason ,
synchronous , cid_num , cid_name , vars , account , locked_channel , early_media , assignedids , NULL ) ;
}
int ast_pbx_outgoing_exten_predial ( const char * type , struct ast_format_cap * cap , const char * addr ,
int timeout , const char * context , const char * exten , int priority , int * reason ,
int synchronous , const char * cid_num , const char * cid_name , struct ast_variable * vars ,
const char * account , struct ast_channel * * locked_channel , int early_media ,
const struct ast_assigned_ids * assignedids , const char * predial_callee )
2014-04-18 16:44:48 +00:00
{
int res ;
int my_reason ;
2013-05-19 00:49:15 +00:00
2014-04-18 16:44:48 +00:00
if ( ! reason ) {
reason = & my_reason ;
}
* reason = 0 ;
if ( locked_channel ) {
* locked_channel = NULL ;
2013-05-18 19:47:24 +00:00
}
2014-04-18 16:44:48 +00:00
res = pbx_outgoing_attempt ( type , cap , addr , timeout , context , exten , priority ,
NULL , NULL , reason , synchronous , cid_num , cid_name , vars , account , locked_channel ,
2016-11-21 21:43:47 +00:00
early_media , assignedids , predial_callee ) ;
2013-05-18 19:47:24 +00:00
2014-04-18 16:44:48 +00:00
if ( res < 0 /* Call failed to get connected for some reason. */
2017-02-09 16:01:22 +00:00
& & 0 < synchronous
2014-04-18 16:44:48 +00:00
& & ast_exists_extension ( NULL , context , " failed " , 1 , NULL ) ) {
struct ast_channel * failed ;
2013-05-18 19:47:24 +00:00
2014-04-18 16:44:48 +00:00
/* We do not have to worry about a locked_channel if dialing failed. */
ast_assert ( ! locked_channel | | ! * locked_channel ) ;
2004-10-15 17:51:37 +00:00
2014-04-18 16:44:48 +00:00
/*!
* \ todo XXX Not good . The channel name is not unique if more than
* one originate fails at a time .
*/
failed = ast_channel_alloc ( 0 , AST_STATE_DOWN , cid_num , cid_name , account ,
" failed " , context , NULL , NULL , 0 , " OutgoingSpoolFailed " ) ;
if ( failed ) {
char failed_reason [ 12 ] ;
2012-05-17 16:28:20 +00:00
2013-05-18 19:47:24 +00:00
ast_set_variables ( failed , vars ) ;
2014-04-18 16:44:48 +00:00
snprintf ( failed_reason , sizeof ( failed_reason ) , " %d " , * reason ) ;
2013-05-18 19:47:24 +00:00
pbx_builtin_setvar_helper ( failed , " REASON " , failed_reason ) ;
2013-12-18 19:28:05 +00:00
ast_channel_unlock ( failed ) ;
2013-05-18 19:47:24 +00:00
if ( ast_pbx_run ( failed ) ) {
2014-04-18 16:44:48 +00:00
ast_log ( LOG_ERROR , " Unable to run PBX on '%s' \n " ,
ast_channel_name ( failed ) ) ;
2013-05-18 19:47:24 +00:00
ast_hangup ( failed ) ;
2012-05-17 16:28:20 +00:00
}
}
2013-05-18 19:47:24 +00:00
}
2012-05-17 16:28:20 +00:00
2014-04-18 16:44:48 +00:00
return res ;
2013-05-18 19:47:24 +00:00
}
2014-04-18 16:44:48 +00:00
int ast_pbx_outgoing_app ( const char * type , struct ast_format_cap * cap , const char * addr ,
int timeout , const char * app , const char * appdata , int * reason , int synchronous ,
const char * cid_num , const char * cid_name , struct ast_variable * vars ,
const char * account , struct ast_channel * * locked_channel ,
const struct ast_assigned_ids * assignedids )
2016-11-21 21:43:47 +00:00
{
return ast_pbx_outgoing_app_predial ( type , cap , addr , timeout , app , appdata , reason , synchronous ,
cid_num , cid_name , vars , account , locked_channel , assignedids , NULL ) ;
}
int ast_pbx_outgoing_app_predial ( const char * type , struct ast_format_cap * cap , const char * addr ,
int timeout , const char * app , const char * appdata , int * reason , int synchronous ,
const char * cid_num , const char * cid_name , struct ast_variable * vars ,
const char * account , struct ast_channel * * locked_channel ,
const struct ast_assigned_ids * assignedids , const char * predial_callee )
2013-05-18 19:47:24 +00:00
{
2014-04-18 16:44:48 +00:00
if ( reason ) {
* reason = 0 ;
}
if ( locked_channel ) {
* locked_channel = NULL ;
}
2013-05-18 19:47:24 +00:00
if ( ast_strlen_zero ( app ) ) {
return - 1 ;
2003-02-02 19:04:14 +00:00
}
2012-05-17 16:28:20 +00:00
2014-04-18 16:44:48 +00:00
return pbx_outgoing_attempt ( type , cap , addr , timeout , NULL , NULL , 0 , app , appdata ,
reason , synchronous , cid_num , cid_name , vars , account , locked_channel , 0 ,
2016-11-21 21:43:47 +00:00
assignedids , predial_callee ) ;
2003-02-02 19:04:14 +00:00
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
/* this is the guts of destroying a context --
freeing up the structure , traversing and destroying the
extensions , switches , ignorepats , includes , etc . etc . */
static void __ast_internal_context_destroy ( struct ast_context * con )
1999-12-04 20:45:45 +00:00
{
2003-04-06 18:19:51 +00:00
struct ast_exten * e , * el , * en ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
struct ast_context * tmp = con ;
2009-03-11 00:28:28 +00:00
2016-07-14 18:51:42 +00:00
/* Free includes */
AST_VECTOR_CALLBACK_VOID ( & tmp - > includes , include_free ) ;
AST_VECTOR_FREE ( & tmp - > includes ) ;
2016-07-15 07:59:48 +00:00
/* Free ignorepats */
AST_VECTOR_CALLBACK_VOID ( & tmp - > ignorepats , ignorepat_free ) ;
AST_VECTOR_FREE ( & tmp - > ignorepats ) ;
2016-07-16 00:28:16 +00:00
/* Free switches */
AST_VECTOR_CALLBACK_VOID ( & tmp - > alts , sw_free ) ;
AST_VECTOR_FREE ( & tmp - > alts ) ;
2008-07-11 22:03:19 +00:00
if ( tmp - > registrar )
ast_free ( tmp - > registrar ) ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
/* destroy the hash tabs */
if ( tmp - > root_table ) {
ast_hashtab_destroy ( tmp - > root_table , 0 ) ;
}
/* and destroy the pattern tree */
if ( tmp - > pattern_tree )
destroy_pattern_tree ( tmp - > pattern_tree ) ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
for ( e = tmp - > root ; e ; ) {
for ( en = e - > peer ; en ; ) {
el = en ;
en = en - > peer ;
destroy_exten ( el ) ;
}
el = e ;
e = e - > next ;
destroy_exten ( el ) ;
}
tmp - > root = NULL ;
ast_rwlock_destroy ( & tmp - > lock ) ;
2013-05-13 19:29:56 +00:00
ast_mutex_destroy ( & tmp - > macrolock ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_free ( tmp ) ;
}
void __ast_context_destroy ( struct ast_context * list , struct ast_hashtab * contexttab , struct ast_context * con , const char * registrar )
{
struct ast_context * tmp , * tmpl = NULL ;
struct ast_exten * exten_item , * prio_item ;
for ( tmp = list ; tmp ; ) {
struct ast_context * next = NULL ; /* next starting point */
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
/* The following code used to skip forward to the next
context with matching registrar , but this didn ' t
2009-03-11 00:28:28 +00:00
make sense ; individual priorities registrar ' d to
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
the matching registrar could occur in any context ! */
ast_debug ( 1 , " Investigate ctx %s %s \n " , tmp - > name , tmp - > registrar ) ;
if ( con ) {
for ( ; tmp ; tmpl = tmp , tmp = tmp - > next ) { /* skip to the matching context */
ast_debug ( 1 , " check ctx %s %s \n " , tmp - > name , tmp - > registrar ) ;
if ( ! strcasecmp ( tmp - > name , con - > name ) ) {
break ; /* found it */
}
2008-06-17 18:23:01 +00:00
}
2006-05-08 22:06:50 +00:00
}
2009-03-11 00:28:28 +00:00
2006-05-08 22:06:50 +00:00
if ( ! tmp ) /* not found, we are done */
break ;
2007-02-28 20:46:01 +00:00
ast_wrlock_context ( tmp ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( registrar ) {
/* then search thru and remove any extens that match registrar. */
struct ast_hashtab_iter * exten_iter ;
struct ast_hashtab_iter * prio_iter ;
2016-07-14 18:51:42 +00:00
int idx ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
/* remove any ignorepats whose registrar matches */
2016-07-15 07:59:48 +00:00
for ( idx = ast_context_ignorepats_count ( tmp ) - 1 ; idx > = 0 ; idx - - ) {
struct ast_ignorepat * ip = AST_VECTOR_GET ( & tmp - > ignorepats , idx ) ;
if ( ! strcmp ( ast_get_ignorepat_registrar ( ip ) , registrar ) ) {
AST_VECTOR_REMOVE_ORDERED ( & tmp - > ignorepats , idx ) ;
ignorepat_free ( ip ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
}
/* remove any includes whose registrar matches */
2016-07-14 18:51:42 +00:00
for ( idx = ast_context_includes_count ( tmp ) - 1 ; idx > = 0 ; idx - - ) {
struct ast_include * i = AST_VECTOR_GET ( & tmp - > includes , idx ) ;
if ( ! strcmp ( ast_get_include_registrar ( i ) , registrar ) ) {
AST_VECTOR_REMOVE_ORDERED ( & tmp - > includes , idx ) ;
include_free ( i ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
}
/* remove any switches whose registrar matches */
2016-07-16 00:28:16 +00:00
for ( idx = ast_context_switches_count ( tmp ) - 1 ; idx > = 0 ; idx - - ) {
struct ast_sw * sw = AST_VECTOR_GET ( & tmp - > alts , idx ) ;
if ( ! strcmp ( ast_get_switch_registrar ( sw ) , registrar ) ) {
AST_VECTOR_REMOVE_ORDERED ( & tmp - > alts , idx ) ;
sw_free ( sw ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
}
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
if ( tmp - > root_table ) { /* it is entirely possible that the context is EMPTY */
exten_iter = ast_hashtab_start_traversal ( tmp - > root_table ) ;
while ( ( exten_item = ast_hashtab_next ( exten_iter ) ) ) {
Fix potential invalid reads that could occur in pbx.c
Here is a cut and paste of my review request for this change:
This past weekend, Russell ran our current suite of unit tests for Asterisk
under valgrind. The PBX pattern match test caused valgrind to spew forth two
invalid read errors. This patch contains two changes that shut valgrind up and
do not cause any new memory leaks.
Change 1: In ast_context_remove_extension_callerid2, valgrind reported an
invalid read in the for loop close to the function's end. Specifically, one of
the the strcmp calls in the loop control was reading invalid memory. This was
because the caller of ast_context_remove_extension_callerid2 (__ast_context
destroy in this case) passed as a parameter a shallow copy of an ast_exten's
exten field. This same ast_exten was what was destroyed inside the for loop,
thus any iterations of the for loop beyond the destruction of the ast_exten
would result in invalid reads. My fix for this is to make a copy of the
ast_exten's exten field and pass the copy to
ast_context_remove_extension_callerid2. In addition, I have also acted
similarly with the ast_exten's matchcid field. Since in this case a NULL is
handled quite differently than an empty string, I needed to be a bit more
careful with its handling.
Change 2: In __ast_context_destroy, we iterated over a hashtab and called
ast_context_remove_extension_callerid2 on each item. Specifically, the hashtab
over which we were iterating was an ast_exten's peer_table. Inside of
ast_context_remove_extension_callerid2, we could possibly destroy this
ast_exten, which also caused the hashtab to be freed. Attempting to call
ast_hashtab_end_traversal on the hashtab iterator caused an invalid read to
occur when trying to read the iterator->tab->do_locking field since
iterator->tab had already been freed. My handling of this problem is a bit less
straightforward. With each iteration over the hashtab's contents, we set a
variable called "end_traversal" based on the return of
ast_context_remove_extension_callerid2. If 0 is ever returned, then we know
that the extension was found and destroyed. Because of this, we cannot call
ast_hashtab_end_traversal because we will be guaranteeing a read of invalid
memory. In such a case, we forego calling ast_hashtab_end_traversal and instead
call ast_free on the hashtab iterator.
Review: https://reviewboard.asterisk.org/r/585
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254362 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-24 21:10:38 +00:00
int end_traversal = 1 ;
2015-04-19 20:49:43 +00:00
/*
* If the extension could not be removed from the root_table due to
* a loaded PBX app , it can exist here but have its peer_table be
* destroyed due to a previous pass through this function .
*/
if ( ! exten_item - > peer_table ) {
continue ;
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
prio_iter = ast_hashtab_start_traversal ( exten_item - > peer_table ) ;
while ( ( prio_item = ast_hashtab_next ( prio_iter ) ) ) {
Fix potential invalid reads that could occur in pbx.c
Here is a cut and paste of my review request for this change:
This past weekend, Russell ran our current suite of unit tests for Asterisk
under valgrind. The PBX pattern match test caused valgrind to spew forth two
invalid read errors. This patch contains two changes that shut valgrind up and
do not cause any new memory leaks.
Change 1: In ast_context_remove_extension_callerid2, valgrind reported an
invalid read in the for loop close to the function's end. Specifically, one of
the the strcmp calls in the loop control was reading invalid memory. This was
because the caller of ast_context_remove_extension_callerid2 (__ast_context
destroy in this case) passed as a parameter a shallow copy of an ast_exten's
exten field. This same ast_exten was what was destroyed inside the for loop,
thus any iterations of the for loop beyond the destruction of the ast_exten
would result in invalid reads. My fix for this is to make a copy of the
ast_exten's exten field and pass the copy to
ast_context_remove_extension_callerid2. In addition, I have also acted
similarly with the ast_exten's matchcid field. Since in this case a NULL is
handled quite differently than an empty string, I needed to be a bit more
careful with its handling.
Change 2: In __ast_context_destroy, we iterated over a hashtab and called
ast_context_remove_extension_callerid2 on each item. Specifically, the hashtab
over which we were iterating was an ast_exten's peer_table. Inside of
ast_context_remove_extension_callerid2, we could possibly destroy this
ast_exten, which also caused the hashtab to be freed. Attempting to call
ast_hashtab_end_traversal on the hashtab iterator caused an invalid read to
occur when trying to read the iterator->tab->do_locking field since
iterator->tab had already been freed. My handling of this problem is a bit less
straightforward. With each iteration over the hashtab's contents, we set a
variable called "end_traversal" based on the return of
ast_context_remove_extension_callerid2. If 0 is ever returned, then we know
that the extension was found and destroyed. Because of this, we cannot call
ast_hashtab_end_traversal because we will be guaranteeing a read of invalid
memory. In such a case, we forego calling ast_hashtab_end_traversal and instead
call ast_free on the hashtab iterator.
Review: https://reviewboard.asterisk.org/r/585
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254362 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-24 21:10:38 +00:00
char extension [ AST_MAX_EXTENSION ] ;
char cidmatch [ AST_MAX_EXTENSION ] ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
if ( ! prio_item - > registrar | | strcmp ( prio_item - > registrar , registrar ) ! = 0 ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
continue ;
}
ast_verb ( 3 , " Remove %s/%s/%d, registrar=%s; con=%s(%p); con->root=%p \n " ,
2016-07-28 19:10:04 +00:00
tmp - > name , prio_item - > name , prio_item - > priority , registrar , con ? con - > name : " <nil> " , con , con ? con - > root_table : NULL ) ;
Fix potential invalid reads that could occur in pbx.c
Here is a cut and paste of my review request for this change:
This past weekend, Russell ran our current suite of unit tests for Asterisk
under valgrind. The PBX pattern match test caused valgrind to spew forth two
invalid read errors. This patch contains two changes that shut valgrind up and
do not cause any new memory leaks.
Change 1: In ast_context_remove_extension_callerid2, valgrind reported an
invalid read in the for loop close to the function's end. Specifically, one of
the the strcmp calls in the loop control was reading invalid memory. This was
because the caller of ast_context_remove_extension_callerid2 (__ast_context
destroy in this case) passed as a parameter a shallow copy of an ast_exten's
exten field. This same ast_exten was what was destroyed inside the for loop,
thus any iterations of the for loop beyond the destruction of the ast_exten
would result in invalid reads. My fix for this is to make a copy of the
ast_exten's exten field and pass the copy to
ast_context_remove_extension_callerid2. In addition, I have also acted
similarly with the ast_exten's matchcid field. Since in this case a NULL is
handled quite differently than an empty string, I needed to be a bit more
careful with its handling.
Change 2: In __ast_context_destroy, we iterated over a hashtab and called
ast_context_remove_extension_callerid2 on each item. Specifically, the hashtab
over which we were iterating was an ast_exten's peer_table. Inside of
ast_context_remove_extension_callerid2, we could possibly destroy this
ast_exten, which also caused the hashtab to be freed. Attempting to call
ast_hashtab_end_traversal on the hashtab iterator caused an invalid read to
occur when trying to read the iterator->tab->do_locking field since
iterator->tab had already been freed. My handling of this problem is a bit less
straightforward. With each iteration over the hashtab's contents, we set a
variable called "end_traversal" based on the return of
ast_context_remove_extension_callerid2. If 0 is ever returned, then we know
that the extension was found and destroyed. Because of this, we cannot call
ast_hashtab_end_traversal because we will be guaranteeing a read of invalid
memory. In such a case, we forego calling ast_hashtab_end_traversal and instead
call ast_free on the hashtab iterator.
Review: https://reviewboard.asterisk.org/r/585
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254362 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-24 21:10:38 +00:00
ast_copy_string ( extension , prio_item - > exten , sizeof ( extension ) ) ;
if ( prio_item - > cidmatch ) {
ast_copy_string ( cidmatch , prio_item - > cidmatch , sizeof ( cidmatch ) ) ;
}
2013-10-25 20:51:13 +00:00
end_traversal & = ast_context_remove_extension_callerid2 ( tmp , extension , prio_item - > priority , cidmatch , prio_item - > matchcid , NULL , 1 ) ;
Fix potential invalid reads that could occur in pbx.c
Here is a cut and paste of my review request for this change:
This past weekend, Russell ran our current suite of unit tests for Asterisk
under valgrind. The PBX pattern match test caused valgrind to spew forth two
invalid read errors. This patch contains two changes that shut valgrind up and
do not cause any new memory leaks.
Change 1: In ast_context_remove_extension_callerid2, valgrind reported an
invalid read in the for loop close to the function's end. Specifically, one of
the the strcmp calls in the loop control was reading invalid memory. This was
because the caller of ast_context_remove_extension_callerid2 (__ast_context
destroy in this case) passed as a parameter a shallow copy of an ast_exten's
exten field. This same ast_exten was what was destroyed inside the for loop,
thus any iterations of the for loop beyond the destruction of the ast_exten
would result in invalid reads. My fix for this is to make a copy of the
ast_exten's exten field and pass the copy to
ast_context_remove_extension_callerid2. In addition, I have also acted
similarly with the ast_exten's matchcid field. Since in this case a NULL is
handled quite differently than an empty string, I needed to be a bit more
careful with its handling.
Change 2: In __ast_context_destroy, we iterated over a hashtab and called
ast_context_remove_extension_callerid2 on each item. Specifically, the hashtab
over which we were iterating was an ast_exten's peer_table. Inside of
ast_context_remove_extension_callerid2, we could possibly destroy this
ast_exten, which also caused the hashtab to be freed. Attempting to call
ast_hashtab_end_traversal on the hashtab iterator caused an invalid read to
occur when trying to read the iterator->tab->do_locking field since
iterator->tab had already been freed. My handling of this problem is a bit less
straightforward. With each iteration over the hashtab's contents, we set a
variable called "end_traversal" based on the return of
ast_context_remove_extension_callerid2. If 0 is ever returned, then we know
that the extension was found and destroyed. Because of this, we cannot call
ast_hashtab_end_traversal because we will be guaranteeing a read of invalid
memory. In such a case, we forego calling ast_hashtab_end_traversal and instead
call ast_free on the hashtab iterator.
Review: https://reviewboard.asterisk.org/r/585
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@254362 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-24 21:10:38 +00:00
}
/* Explanation:
* ast_context_remove_extension_callerid2 will destroy the extension that it comes across . This
* destruction includes destroying the exten ' s peer_table , which we are currently traversing . If
* ast_context_remove_extension_callerid2 ever should return ' 0 ' then this means we have destroyed
* the hashtable which we are traversing , and thus calling ast_hashtab_end_traversal will result
* in reading invalid memory . Thus , if we detect that we destroyed the hashtable , then we will simply
* free the iterator
*/
if ( end_traversal ) {
ast_hashtab_end_traversal ( prio_iter ) ;
} else {
ast_free ( prio_iter ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
}
}
ast_hashtab_end_traversal ( exten_iter ) ;
2003-04-06 18:19:51 +00:00
}
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
/* delete the context if it's registrar matches, is empty, has refcount of 1, */
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
/* it's not empty, if it has includes, ignorepats, or switches that are registered from
another registrar . It ' s not empty if there are any extensions */
2016-07-16 00:28:16 +00:00
if ( strcmp ( tmp - > registrar , registrar ) = = 0 & & tmp - > refcount < 2 & & ! tmp - > root & & ! ast_context_ignorepats_count ( tmp ) & & ! ast_context_includes_count ( tmp ) & & ! ast_context_switches_count ( tmp ) ) {
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
ast_debug ( 1 , " delete ctx %s %s \n " , tmp - > name , tmp - > registrar ) ;
ast_hashtab_remove_this_object ( contexttab , tmp ) ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
next = tmp - > next ;
if ( tmpl )
tmpl - > next = next ;
else
contexts = next ;
/* Okay, now we're safe to let it go -- in a sense, we were
ready to let it go as soon as we locked it . */
ast_unlock_context ( tmp ) ;
__ast_internal_context_destroy ( tmp ) ;
2008-05-14 21:11:49 +00:00
} else {
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
ast_debug ( 1 , " Couldn't delete ctx %s/%s; refc=%d; tmp.root=%p \n " , tmp - > name , tmp - > registrar ,
tmp - > refcount , tmp - > root ) ;
2008-05-14 21:11:49 +00:00
ast_unlock_context ( tmp ) ;
(closes issue #13041)
Reported by: eliel
Tested by: murf
(closes issue #12960)
Reported by: mnicholson
In this 'omnibus' fix, I **think** I solved both
the problem in 13041, where unloading pbx_ael.so
caused crashes, or incomplete removal of previous
registrar'ed entries. And I added code to completely
remove all includes, switches, and ignorepats that
had a matching registrar entry, which should
appease 12960.
I also added a lot of seemingly useless brackets
around single statement if's, which helped debug
so much that I'm leaving them there.
I added a routine to check the correlation between
the extension tree lists and the hashtab
tables. It can be amazingly helpful when you have
lots of dialplan stuff, and need to narrow
down where a problem is occurring. It's ifdef'd
out by default.
I cleaned up the code around the new CIDmatch code.
It was leaving hanging extens with bad ptrs, getting confused
over which objects to remove, etc. I tightened
up the code and changed the call to remove_exten
in the merge_and_delete code.
I added more conditions to check for empty context
worthy of deletion. It's not empty if there are
any includes, switches, or ignorepats present.
If I've missed anything, please re-open this bug,
and be prepared to supply example dialplan code.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@130145 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-11 18:24:31 +00:00
next = tmp - > next ;
tmpl = tmp ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
}
} else if ( con ) {
ast_verb ( 3 , " Deleting context %s registrar=%s \n " , tmp - > name , tmp - > registrar ) ;
ast_debug ( 1 , " delete ctx %s %s \n " , tmp - > name , tmp - > registrar ) ;
ast_hashtab_remove_this_object ( contexttab , tmp ) ;
2009-03-11 00:28:28 +00:00
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
next = tmp - > next ;
if ( tmpl )
tmpl - > next = next ;
else
contexts = next ;
/* Okay, now we're safe to let it go -- in a sense, we were
ready to let it go as soon as we locked it . */
ast_unlock_context ( tmp ) ;
__ast_internal_context_destroy ( tmp ) ;
1999-12-04 20:45:45 +00:00
}
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
2006-05-08 22:06:50 +00:00
/* if we have a specific match, we are done, otherwise continue */
tmp = con ? NULL : next ;
1999-12-04 20:45:45 +00:00
}
2003-07-14 15:35:21 +00:00
}
2015-06-08 15:09:57 +00:00
int ast_context_destroy_by_name ( const char * context , const char * registrar )
{
struct ast_context * con ;
int ret = - 1 ;
ast_wrlock_contexts ( ) ;
con = ast_context_find ( context ) ;
if ( con ) {
ast_context_destroy ( con , registrar ) ;
ret = 0 ;
}
ast_unlock_contexts ( ) ;
return ret ;
}
2004-10-03 04:19:59 +00:00
void ast_context_destroy ( struct ast_context * con , const char * registrar )
2003-07-14 15:35:21 +00:00
{
2007-03-02 18:05:29 +00:00
ast_wrlock_contexts ( ) ;
(closes issue #6002)
Reported by: rizzo
Tested by: murf
Proposal of the changes to be made, and then an announcement of how they were accomplished:
http://lists.digium.com/pipermail/asterisk-dev/2008-February/032065.html
and:
http://lists.digium.com/pipermail/asterisk-dev/2008-March/032124.html
Here is a recap, file by file, of what I have done:
pbx/pbx_config.c
pbx/pbx_ael.c
All funcs that were passed a ptr to the context list, now will ALSO be passed a hashtab ptr to the same set.
Why? because (for the time being), the dialplan is stored in both, to facilitate a quick, low-cost move to
hash-tables to speed up dialplan processing. If it was deemed necessary to pass the context LIST, well, it
is just as necessary to have the TABLE available. This is because the list/table in question might not be
the global one, but temporary ones we would use to stage the dialplan on, and then swap into the global
position when things are ready.
We now have one external function for apps to use, "ast_context_find_or_create()" instead of the pre-existing
"find" and "create", as all existing usages used both in tandem anyway.
pbx_config, and pbx_ael, will stage the reloaded dialplan into local lists and tables, and
then call merge_contexts_and_delete, which will merge (now) existing contexts and
priorities from other registrars into this local set by copying them. Then, merge_contexts_and_delete will
lock down the contexts, swap the lists and tables, and unlock (real quick), and then
destroy the old dialplan.
chan_sip.c
chan_iax.c
chan_skinny.c
All the channel drivers that would add regcontexts now use the ast_context_find_or_create now.
chan_sip also includes a small fix to get rid of warnings about removing priorities that never got entered.
apps/app_meetme.c
apps/app_dial.c
apps/app_queue.c
All the apps that added a context/exten/priority were also modified to use ast_context_find_or_create instead.
include/asterisk/pbx.h
ast_context_create() is removed. Find_or_create_ is the new method.
ast_context_find_or_create() interface gets the hashtab added.
ast_merge_contexts_and_delete() gets the local hashtab arg added.
ast_wrlock_contexts_version() is added so you can detect if someone else got a writelock between your readlocking and writelocking.
ast_hashtab_compare_contexts was made public for use in pbx_config/pbx_ael
ast_hashtab_hash_contexts was in like fashion make public.
include/asterisk/pval.h
ast_compile_ael2() interface changed to include the local hashtab table ptr.
main/features.c
For the sake of the parking context, we use ast_context_find_or_create().
main/pbx.c
I changed all the "tree" names to "table" instead. That's because the original
implementation was based on binary trees. (had a free library). Then I moved
to hashtabs. Now, the names move forward too.
refcount field added to contexts, so you can keep track of how many modules
wanted this context to exist.
Some log messages that are warnings were inflated from LOG_NOTICE to LOG_WARNING.
Added some calls to ast_verb(3,...) for debug messages
Lots of little mods to ast_context_remove_extension2, which is now excersized in ways
it was not previously; one definite bug fixed.
find_or_create was upgraded to handle both local lists/tables as well as the globals.
context_merge() was added to do the per-context merging of the old/present contexts/extens/prios into the new/proposed local list/tables
ast_merge_contexts_and_delete() was heavily modified.
ast_add_extension2() was also upgraded to handle changes.
the context_destroy() code was re-engineered to handle the new way of doing things,
by exten/prio instead of by context.
res/ael/pval.c
res/ael/ael.tab.c
res/ael/ael.tab.h
res/ael/ael.y
res/ael/ael_lex.c
res/ael/ael.flex
utils/ael_main.c
utils/extconf.c
utils/conf2ael.c
utils/Makefile
Had to change the interface to ast_compile_ael2(), to include the hashtab ptr.
This ended up involving several external apps. The main gotcha was I had to
include lock.h and hashtab.h in several places.
As a side note, I tested this stuff pretty thoroughly, I replicated the problems
originally reported by Luigi, and made triply sure that reloads worked, and everything
worked thru "stop gracefully". I found a and fixed a few bugs as I was merging into
trunk, that did not appear in my tests of bug6002.
How's this for verbose commit messages?
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@106757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-03-07 18:57:57 +00:00
__ast_context_destroy ( contexts , contexts_table , con , registrar ) ;
2007-03-02 18:05:29 +00:00
ast_unlock_contexts ( ) ;
1999-12-04 20:45:45 +00:00
}
2015-12-29 01:18:01 +00:00
void wait_for_hangup ( struct ast_channel * chan , const void * data )
2001-04-27 15:07:56 +00:00
{
int res ;
struct ast_frame * f ;
2006-10-05 01:40:06 +00:00
double waitsec ;
2004-07-09 08:32:09 +00:00
int waittime ;
2006-05-09 08:03:52 +00:00
2009-08-10 19:20:57 +00:00
if ( ast_strlen_zero ( data ) | | ( sscanf ( data , " %30lg " , & waitsec ) ! = 1 ) | | ( waitsec < 0 ) )
2006-10-05 01:40:06 +00:00
waitsec = - 1 ;
if ( waitsec > - 1 ) {
waittime = waitsec * 1000.0 ;
ast_safe_sleep ( chan , waittime ) ;
2004-07-09 08:32:09 +00:00
} else do {
2001-04-27 15:07:56 +00:00
res = ast_waitfor ( chan , - 1 ) ;
if ( res < 0 )
return ;
f = ast_read ( chan ) ;
if ( f )
ast_frfree ( f ) ;
} while ( f ) ;
}
2008-07-09 15:57:06 +00:00
/*!
2015-12-29 01:18:01 +00:00
* \ ingroup functions
2008-07-09 15:57:06 +00:00
*/
2015-12-29 01:18:01 +00:00
static int testtime_write ( struct ast_channel * chan , const char * cmd , char * var , const char * value )
2008-07-09 15:57:06 +00:00
{
2015-12-29 01:18:01 +00:00
struct ast_tm tm ;
struct timeval tv ;
char * remainder , result [ 30 ] , timezone [ 80 ] ;
/* Turn off testing? */
if ( ! pbx_checkcondition ( value ) ) {
pbx_builtin_setvar_helper ( chan , " TESTTIME " , NULL ) ;
return 0 ;
}
/* Parse specified time */
if ( ! ( remainder = ast_strptime ( value , " %Y/%m/%d %H:%M:%S " , & tm ) ) ) {
return - 1 ;
}
sscanf ( remainder , " %79s " , timezone ) ;
tv = ast_mktime ( & tm , S_OR ( timezone , NULL ) ) ;
snprintf ( result , sizeof ( result ) , " %ld " , ( long ) tv . tv_sec ) ;
pbx_builtin_setvar_helper ( chan , " __TESTTIME " , result ) ;
2010-01-13 21:27:34 +00:00
return 0 ;
}
static struct ast_custom_function testtime_function = {
. name = " TESTTIME " ,
. write = testtime_write ,
} ;
2006-05-09 08:03:52 +00:00
int pbx_checkcondition ( const char * condition )
2004-05-09 07:19:00 +00:00
{
2008-05-25 14:31:29 +00:00
int res ;
if ( ast_strlen_zero ( condition ) ) { /* NULL or empty strings are false */
2005-10-18 16:51:28 +00:00
return 0 ;
2009-08-10 19:20:57 +00:00
} else if ( sscanf ( condition , " %30d " , & res ) = = 1 ) { /* Numbers are evaluated for truth */
2008-05-25 14:31:29 +00:00
return res ;
} else { /* Strings are true */
2006-04-18 13:37:07 +00:00
return 1 ;
2008-05-25 14:31:29 +00:00
}
2002-09-11 17:09:48 +00:00
}
Multiple revisions 399887,400138,400178,400180-400181
........
r399887 | dlee | 2013-09-26 10:41:47 -0500 (Thu, 26 Sep 2013) | 1 line
Minor performance bump by not allocate manager variable struct if we don't need it
........
r400138 | dlee | 2013-09-30 10:24:00 -0500 (Mon, 30 Sep 2013) | 23 lines
Stasis performance improvements
This patch addresses several performance problems that were found in
the initial performance testing of Asterisk 12.
The Stasis dispatch object was allocated as an AO2 object, even though
it has a very confined lifecycle. This was replaced with a straight
ast_malloc().
The Stasis message router was spending an inordinate amount of time
searching hash tables. In this case, most of our routers had 6 or
fewer routes in them to begin with. This was replaced with an array
that's searched linearly for the route.
We more heavily rely on AO2 objects in Asterisk 12, and the memset()
in ao2_ref() actually became noticeable on the profile. This was
#ifdef'ed to only run when AO2_DEBUG was enabled.
After being misled by an erroneous comment in taskprocessor.c during
profiling, the wrong comment was removed.
Review: https://reviewboard.asterisk.org/r/2873/
........
r400178 | dlee | 2013-09-30 13:26:27 -0500 (Mon, 30 Sep 2013) | 24 lines
Taskprocessor optimization; switch Stasis to use taskprocessors
This patch optimizes taskprocessor to use a semaphore for signaling,
which the OS can do a better job at managing contention and waiting
that we can with a mutex and condition.
The taskprocessor execution was also slightly optimized to reduce the
number of locks taken.
The only observable difference in the taskprocessor implementation is
that when the final reference to the taskprocessor goes away, it will
execute all tasks to completion instead of discarding the unexecuted
tasks.
For systems where unnamed semaphores are not supported, a really
simple semaphore implementation is provided. (Which gives identical
performance as the original taskprocessor implementation).
The way we ended up implementing Stasis caused the threadpool to be a
burden instead of a boost to performance. This was switched to just
use taskprocessors directly for subscriptions.
Review: https://reviewboard.asterisk.org/r/2881/
........
r400180 | dlee | 2013-09-30 13:39:34 -0500 (Mon, 30 Sep 2013) | 28 lines
Optimize how Stasis forwards are dispatched
This patch optimizes how forwards are dispatched in Stasis.
Originally, forwards were dispatched as subscriptions that are invoked
on the publishing thread. This did not account for the vast number of
forwards we would end up having in the system, and the amount of work it
would take to walk though the forward subscriptions.
This patch modifies Stasis so that rather than walking the tree of
forwards on every dispatch, when forwards and subscriptions are changed,
the subscriber list for every topic in the tree is changed.
This has a couple of benefits. First, this reduces the workload of
dispatching messages. It also reduces contention when dispatching to
different topics that happen to forward to the same aggregation topic
(as happens with all of the channel, bridge and endpoint topics).
Since forwards are no longer subscriptions, the bulk of this patch is
simply changing stasis_subscription objects to stasis_forward objects
(which, admittedly, I should have done in the first place.)
Since this required me to yet again put in a growing array, I finally
abstracted that out into a set of ast_vector macros in
asterisk/vector.h.
Review: https://reviewboard.asterisk.org/r/2883/
........
r400181 | dlee | 2013-09-30 13:48:57 -0500 (Mon, 30 Sep 2013) | 28 lines
Remove dispatch object allocation from Stasis publishing
While looking for areas for performance improvement, I realized that an
unused feature in Stasis was negatively impacting performance.
When a message is sent to a subscriber, a dispatch object is allocated
for the dispatch, containing the topic the message was published to, the
subscriber the message is being sent to, and the message itself.
The topic is actually unused by any subscriber in Asterisk today. And
the subscriber is associated with the taskprocessor the message is being
dispatched to.
First, this patch removes the unused topic parameter from Stasis
subscription callbacks.
Second, this patch introduces the concept of taskprocessor local data,
data that may be set on a taskprocessor and provided along with the data
pointer when a task is pushed using the ast_taskprocessor_push_local()
call. This allows the task to have both data specific to that
taskprocessor, in addition to data specific to that invocation.
With those two changes, the dispatch object can be removed completely,
and the message is simply refcounted and sent directly to the
taskprocessor.
Review: https://reviewboard.asterisk.org/r/2884/
........
Merged revisions 399887,400138,400178,400180-400181 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400186 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-09-30 18:55:27 +00:00
static void presence_state_cb ( void * unused , struct stasis_subscription * sub , struct stasis_message * msg )
2012-06-04 20:26:12 +00:00
{
2014-12-22 14:33:24 +00:00
struct ast_presence_state_message * presence_state ;
2013-04-16 15:48:16 +00:00
struct ast_str * hint_app = NULL ;
2014-12-22 14:33:24 +00:00
struct ast_hintdevice * device ;
struct ast_hintdevice * cmpdevice ;
struct ao2_iterator * dev_iter ;
2012-06-04 20:26:12 +00:00
2013-04-16 15:48:16 +00:00
if ( stasis_message_type ( msg ) ! = ast_presence_state_message_type ( ) ) {
2012-06-04 20:26:12 +00:00
return ;
}
2014-12-22 14:33:24 +00:00
presence_state = stasis_message_data ( msg ) ;
if ( ao2_container_count ( hintdevices ) = = 0 ) {
/* There are no hints monitoring devices. */
return ;
}
2013-04-16 15:48:16 +00:00
hint_app = ast_str_create ( 1024 ) ;
if ( ! hint_app ) {
2012-06-04 20:26:12 +00:00
return ;
}
2014-12-22 14:33:24 +00:00
cmpdevice = ast_alloca ( sizeof ( * cmpdevice ) + strlen ( presence_state - > provider ) ) ;
strcpy ( cmpdevice - > hintdevice , presence_state - > provider ) ;
2012-06-04 20:26:12 +00:00
2014-12-22 14:33:24 +00:00
ast_mutex_lock ( & context_merge_lock ) ; /* Hold off ast_merge_contexts_and_delete */
dev_iter = ao2_t_callback ( hintdevices ,
OBJ_POINTER | OBJ_MULTIPLE ,
hintdevice_cmp_multiple ,
cmpdevice ,
" find devices in container " ) ;
if ( ! dev_iter ) {
ast_mutex_unlock ( & context_merge_lock ) ;
ast_free ( hint_app ) ;
return ;
}
for ( ; ( device = ao2_iterator_next ( dev_iter ) ) ; ao2_t_ref ( device , - 1 , " Next device " ) ) {
2016-01-08 22:59:44 +00:00
if ( device - > hint ) {
presence_state_notify_callbacks ( device - > hint , & hint_app , presence_state ) ;
2013-04-16 15:48:16 +00:00
}
2012-06-04 20:26:12 +00:00
}
2014-12-22 14:33:24 +00:00
ao2_iterator_destroy ( dev_iter ) ;
2013-04-16 15:48:16 +00:00
ast_mutex_unlock ( & context_merge_lock ) ;
ast_free ( hint_app ) ;
2012-06-04 20:26:12 +00:00
}
2014-07-30 18:32:25 +00:00
static int action_extensionstatelist ( struct mansession * s , const struct message * m )
{
const char * action_id = astman_get_header ( m , " ActionID " ) ;
struct ast_hint * hint ;
struct ao2_iterator it_hints ;
2014-08-07 14:17:54 +00:00
int hint_count = 0 ;
2014-07-30 18:32:25 +00:00
if ( ! hints ) {
astman_send_error ( s , m , " No dialplan hints are available " ) ;
return 0 ;
}
2015-01-12 18:09:27 +00:00
astman_send_listack ( s , m , " Extension Statuses will follow " , " start " ) ;
2014-07-30 18:32:25 +00:00
ao2_lock ( hints ) ;
it_hints = ao2_iterator_init ( hints , 0 ) ;
for ( ; ( hint = ao2_iterator_next ( & it_hints ) ) ; ao2_ref ( hint , - 1 ) ) {
ao2_lock ( hint ) ;
2014-08-07 14:17:54 +00:00
/* Ignore pattern matching hints; they are stored in the
* hints container but aren ' t real from the perspective of
* an AMI user
*/
if ( hint - > exten - > exten [ 0 ] = = ' _ ' ) {
ao2_unlock ( hint ) ;
continue ;
}
+ + hint_count ;
2014-07-30 18:32:25 +00:00
astman_append ( s , " Event: ExtensionStatus \r \n " ) ;
if ( ! ast_strlen_zero ( action_id ) ) {
astman_append ( s , " ActionID: %s \r \n " , action_id ) ;
}
astman_append ( s ,
" Exten: %s \r \n "
" Context: %s \r \n "
" Hint: %s \r \n "
" Status: %d \r \n "
" StatusText: %s \r \n \r \n " ,
hint - > exten - > exten ,
hint - > exten - > parent - > name ,
hint - > exten - > app ,
hint - > laststate ,
ast_extension_state2str ( hint - > laststate ) ) ;
ao2_unlock ( hint ) ;
}
ao2_iterator_destroy ( & it_hints ) ;
ao2_unlock ( hints ) ;
2015-01-09 18:16:54 +00:00
astman_send_list_complete_start ( s , m , " ExtensionStateListComplete " , hint_count ) ;
astman_send_list_complete_end ( s ) ;
2014-07-30 18:32:25 +00:00
return 0 ;
}
2013-08-16 17:33:21 +00:00
/*!
* \ internal
* \ brief Clean up resources on Asterisk shutdown .
*
* \ note Cleans up resources allocated in load_pbx
*/
2012-10-02 01:47:16 +00:00
static void unload_pbx ( void )
{
2013-05-17 21:10:32 +00:00
presence_state_sub = stasis_unsubscribe_and_join ( presence_state_sub ) ;
device_state_sub = stasis_unsubscribe_and_join ( device_state_sub ) ;
2012-10-02 01:47:16 +00:00
ast_manager_unregister ( " ShowDialPlan " ) ;
2014-07-30 18:32:25 +00:00
ast_manager_unregister ( " ExtensionStateList " ) ;
2012-12-11 20:05:32 +00:00
ast_cli_unregister_multiple ( pbx_cli , ARRAY_LEN ( pbx_cli ) ) ;
2012-10-02 01:47:16 +00:00
ast_custom_function_unregister ( & exception_function ) ;
ast_custom_function_unregister ( & testtime_function ) ;
}
1999-12-04 20:45:45 +00:00
int load_pbx ( void )
{
2014-07-30 18:32:25 +00:00
int res = 0 ;
2004-07-17 02:25:53 +00:00
2015-03-26 22:24:26 +00:00
ast_register_cleanup ( unload_pbx ) ;
2012-12-11 20:05:32 +00:00
1999-12-04 20:45:45 +00:00
/* Initialize the PBX */
2007-07-23 14:21:41 +00:00
ast_verb ( 1 , " Asterisk PBX Core Initializing \n " ) ;
2008-05-03 04:12:54 +00:00
2015-12-29 01:18:01 +00:00
ast_verb ( 2 , " Registering builtin functions: \n " ) ;
2008-12-05 10:31:25 +00:00
ast_cli_register_multiple ( pbx_cli , ARRAY_LEN ( pbx_cli ) ) ;
2007-10-04 02:01:43 +00:00
__ast_custom_function_register ( & exception_function , NULL ) ;
2010-01-13 21:27:34 +00:00
__ast_custom_function_register ( & testtime_function , NULL ) ;
2004-07-17 02:25:53 +00:00
2006-10-30 21:18:39 +00:00
/* Register manager application */
2014-07-30 18:32:25 +00:00
res | = ast_manager_register_xml_core ( " ShowDialPlan " , EVENT_FLAG_CONFIG | EVENT_FLAG_REPORTING , manager_show_dialplan ) ;
res | = ast_manager_register_xml_core ( " ExtensionStateList " , EVENT_FLAG_CALL | EVENT_FLAG_REPORTING , action_extensionstatelist ) ;
if ( res ) {
return - 1 ;
}
Merge major changes to the way device state is passed around Asterisk. The two
places that cared about device states were app_queue and the hint code in pbx.c.
The changes include converting it to use the Asterisk event system, as well as
other efficiency improvements.
* app_queue: This module used to register a callback into devicestate.c to
monitor device state changes. Now, it is just a subscriber to Asterisk
events with the type, device state.
* pbx.c hints: Previously, the device state processing thread in devicestate.c
would call ast_hint_state_changed() each time the state of a device changed.
Then, that code would go looking for all the hints that monitor that device,
and call their callbacks. All of this blocked the device state processing
thread. Now, the hint code is a subscriber of Asterisk events with the
type, device state. Furthermore, when this code receives a device state
change event, it queues it up to be processed by another thread so that it
doesn't block one of the event processing threads.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@66958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-01 23:34:43 +00:00
2013-04-16 15:33:59 +00:00
if ( ! ( device_state_sub = stasis_subscribe ( ast_device_state_topic_all ( ) , device_state_cb , NULL ) ) ) {
2012-06-04 20:26:12 +00:00
return - 1 ;
}
2013-04-16 15:48:16 +00:00
if ( ! ( presence_state_sub = stasis_subscribe ( ast_presence_state_topic_all ( ) , presence_state_cb , NULL ) ) ) {
Merge major changes to the way device state is passed around Asterisk. The two
places that cared about device states were app_queue and the hint code in pbx.c.
The changes include converting it to use the Asterisk event system, as well as
other efficiency improvements.
* app_queue: This module used to register a callback into devicestate.c to
monitor device state changes. Now, it is just a subscriber to Asterisk
events with the type, device state.
* pbx.c hints: Previously, the device state processing thread in devicestate.c
would call ast_hint_state_changed() each time the state of a device changed.
Then, that code would go looking for all the hints that monitor that device,
and call their callbacks. All of this blocked the device state processing
thread. Now, the hint code is a subscriber of Asterisk events with the
type, device state. Furthermore, when this code receives a device state
change event, it queues it up to be processed by another thread so that it
doesn't block one of the event processing threads.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@66958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-01 23:34:43 +00:00
return - 1 ;
}
1999-12-04 20:45:45 +00:00
return 0 ;
}
2001-09-28 21:20:52 +00:00
/*
* Lock context list functions . . .
*/
2011-07-08 01:26:01 +00:00
int ast_wrlock_contexts ( void )
2007-02-28 20:46:01 +00:00
{
2010-08-05 07:47:30 +00:00
return ast_mutex_lock ( & conlock ) ;
2007-02-28 20:46:01 +00:00
}
2011-07-08 01:26:01 +00:00
int ast_rdlock_contexts ( void )
2001-09-28 21:20:52 +00:00
{
2010-08-05 07:47:30 +00:00
return ast_mutex_lock ( & conlock ) ;
2001-09-28 21:20:52 +00:00
}
2011-07-08 01:26:01 +00:00
int ast_unlock_contexts ( void )
2001-09-28 21:20:52 +00:00
{
2010-08-05 07:47:30 +00:00
return ast_mutex_unlock ( & conlock ) ;
2001-09-28 21:20:52 +00:00
}
/*
* Lock context . . .
*/
2007-02-28 20:46:01 +00:00
int ast_wrlock_context ( struct ast_context * con )
{
return ast_rwlock_wrlock ( & con - > lock ) ;
}
int ast_rdlock_context ( struct ast_context * con )
2001-09-28 21:20:52 +00:00
{
2007-02-28 20:46:01 +00:00
return ast_rwlock_rdlock ( & con - > lock ) ;
2001-09-28 21:20:52 +00:00
}
int ast_unlock_context ( struct ast_context * con )
{
2007-02-28 20:46:01 +00:00
return ast_rwlock_unlock ( & con - > lock ) ;
2001-09-28 21:20:52 +00:00
}
/*
* Name functions . . .
*/
2004-10-03 04:19:59 +00:00
const char * ast_get_context_name ( struct ast_context * con )
2001-09-28 21:20:52 +00:00
{
return con ? con - > name : NULL ;
}
2006-03-28 22:09:38 +00:00
struct ast_context * ast_get_extension_context ( struct ast_exten * exten )
{
return exten ? exten - > parent : NULL ;
}
2004-10-03 04:19:59 +00:00
const char * ast_get_extension_name ( struct ast_exten * exten )
2001-09-28 21:20:52 +00:00
{
2016-07-28 19:10:04 +00:00
return exten ? exten - > name : NULL ;
2001-09-28 21:20:52 +00:00
}
2004-10-03 04:19:59 +00:00
const char * ast_get_extension_label ( struct ast_exten * exten )
{
return exten ? exten - > label : NULL ;
}
2001-09-28 21:20:52 +00:00
int ast_get_extension_priority ( struct ast_exten * exten )
{
return exten ? exten - > priority : - 1 ;
}
/*
* Registrar info functions . . .
*/
2004-10-03 04:19:59 +00:00
const char * ast_get_context_registrar ( struct ast_context * c )
2001-09-28 21:20:52 +00:00
{
return c ? c - > registrar : NULL ;
}
2004-10-03 04:19:59 +00:00
const char * ast_get_extension_registrar ( struct ast_exten * e )
2001-09-28 21:20:52 +00:00
{
return e ? e - > registrar : NULL ;
}
2016-12-19 21:03:52 +00:00
const char * ast_get_extension_registrar_file ( struct ast_exten * e )
{
return e ? e - > registrar_file : NULL ;
}
int ast_get_extension_registrar_line ( struct ast_exten * e )
{
return e ? e - > registrar_line : 0 ;
}
2004-08-21 18:55:39 +00:00
int ast_get_extension_matchcid ( struct ast_exten * e )
{
return e ? e - > matchcid : 0 ;
}
2004-10-03 04:19:59 +00:00
const char * ast_get_extension_cidmatch ( struct ast_exten * e )
2004-08-21 18:55:39 +00:00
{
2016-07-28 19:10:04 +00:00
return e ? e - > cidmatch_display : NULL ;
2004-08-21 18:55:39 +00:00
}
2004-10-03 04:19:59 +00:00
const char * ast_get_extension_app ( struct ast_exten * e )
2001-09-28 21:20:52 +00:00
{
return e ? e - > app : NULL ;
}
void * ast_get_extension_app_data ( struct ast_exten * e )
{
return e ? e - > data : NULL ;
}
/*
* Walking functions . . .
*/
struct ast_context * ast_walk_contexts ( struct ast_context * con )
{
2005-12-26 21:38:50 +00:00
return con ? con - > next : contexts ;
2001-09-28 21:20:52 +00:00
}
struct ast_exten * ast_walk_context_extensions ( struct ast_context * con ,
struct ast_exten * exten )
{
if ( ! exten )
return con ? con - > root : NULL ;
else
return exten - > next ;
}
2016-07-16 00:28:16 +00:00
const struct ast_sw * ast_walk_context_switches ( const struct ast_context * con ,
const struct ast_sw * sw )
2001-09-28 21:20:52 +00:00
{
2016-07-16 00:28:16 +00:00
if ( sw ) {
int idx ;
int next = 0 ;
for ( idx = 0 ; idx < ast_context_switches_count ( con ) ; idx + + ) {
const struct ast_sw * s = ast_context_switches_get ( con , idx ) ;
if ( next ) {
return s ;
}
if ( sw = = s ) {
next = 1 ;
}
}
return NULL ;
}
if ( ! ast_context_switches_count ( con ) ) {
return NULL ;
}
return ast_context_switches_get ( con , 0 ) ;
}
int ast_context_switches_count ( const struct ast_context * con )
{
return AST_VECTOR_SIZE ( & con - > alts ) ;
}
const struct ast_sw * ast_context_switches_get ( const struct ast_context * con , int idx )
{
return AST_VECTOR_GET ( & con - > alts , idx ) ;
2001-09-28 21:20:52 +00:00
}
struct ast_exten * ast_walk_extension_priorities ( struct ast_exten * exten ,
struct ast_exten * priority )
{
2005-12-26 21:38:50 +00:00
return priority ? priority - > peer : exten ;
2001-09-28 21:20:52 +00:00
}
2016-07-14 18:51:42 +00:00
const struct ast_include * ast_walk_context_includes ( const struct ast_context * con ,
const struct ast_include * inc )
2001-09-28 21:20:52 +00:00
{
2016-07-14 18:51:42 +00:00
if ( inc ) {
int idx ;
int next = 0 ;
for ( idx = 0 ; idx < ast_context_includes_count ( con ) ; idx + + ) {
const struct ast_include * include = AST_VECTOR_GET ( & con - > includes , idx ) ;
if ( next ) {
return include ;
}
if ( inc = = include ) {
next = 1 ;
}
}
return NULL ;
}
if ( ! ast_context_includes_count ( con ) ) {
return NULL ;
}
return ast_context_includes_get ( con , 0 ) ;
}
int ast_context_includes_count ( const struct ast_context * con )
{
return AST_VECTOR_SIZE ( & con - > includes ) ;
}
const struct ast_include * ast_context_includes_get ( const struct ast_context * con , int idx )
{
return AST_VECTOR_GET ( & con - > includes , idx ) ;
2001-09-28 21:20:52 +00:00
}
2016-07-15 07:59:48 +00:00
const struct ast_ignorepat * ast_walk_context_ignorepats ( const struct ast_context * con ,
const struct ast_ignorepat * ip )
2001-09-28 21:20:52 +00:00
{
2016-07-15 07:59:48 +00:00
if ( ! con ) {
return NULL ;
}
if ( ip ) {
int idx ;
int next = 0 ;
for ( idx = 0 ; idx < ast_context_ignorepats_count ( con ) ; idx + + ) {
const struct ast_ignorepat * i = ast_context_ignorepats_get ( con , idx ) ;
if ( next ) {
return i ;
}
if ( ip = = i ) {
next = 1 ;
}
}
return NULL ;
}
if ( ! ast_context_ignorepats_count ( con ) ) {
return NULL ;
}
return ast_context_ignorepats_get ( con , 0 ) ;
}
int ast_context_ignorepats_count ( const struct ast_context * con )
{
return AST_VECTOR_SIZE ( & con - > ignorepats ) ;
}
const struct ast_ignorepat * ast_context_ignorepats_get ( const struct ast_context * con , int idx )
{
return AST_VECTOR_GET ( & con - > ignorepats , idx ) ;
2001-09-28 21:20:52 +00:00
}
2003-10-25 17:50:06 +00:00
int ast_context_verify_includes ( struct ast_context * con )
{
2016-07-14 18:51:42 +00:00
int idx ;
2003-10-25 17:50:06 +00:00
int res = 0 ;
2016-07-14 18:51:42 +00:00
for ( idx = 0 ; idx < ast_context_includes_count ( con ) ; idx + + ) {
const struct ast_include * inc = ast_context_includes_get ( con , idx ) ;
if ( ast_context_find ( include_rname ( inc ) ) ) {
2008-03-04 04:28:48 +00:00
continue ;
2016-07-14 18:51:42 +00:00
}
2008-03-04 04:28:48 +00:00
res = - 1 ;
ast_log ( LOG_WARNING , " Context '%s' tries to include nonexistent context '%s' \n " ,
2016-07-14 18:51:42 +00:00
ast_get_context_name ( con ) , include_rname ( inc ) ) ;
2008-03-04 04:28:48 +00:00
break ;
}
2003-10-25 17:50:06 +00:00
return res ;
}
2004-10-24 02:53:24 +00:00
2004-11-22 22:11:10 +00:00
2006-05-09 08:03:52 +00:00
static int __ast_goto_if_exists ( struct ast_channel * chan , const char * context , const char * exten , int priority , int async )
2004-11-22 22:11:10 +00:00
{
2005-04-29 15:04:26 +00:00
int ( * goto_func ) ( struct ast_channel * chan , const char * context , const char * exten , int priority ) ;
2004-12-08 18:24:04 +00:00
2005-04-29 15:04:26 +00:00
if ( ! chan )
return - 2 ;
2004-12-08 18:24:04 +00:00
2006-04-19 09:31:41 +00:00
if ( context = = NULL )
2012-02-13 17:27:06 +00:00
context = ast_channel_context ( chan ) ;
2006-04-19 09:31:41 +00:00
if ( exten = = NULL )
2012-02-13 17:27:06 +00:00
exten = ast_channel_exten ( chan ) ;
2006-04-19 09:31:41 +00:00
2005-04-29 15:04:26 +00:00
goto_func = ( async ) ? ast_async_goto : ast_explicit_goto ;
2010-07-14 15:48:36 +00:00
if ( ast_exists_extension ( chan , context , exten , priority ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( chan ) - > id . number . valid , ast_channel_caller ( chan ) - > id . number . str , NULL ) ) )
2006-04-19 09:31:41 +00:00
return goto_func ( chan , context , exten , priority ) ;
2009-04-09 19:10:02 +00:00
else {
return AST_PBX_GOTO_FAILED ;
}
2004-11-22 22:11:10 +00:00
}
2006-04-06 16:44:31 +00:00
int ast_goto_if_exists ( struct ast_channel * chan , const char * context , const char * exten , int priority )
{
2004-11-23 20:25:02 +00:00
return __ast_goto_if_exists ( chan , context , exten , priority , 0 ) ;
}
2006-04-06 16:44:31 +00:00
int ast_async_goto_if_exists ( struct ast_channel * chan , const char * context , const char * exten , int priority )
{
2004-11-23 20:25:02 +00:00
return __ast_goto_if_exists ( chan , context , exten , priority , 1 ) ;
}
2008-02-18 15:47:00 +00:00
static int pbx_parseable_goto ( struct ast_channel * chan , const char * goto_string , int async )
2004-11-22 22:11:10 +00:00
{
char * exten , * pri , * context ;
2006-04-18 13:37:07 +00:00
char * stringp ;
2004-11-22 22:11:10 +00:00
int ipri ;
int mode = 0 ;
2005-10-26 18:54:24 +00:00
if ( ast_strlen_zero ( goto_string ) ) {
2007-07-23 19:51:41 +00:00
ast_log ( LOG_WARNING , " Goto requires an argument ([[context,]extension,]priority) \n " ) ;
2004-11-22 22:11:10 +00:00
return - 1 ;
}
2006-04-18 13:37:07 +00:00
stringp = ast_strdupa ( goto_string ) ;
2007-07-23 19:51:41 +00:00
context = strsep ( & stringp , " , " ) ; /* guaranteed non-null */
exten = strsep ( & stringp , " , " ) ;
pri = strsep ( & stringp , " , " ) ;
2006-04-18 13:37:07 +00:00
if ( ! exten ) { /* Only a priority in this one */
2004-11-22 22:11:10 +00:00
pri = context ;
exten = NULL ;
context = NULL ;
2006-04-18 13:37:07 +00:00
} else if ( ! pri ) { /* Only an extension and priority in this one */
pri = exten ;
exten = context ;
context = NULL ;
2004-11-22 22:11:10 +00:00
}
if ( * pri = = ' + ' ) {
mode = 1 ;
pri + + ;
} else if ( * pri = = ' - ' ) {
mode = - 1 ;
pri + + ;
}
2009-08-10 19:20:57 +00:00
if ( sscanf ( pri , " %30d " , & ipri ) ! = 1 ) {
2012-02-13 17:27:06 +00:00
ipri = ast_findlabel_extension ( chan , context ? context : ast_channel_context ( chan ) ,
exten ? exten : ast_channel_exten ( chan ) , pri ,
2012-02-29 16:52:47 +00:00
S_COR ( ast_channel_caller ( chan ) - > id . number . valid , ast_channel_caller ( chan ) - > id . number . str , NULL ) ) ;
2010-07-14 15:48:36 +00:00
if ( ipri < 1 ) {
2004-11-22 22:11:10 +00:00
ast_log ( LOG_WARNING , " Priority '%s' must be a number > 0, or valid label \n " , pri ) ;
return - 1 ;
} else
mode = 0 ;
2006-05-09 08:03:52 +00:00
}
2004-11-22 22:11:10 +00:00
/* At this point we have a priority and maybe an extension and a context */
2006-05-09 08:03:52 +00:00
if ( mode )
2012-02-20 23:43:27 +00:00
ipri = ast_channel_priority ( chan ) + ( ipri * mode ) ;
2004-11-22 22:11:10 +00:00
2008-02-18 15:47:00 +00:00
if ( async )
ast_async_goto ( chan , context , exten , ipri ) ;
else
ast_explicit_goto ( chan , context , exten , ipri ) ;
2009-03-11 00:28:28 +00:00
2004-11-22 22:11:10 +00:00
return 0 ;
}
2008-02-18 15:47:00 +00:00
int ast_parseable_goto ( struct ast_channel * chan , const char * goto_string )
{
return pbx_parseable_goto ( chan , goto_string , 0 ) ;
}
int ast_async_parseable_goto ( struct ast_channel * chan , const char * goto_string )
{
return pbx_parseable_goto ( chan , goto_string , 1 ) ;
}
2009-05-26 14:36:11 +00:00
2010-11-30 09:49:25 +00:00
static int hint_hash ( const void * obj , const int flags )
{
const struct ast_hint * hint = obj ;
2011-07-22 20:46:36 +00:00
const char * exten_name ;
int res ;
2010-11-30 09:49:25 +00:00
2011-07-22 20:46:36 +00:00
exten_name = ast_get_extension_name ( hint - > exten ) ;
if ( ast_strlen_zero ( exten_name ) ) {
/*
* If the exten or extension name isn ' t set , return 0 so that
* the ao2_find ( ) search will start in the first bucket .
*/
res = 0 ;
} else {
res = ast_str_case_hash ( exten_name ) ;
2010-11-30 09:49:25 +00:00
}
return res ;
}
static int hint_cmp ( void * obj , void * arg , int flags )
{
const struct ast_hint * hint = obj ;
const struct ast_exten * exten = arg ;
return ( hint - > exten = = exten ) ? CMP_MATCH | CMP_STOP : 0 ;
}
2011-01-18 20:40:59 +00:00
static int statecbs_cmp ( void * obj , void * arg , int flags )
{
const struct ast_state_cb * state_cb = obj ;
2011-12-23 02:35:13 +00:00
ast_state_cb_type change_cb = arg ;
2011-01-18 20:40:59 +00:00
2011-12-23 02:35:13 +00:00
return ( state_cb - > change_cb = = change_cb ) ? CMP_MATCH | CMP_STOP : 0 ;
2011-01-18 20:40:59 +00:00
}
2012-12-11 20:05:32 +00:00
/*!
* \ internal
* \ brief Clean up resources on Asterisk shutdown
*/
2012-10-02 01:47:16 +00:00
static void pbx_shutdown ( void )
{
2016-01-08 22:59:44 +00:00
STASIS_MESSAGE_TYPE_CLEANUP ( hint_change_message_type ) ;
2012-10-02 01:47:16 +00:00
if ( hints ) {
2015-04-29 19:49:23 +00:00
ao2_container_unregister ( " hints " ) ;
2012-10-02 01:47:16 +00:00
ao2_ref ( hints , - 1 ) ;
2012-12-11 20:05:32 +00:00
hints = NULL ;
2012-10-02 01:47:16 +00:00
}
if ( hintdevices ) {
2015-04-29 19:49:23 +00:00
ao2_container_unregister ( " hintdevices " ) ;
2012-10-02 01:47:16 +00:00
ao2_ref ( hintdevices , - 1 ) ;
2012-12-11 20:05:32 +00:00
hintdevices = NULL ;
2012-10-02 01:47:16 +00:00
}
2016-03-28 16:31:29 +00:00
if ( autohints ) {
ao2_container_unregister ( " autohints " ) ;
ao2_ref ( autohints , - 1 ) ;
autohints = NULL ;
}
2012-10-02 01:47:16 +00:00
if ( statecbs ) {
2015-04-29 19:49:23 +00:00
ao2_container_unregister ( " statecbs " ) ;
2012-10-02 01:47:16 +00:00
ao2_ref ( statecbs , - 1 ) ;
2012-12-11 20:05:32 +00:00
statecbs = NULL ;
2012-10-02 01:47:16 +00:00
}
2013-05-13 19:29:56 +00:00
if ( contexts_table ) {
ast_hashtab_destroy ( contexts_table , NULL ) ;
}
2012-10-02 01:47:16 +00:00
}
2015-04-29 19:49:23 +00:00
static void print_hints_key ( void * v_obj , void * where , ao2_prnt_fn * prnt )
{
struct ast_hint * hint = v_obj ;
if ( ! hint ) {
return ;
}
prnt ( where , " %s@%s " , ast_get_extension_name ( hint - > exten ) ,
ast_get_context_name ( ast_get_extension_context ( hint - > exten ) ) ) ;
}
static void print_hintdevices_key ( void * v_obj , void * where , ao2_prnt_fn * prnt )
{
struct ast_hintdevice * hintdevice = v_obj ;
if ( ! hintdevice ) {
return ;
}
prnt ( where , " %s => %s@%s " , hintdevice - > hintdevice ,
ast_get_extension_name ( hintdevice - > hint - > exten ) ,
ast_get_context_name ( ast_get_extension_context ( hintdevice - > hint - > exten ) ) ) ;
}
2016-03-28 16:31:29 +00:00
static void print_autohint_key ( void * v_obj , void * where , ao2_prnt_fn * prnt )
{
struct ast_autohint * autohint = v_obj ;
if ( ! autohint ) {
return ;
}
prnt ( where , " %s " , autohint - > context ) ;
}
2015-04-29 19:49:23 +00:00
static void print_statecbs_key ( void * v_obj , void * where , ao2_prnt_fn * prnt )
{
struct ast_state_cb * state_cb = v_obj ;
if ( ! state_cb ) {
return ;
}
prnt ( where , " %d " , state_cb - > id ) ;
}
2010-11-30 09:49:25 +00:00
int ast_pbx_init ( void )
{
hints = ao2_container_alloc ( HASH_EXTENHINT_SIZE , hint_hash , hint_cmp ) ;
2015-04-29 19:49:23 +00:00
if ( hints ) {
ao2_container_register ( " hints " , hints , print_hints_key ) ;
}
2010-11-30 09:49:25 +00:00
hintdevices = ao2_container_alloc ( HASH_EXTENHINT_SIZE , hintdevice_hash_cb , hintdevice_cmp_multiple ) ;
2015-04-29 19:49:23 +00:00
if ( hintdevices ) {
ao2_container_register ( " hintdevices " , hintdevices , print_hintdevices_key ) ;
}
2016-03-28 16:31:29 +00:00
/* This is protected by the context_and_merge lock */
autohints = ao2_container_alloc_options ( AO2_ALLOC_OPT_LOCK_NOLOCK , HASH_EXTENHINT_SIZE ,
autohint_hash_cb , autohint_cmp ) ;
if ( hintdevices ) {
ao2_container_register ( " autohints " , autohints , print_autohint_key ) ;
}
2011-12-23 02:35:13 +00:00
statecbs = ao2_container_alloc ( 1 , NULL , statecbs_cmp ) ;
2015-04-29 19:49:23 +00:00
if ( statecbs ) {
ao2_container_register ( " statecbs " , statecbs , print_statecbs_key ) ;
}
2010-11-30 09:49:25 +00:00
2013-06-22 14:03:22 +00:00
ast_register_cleanup ( pbx_shutdown ) ;
2012-12-11 20:05:32 +00:00
2016-01-08 22:59:44 +00:00
if ( STASIS_MESSAGE_TYPE_INIT ( hint_change_message_type ) ! = 0 ) {
return - 1 ;
}
2016-03-28 16:31:29 +00:00
return ( hints & & hintdevices & & autohints & & statecbs ) ? 0 : - 1 ;
2010-11-30 09:49:25 +00:00
}