2007-12-08 03:27:16 +00:00
/*
* XXX this file probably need a fair amount of cleanup , at the very least :
*
* - documenting its purpose ;
* - removing all unnecessary headers and other stuff from the sources
* it was copied from ;
* - fixing the formatting
*/
# include "asterisk.h"
2006-04-24 17:41:27 +00:00
# include <locale.h>
# include <ctype.h>
# include <regex.h>
# include <limits.h>
2006-05-01 19:23:43 +00:00
2007-11-26 17:46:41 +00:00
ASTERISK_FILE_VERSION ( __FILE__ , " $Revision$ " )
2006-08-21 02:11:39 +00:00
# include "asterisk/channel.h"
2007-08-15 19:21:27 +00:00
# include "asterisk/ast_expr.h"
2006-04-27 00:05:05 +00:00
# include "asterisk/module.h"
2006-08-21 02:11:39 +00:00
# include "asterisk/app.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/lock.h"
# include "asterisk/hashtab.h"
2006-04-24 17:41:27 +00:00
# include "asterisk/ael_structs.h"
2007-08-15 19:21:27 +00:00
# include "asterisk/extconf.h"
2006-05-01 19:23:43 +00:00
2007-08-24 14:55:34 +00:00
/*** MODULEINFO
2007-08-24 15:29:16 +00:00
< depend > res_ael_share < / depend >
* * */
2007-08-24 14:55:34 +00:00
2006-08-09 01:17:47 +00:00
struct namelist
{
char name [ 100 ] ;
char name2 [ 100 ] ;
struct namelist * next ;
} ;
struct ast_context
{
int extension_count ;
char name [ 100 ] ;
char registrar [ 100 ] ;
struct namelist * includes ;
struct namelist * ignorepats ;
struct namelist * switches ;
struct namelist * eswitches ;
struct namelist * includes_last ;
struct namelist * ignorepats_last ;
struct namelist * switches_last ;
struct namelist * eswitches_last ;
struct ast_context * next ;
} ;
# define ADD_LAST(headptr,memptr) if(!headptr){ headptr=(memptr); (headptr##_last)=(memptr);} else {(headptr##_last)->next = (memptr); (headptr##_last) = (memptr);}
void destroy_namelist ( struct namelist * x ) ;
void destroy_namelist ( struct namelist * x )
{
struct namelist * z , * z2 ;
for ( z = x ; z ; z = z2 )
{
z2 = z - > next ;
z - > next = 0 ;
free ( z ) ;
}
}
2007-09-21 14:40:10 +00:00
struct namelist * create_name ( const char * name ) ;
struct namelist * create_name ( const char * name )
2006-08-09 01:17:47 +00:00
{
2006-10-24 01:28:45 +00:00
struct namelist * x = calloc ( 1 , sizeof ( * x ) ) ;
if ( ! x )
return NULL ;
strncpy ( x - > name , name , sizeof ( x - > name ) - 1 ) ;
2006-08-09 01:17:47 +00:00
return x ;
}
struct ast_context * context_list ;
struct ast_context * last_context ;
struct namelist * globalvars ;
struct namelist * globalvars_last ;
2006-04-24 17:41:27 +00:00
int conts = 0 , extens = 0 , priors = 0 ;
char last_exten [ 18000 ] ;
2007-12-20 09:55:05 +00:00
static char config_dir [ PATH_MAX ] ;
static char var_dir [ PATH_MAX ] ;
const char * ast_config_AST_CONFIG_DIR = config_dir ;
const char * ast_config_AST_VAR_DIR = var_dir ;
2006-04-24 17:41:27 +00:00
void ast_cli_register_multiple ( void ) ;
2006-08-09 01:17:47 +00:00
int ast_add_extension2 ( struct ast_context * con ,
2006-04-24 17:41:27 +00:00
int replace , const char * extension , int priority , const char * label , const char * callerid ,
const char * application , void * data , void ( * datad ) ( void * ) ,
const char * registrar ) ;
void pbx_builtin_setvar ( void * chan , void * data ) ;
2006-08-09 01:17:47 +00:00
struct ast_context * ast_context_create ( void * * extcontexts , const char * name , const char * registrar ) ;
Merged revisions 87168 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r87168 | murf | 2007-10-26 10:34:02 -0600 (Fri, 26 Oct 2007) | 1 line
closes issue #11086 where a user complains that references to following contexts report a problem; The problem was REALLy that he was referring to empty contexts, which were being ignored. Reporter stated that empty contexts should be OK. I checked it out against extensions.conf, and sure enough, empty contexts ARE ok. So, I removed the restriction from AEL. This, though, highlighted a problem with multiple contexts of the same name. This should be OK, also. So, I added the extend keyword to AEL, and it can preceed the 'context' keyword (mixed with 'abstract', if nec.). This will turn off the warnings in AEL if the same context name is used 2 or more times. Also, I now call ast_context_find_or_create for contexts now, instead of just ast_context_create; I did this because pbx_config does this. The 'extend' keyword thus becomes a statement of intent. AEL can now duplicate the behavior of pbx_config,
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@87187 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-10-26 17:39:39 +00:00
struct ast_context * ast_context_find_or_create ( void * * extcontexts , const char * name , const char * registrar ) ;
2006-08-09 01:17:47 +00:00
void ast_context_add_ignorepat2 ( struct ast_context * con , const char * value , const char * registrar ) ;
void ast_context_add_include2 ( struct ast_context * con , const char * value , const char * registrar ) ;
void ast_context_add_switch2 ( struct ast_context * con , const char * value , const char * data , int eval , const char * registrar ) ;
2006-04-24 17:41:27 +00:00
void ast_merge_contexts_and_delete ( void ) ;
void ast_context_verify_includes ( void ) ;
struct ast_context * ast_walk_contexts ( void ) ;
void ast_cli_unregister_multiple ( void ) ;
void ast_context_destroy ( void ) ;
void ast_log ( int level , const char * file , int line , const char * function , const char * fmt , . . . ) ;
char * ast_process_quotes_and_slashes ( char * start , char find , char replace_with ) ;
void ast_verbose ( const char * fmt , . . . ) ;
struct ast_app * pbx_findapp ( const char * app ) ;
2006-08-09 01:17:47 +00:00
void filter_leading_space_from_exprs ( char * str ) ;
void filter_newlines ( char * str ) ;
2006-08-11 21:30:03 +00:00
static int quiet = 0 ;
2006-04-24 17:41:27 +00:00
static int no_comp = 0 ;
static int use_curr_dir = 0 ;
2006-08-09 01:17:47 +00:00
static int dump_extensions = 0 ;
static int FIRST_TIME = 0 ;
static FILE * dumpfile ;
2006-04-24 17:41:27 +00:00
2007-08-15 19:21:27 +00:00
void ast_log ( int level , const char * file , int line , const char * function , const char * fmt , . . . )
{
va_list vars ;
va_start ( vars , fmt ) ;
printf ( " LOG: lev:%d file:%s line:%d func: %s " ,
level , file , line , function ) ;
vprintf ( fmt , vars ) ;
fflush ( stdout ) ;
va_end ( vars ) ;
}
struct ast_exten * pbx_find_extension ( struct ast_channel * chan ,
struct ast_context * bypass ,
struct pbx_find_info * q ,
const char * context ,
const char * exten ,
int priority ,
const char * label ,
const char * callerid ,
enum ext_match_t action ) ;
struct ast_exten * pbx_find_extension ( struct ast_channel * chan ,
struct ast_context * bypass ,
struct pbx_find_info * q ,
const char * context ,
const char * exten ,
int priority ,
const char * label ,
const char * callerid ,
enum ext_match_t action )
{
return localized_find_extension ( bypass , q , context , exten , priority , label , callerid , action ) ;
}
2006-04-24 17:41:27 +00:00
struct ast_app * pbx_findapp ( const char * app )
{
return ( struct ast_app * ) 1 ; /* so as not to trigger an error */
}
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
struct ast_custom_function * ast_custom_function_find ( const char * name ) ;
struct ast_custom_function * ast_custom_function_find ( const char * name )
{
return 0 ; /* in "standalone" mode, functions are just not avail */
}
2007-11-21 16:07:11 +00:00
void ast_register_file_version ( const char * file , const char * version )
{
}
void ast_unregister_file_version ( const char * file )
{
}
In regards to changes for 9508, expr2 system choking on floating point numbers, I'm adding this update to round out (no pun intended) and make this FP-capable version of the Expr2 stuff interoperate better with previous integer-only usage, by providing Functions syntax, with 20 builtin functions for floating pt to integer conversions, and some general floating point math routines that might commonly be used also. Along with this, I made it so if a function was not a builtin, it will try and find it in the ast_custom_function list, and if found, execute it and collect the results. Thus, you can call system functions like CDR(), CHANNEL(), etc, from within $\[..\] exprs, without having to wrap them in $\{...\} (curly brace) notation. Did a valgrind on the standalone and made sure there's no mem leaks. Looks good. Updated the docs, too.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@73449 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-05 18:15:22 +00:00
2007-11-21 16:07:11 +00:00
int ast_add_profile ( const char * x , uint64_t scale )
2006-05-20 00:41:36 +00:00
{
if ( ! no_comp )
printf ( " Executed ast_add_profile(); \n " ) ;
2007-11-21 16:07:11 +00:00
return 0 ;
2006-05-20 00:41:36 +00:00
}
2006-08-25 20:43:51 +00:00
int ast_loader_register ( int ( * updater ) ( void ) )
{
return 1 ;
}
int ast_loader_unregister ( int ( * updater ) ( void ) )
{
return 1 ;
}
void ast_module_register ( const struct ast_module_info * x )
{
}
void ast_module_unregister ( const struct ast_module_info * x )
{
}
2006-04-24 17:41:27 +00:00
void ast_cli_register_multiple ( void )
{
if ( ! no_comp )
2006-08-11 21:30:03 +00:00
printf ( " Executed ast_cli_register_multiple(); \n " ) ;
2006-04-24 17:41:27 +00:00
}
2007-08-14 14:32:21 +00:00
void pbx_substitute_variables_helper ( struct ast_channel * c , const char * cp1 , char * cp2 , int count ) ;
void pbx_substitute_variables_helper ( struct ast_channel * c , const char * cp1 , char * cp2 , int count )
{
if ( cp1 & & * cp1 )
strncpy ( cp2 , cp1 , AST_MAX_EXTENSION ) ; /* Right now, this routine is ONLY being called for
a possible var substitution on extension names ,
so . . . . ! */
else
* cp2 = 0 ;
}
2006-08-09 01:17:47 +00:00
int ast_add_extension2 ( 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 * ) ,
const char * registrar )
2006-04-24 17:41:27 +00:00
{
priors + + ;
2006-08-09 01:17:47 +00:00
con - > extension_count + + ;
2006-04-24 17:41:27 +00:00
if ( strcmp ( extension , last_exten ) ! = 0 ) {
extens + + ;
strcpy ( last_exten , extension ) ;
}
if ( ! label ) {
label = " (null) " ;
}
if ( ! callerid ) {
callerid = " (null) " ;
}
if ( ! application ) {
application = " (null) " ;
}
2006-08-09 01:17:47 +00:00
2006-04-24 17:41:27 +00:00
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_add_extension2(context=%s, rep=%d, exten=%s, priority=%d, label=%s, callerid=%s, appl=%s, data=%s, FREE, registrar=%s); \n " ,
con - > name , replace , extension , priority , label , callerid , application , ( data ? ( char * ) data : " (null) " ) , registrar ) ;
if ( dump_extensions & & dumpfile ) {
struct namelist * n ;
2007-03-02 05:57:06 +00:00
char * data2 , * data3 = 0 ;
int commacount = 0 ;
2006-08-09 01:17:47 +00:00
if ( FIRST_TIME ) {
FIRST_TIME = 0 ;
if ( globalvars )
fprintf ( dumpfile , " [globals] \n " ) ;
for ( n = globalvars ; n ; n = n - > next ) {
fprintf ( dumpfile , " %s \n " , n - > name ) ;
}
}
/* print out each extension , possibly the context header also */
if ( con ! = last_context ) {
fprintf ( dumpfile , " \n \n [%s] \n " , con - > name ) ;
last_context = con ;
for ( n = con - > ignorepats ; n ; n = n - > next ) {
fprintf ( dumpfile , " ignorepat => %s \n " , n - > name ) ;
}
for ( n = con - > includes ; n ; n = n - > next ) {
fprintf ( dumpfile , " include => %s \n " , n - > name ) ;
}
for ( n = con - > switches ; n ; n = n - > next ) {
fprintf ( dumpfile , " switch => %s/%s \n " , n - > name , n - > name2 ) ;
}
for ( n = con - > eswitches ; n ; n = n - > next ) {
fprintf ( dumpfile , " eswitch => %s/%s \n " , n - > name , n - > name2 ) ;
}
}
if ( data ) {
filter_newlines ( ( char * ) data ) ;
filter_leading_space_from_exprs ( ( char * ) data ) ;
2007-03-02 05:57:06 +00:00
/* compiling turns commas into vertical bars in the app data, and also removes the backslash from before escaped commas;
we have to restore the escaping backslash in front of any commas ; the vertical bars are OK to leave as - is */
for ( data2 = data ; * data2 ; data2 + + ) {
if ( * data2 = = ' , ' )
commacount + + ; /* we need to know how much bigger the string will grow-- one backslash for each comma */
}
if ( commacount )
{
char * d3 , * d4 ;
data2 = ( char * ) malloc ( strlen ( data ) + commacount + 1 ) ;
data3 = data ;
d3 = data ;
d4 = data2 ;
while ( * d3 ) {
if ( * d3 = = ' , ' ) {
* d4 + + = ' \\ ' ; /* put a backslash in front of each comma */
* d4 + + = * d3 + + ;
} else
* d4 + + = * d3 + + ; /* or just copy the char */
}
* d4 + + = 0 ; /* cap off the new string */
data = data2 ;
} else
data2 = 0 ;
2006-08-09 01:17:47 +00:00
if ( strcmp ( label , " (null) " ) ! = 0 )
fprintf ( dumpfile , " exten => %s,%d(%s),%s(%s) \n " , extension , priority , label , application , ( char * ) data ) ;
else
fprintf ( dumpfile , " exten => %s,%d,%s(%s) \n " , extension , priority , application , ( char * ) data ) ;
2006-04-24 17:41:27 +00:00
2007-03-02 05:57:06 +00:00
if ( data2 ) {
free ( data2 ) ;
data2 = 0 ;
data = data3 ; /* restore data to pre-messedup state */
}
2006-08-09 01:17:47 +00:00
} else {
if ( strcmp ( label , " (null) " ) ! = 0 )
fprintf ( dumpfile , " exten => %s,%d(%s),%s \n " , extension , priority , label , application ) ;
else
fprintf ( dumpfile , " exten => %s,%d,%s \n " , extension , priority , application ) ;
}
}
2006-04-24 17:41:27 +00:00
/* since add_extension2 is responsible for the malloc'd data stuff */
if ( data )
free ( data ) ;
return 0 ;
}
void pbx_builtin_setvar ( void * chan , void * data )
{
2007-09-21 14:40:10 +00:00
struct namelist * x = create_name ( data ) ;
2006-04-24 17:41:27 +00:00
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed pbx_builtin_setvar(chan, data=%s); \n " , ( char * ) data ) ;
if ( dump_extensions ) {
2007-09-21 14:40:10 +00:00
x = create_name ( data ) ;
2006-08-09 01:17:47 +00:00
ADD_LAST ( globalvars , x ) ;
}
2006-04-24 17:41:27 +00:00
}
2006-08-09 01:17:47 +00:00
struct ast_context * ast_context_create ( void * * extcontexts , const char * name , const char * registrar )
2006-04-24 17:41:27 +00:00
{
2006-10-24 01:28:45 +00:00
struct ast_context * x = calloc ( 1 , sizeof ( * x ) ) ;
if ( ! x )
return NULL ;
2006-08-09 01:17:47 +00:00
x - > next = context_list ;
context_list = x ;
2006-10-24 01:28:45 +00:00
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_context_create(conts, name=%s, registrar=%s); \n " , name , registrar ) ;
2006-04-24 17:41:27 +00:00
conts + + ;
2006-10-24 01:28:45 +00:00
strncpy ( x - > name , name , sizeof ( x - > name ) - 1 ) ;
strncpy ( x - > registrar , registrar , sizeof ( x - > registrar ) - 1 ) ;
2006-08-09 01:17:47 +00:00
return x ;
Merged revisions 87168 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r87168 | murf | 2007-10-26 10:34:02 -0600 (Fri, 26 Oct 2007) | 1 line
closes issue #11086 where a user complains that references to following contexts report a problem; The problem was REALLy that he was referring to empty contexts, which were being ignored. Reporter stated that empty contexts should be OK. I checked it out against extensions.conf, and sure enough, empty contexts ARE ok. So, I removed the restriction from AEL. This, though, highlighted a problem with multiple contexts of the same name. This should be OK, also. So, I added the extend keyword to AEL, and it can preceed the 'context' keyword (mixed with 'abstract', if nec.). This will turn off the warnings in AEL if the same context name is used 2 or more times. Also, I now call ast_context_find_or_create for contexts now, instead of just ast_context_create; I did this because pbx_config does this. The 'extend' keyword thus becomes a statement of intent. AEL can now duplicate the behavior of pbx_config,
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@87187 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-10-26 17:39:39 +00:00
}
struct ast_context * ast_context_find_or_create ( void * * extcontexts , const char * name , const char * registrar )
{
struct ast_context * x = calloc ( 1 , sizeof ( * x ) ) ;
if ( ! x )
return NULL ;
x - > next = context_list ;
context_list = x ;
if ( ! no_comp )
printf ( " Executed ast_context_find_or_create(conts, name=%s, registrar=%s); \n " , name , registrar ) ;
conts + + ;
strncpy ( x - > name , name , sizeof ( x - > name ) - 1 ) ;
strncpy ( x - > registrar , registrar , sizeof ( x - > registrar ) - 1 ) ;
return x ;
2006-04-24 17:41:27 +00:00
}
2006-08-09 01:17:47 +00:00
void ast_context_add_ignorepat2 ( struct ast_context * con , const char * value , const char * registrar )
2006-04-24 17:41:27 +00:00
{
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_context_add_ignorepat2(con, value=%s, registrar=%s); \n " , value , registrar ) ;
if ( dump_extensions ) {
struct namelist * x ;
2007-09-21 14:40:10 +00:00
x = create_name ( value ) ;
2006-08-09 01:17:47 +00:00
ADD_LAST ( con - > ignorepats , x ) ;
}
2006-04-24 17:41:27 +00:00
}
2006-08-09 01:17:47 +00:00
void ast_context_add_include2 ( struct ast_context * con , const char * value , const char * registrar )
2006-04-24 17:41:27 +00:00
{
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_context_add_include2(con, value=%s, registrar=%s); \n " , value , registrar ) ;
if ( dump_extensions ) {
struct namelist * x ;
x = create_name ( ( char * ) value ) ;
ADD_LAST ( con - > includes , x ) ;
}
2006-04-24 17:41:27 +00:00
}
2006-08-09 01:17:47 +00:00
void ast_context_add_switch2 ( struct ast_context * con , const char * value , const char * data , int eval , const char * registrar )
2006-04-24 17:41:27 +00:00
{
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_context_add_switch2(con, value=%s, data=%s, eval=%d, registrar=%s); \n " , value , data , eval , registrar ) ;
if ( dump_extensions ) {
struct namelist * x ;
x = create_name ( ( char * ) value ) ;
strncpy ( x - > name2 , data , 100 ) ;
if ( eval ) {
ADD_LAST ( con - > switches , x ) ;
} else {
ADD_LAST ( con - > eswitches , x ) ;
}
}
2006-04-24 17:41:27 +00:00
}
void ast_merge_contexts_and_delete ( void )
{
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_merge_contexts_and_delete(); \n " ) ;
2006-04-24 17:41:27 +00:00
}
void ast_context_verify_includes ( void )
{
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_context_verify_includes(); \n " ) ;
2006-04-24 17:41:27 +00:00
}
struct ast_context * ast_walk_contexts ( void )
{
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_walk_contexts(); \n " ) ;
2006-04-24 17:41:27 +00:00
return 0 ;
}
void ast_cli_unregister_multiple ( void )
{
if ( ! no_comp )
2006-08-09 01:17:47 +00:00
printf ( " Executed ast_cli_unregister_multiple(); \n " ) ;
2006-04-24 17:41:27 +00:00
}
void ast_context_destroy ( void )
{
2006-08-11 21:30:03 +00:00
if ( ! no_comp )
printf ( " Executed ast_context_destroy(); \n " ) ;
2006-04-24 17:41:27 +00:00
}
2006-08-09 01:17:47 +00:00
void filter_leading_space_from_exprs ( char * str )
{
/* Mainly for aesthetics */
char * t , * v , * u = str ;
while ( u & & * u ) {
2006-04-24 17:41:27 +00:00
2006-08-09 01:17:47 +00:00
if ( * u = = ' $ ' & & * ( u + 1 ) = = ' [ ' ) {
t = u + 2 ;
while ( * t = = ' \n ' | | * t = = ' \r ' | | * t = = ' \t ' | | * t = = ' ' ) {
v = t ;
while ( * v ) {
* v = * ( v + 1 ) ;
v + + ;
}
}
}
u + + ;
}
}
void filter_newlines ( char * str )
{
/* remove all newlines, returns */
char * t = str ;
while ( t & & * t ) {
if ( * t = = ' \n ' | | * t = = ' \r ' ) {
* t = ' ' ; /* just replace newlines and returns with spaces; they act as
token separators , and just blindly removing them could be
harmful . */
}
t + + ;
}
}
extern struct module_symbols mod_data ;
2007-08-15 19:21:27 +00:00
int ael_external_load_module ( void ) ;
2006-04-24 17:41:27 +00:00
int main ( int argc , char * * argv )
{
int i ;
2006-08-09 01:17:47 +00:00
struct namelist * n ;
struct ast_context * lp , * lp2 ;
2006-04-24 17:41:27 +00:00
2006-08-09 01:17:47 +00:00
for ( i = 1 ; i < argc ; i + + ) {
2006-04-24 17:41:27 +00:00
if ( argv [ i ] [ 0 ] = = ' - ' & & argv [ i ] [ 1 ] = = ' n ' )
no_comp = 1 ;
2006-08-11 21:30:03 +00:00
if ( argv [ i ] [ 0 ] = = ' - ' & & argv [ i ] [ 1 ] = = ' q ' ) {
quiet = 1 ;
no_comp = 1 ;
}
2006-04-24 17:41:27 +00:00
if ( argv [ i ] [ 0 ] = = ' - ' & & argv [ i ] [ 1 ] = = ' d ' )
use_curr_dir = 1 ;
2006-08-09 01:17:47 +00:00
if ( argv [ i ] [ 0 ] = = ' - ' & & argv [ i ] [ 1 ] = = ' w ' )
dump_extensions = 1 ;
2006-04-24 17:41:27 +00:00
}
2006-08-11 21:30:03 +00:00
if ( ! quiet ) {
printf ( " \n (If you find progress and other non-error messages irritating, you can use -q to suppress them) \n " ) ;
if ( ! no_comp )
printf ( " \n (You can use the -n option if you aren't interested in seeing all the instructions generated by the compiler) \n \n " ) ;
if ( ! use_curr_dir )
printf ( " \n (You can use the -d option if you want to use the current working directory as the CONFIG_DIR. I will look in this dir for extensions.ael* and its included files) \n \n " ) ;
if ( ! dump_extensions )
printf ( " \n (You can use the -w option to dump extensions.conf format to extensions.conf.aeldump) \n " ) ;
}
2006-08-09 01:17:47 +00:00
if ( use_curr_dir ) {
2007-12-20 09:55:05 +00:00
strcpy ( config_dir , " . " ) ;
2007-08-15 19:21:27 +00:00
localized_use_local_dir ( ) ;
2006-04-24 17:41:27 +00:00
}
2006-08-09 01:17:47 +00:00
else {
2007-12-20 09:55:05 +00:00
strcpy ( config_dir , " /etc/asterisk " ) ;
2007-08-15 19:21:27 +00:00
localized_use_conf_dir ( ) ;
2006-04-24 17:41:27 +00:00
}
2007-12-20 09:55:05 +00:00
strcpy ( var_dir , " /var/lib/asterisk " ) ;
2006-04-24 17:41:27 +00:00
2006-08-09 01:17:47 +00:00
if ( dump_extensions ) {
dumpfile = fopen ( " extensions.conf.aeldump " , " w " ) ;
if ( ! dumpfile ) {
printf ( " \n \n Sorry, cannot open extensions.conf.aeldump for writing! Correct the situation and try again! \n \n " ) ;
exit ( 10 ) ;
}
}
FIRST_TIME = 1 ;
2006-08-25 20:43:51 +00:00
ael_external_load_module ( ) ;
2006-04-24 17:41:27 +00:00
ast_log ( 4 , " ael2_parse " , __LINE__ , " main " , " %d contexts, %d extensions, %d priorities \n " , conts , extens , priors ) ;
2006-08-09 01:17:47 +00:00
if ( dump_extensions & & dumpfile ) {
for ( lp = context_list ; lp ; lp = lp - > next ) { /* print out any contexts that didn't have any
extensions in them */
if ( lp - > extension_count = = 0 ) {
fprintf ( dumpfile , " \n \n [%s] \n " , lp - > name ) ;
for ( n = lp - > ignorepats ; n ; n = n - > next ) {
fprintf ( dumpfile , " ignorepat => %s \n " , n - > name ) ;
}
for ( n = lp - > includes ; n ; n = n - > next ) {
fprintf ( dumpfile , " include => %s \n " , n - > name ) ;
}
for ( n = lp - > switches ; n ; n = n - > next ) {
fprintf ( dumpfile , " switch => %s/%s \n " , n - > name , n - > name2 ) ;
}
for ( n = lp - > eswitches ; n ; n = n - > next ) {
fprintf ( dumpfile , " eswitch => %s/%s \n " , n - > name , n - > name2 ) ;
}
}
}
}
if ( dump_extensions & & dumpfile )
fclose ( dumpfile ) ;
for ( lp = context_list ; lp ; lp = lp2 ) { /* free the ast_context structs */
lp2 = lp - > next ;
lp - > next = 0 ;
destroy_namelist ( lp - > includes ) ;
destroy_namelist ( lp - > ignorepats ) ;
destroy_namelist ( lp - > switches ) ;
destroy_namelist ( lp - > eswitches ) ;
free ( lp ) ;
}
2006-04-24 17:41:27 +00:00
return 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
int ast_hashtab_compare_contexts ( const void * ah_a , const void * ah_b ) ;
int ast_hashtab_compare_contexts ( const void * ah_a , const void * ah_b )
{
return 0 ;
}
unsigned int ast_hashtab_hash_contexts ( const void * obj ) ;
unsigned int ast_hashtab_hash_contexts ( const void * obj )
{
return 0 ;
}
# ifdef DEBUG_THREADS
void ast_mark_lock_acquired ( void * lock_addr )
{
}
void ast_remove_lock_info ( void * lock_addr )
{
}
void ast_store_lock_info ( enum ast_lock_type type , const char * filename ,
int line_num , const char * func , const char * lock_name , void * lock_addr )
{
}
# endif