2007-08-15 21:25:13 +00:00
# ifndef _ASTERISK_PVAL_H
# define _ASTERISK_PVAL_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
/* whatever includes this, better include asterisk/lock.h and asterisk/hashtab.h */
2007-08-15 21:25:13 +00:00
typedef enum
{
PV_WORD , /* an ident, string, name, label, etc. A user-supplied string. */ /* 0 */
PV_MACRO , /* 1 */
PV_CONTEXT , /* 2 */
PV_MACRO_CALL , /* 3 */
PV_APPLICATION_CALL , /* 4 */
PV_CASE , /* 5 */
PV_PATTERN , /* 6 */
PV_DEFAULT , /* 7 */
PV_CATCH , /* 8 */
PV_SWITCHES , /* 9 */
PV_ESWITCHES , /* 10 */
PV_INCLUDES , /* 11 */
PV_STATEMENTBLOCK , /* 12 */
PV_VARDEC , /* you know, var=val; */ /* 13 */
PV_GOTO , /* 14 */
PV_LABEL , /* 15 */
PV_FOR , /* 16 */
PV_WHILE , /* 17 */
PV_BREAK , /* 18 */
PV_RETURN , /* 19 */
PV_CONTINUE , /* 20 */
PV_IF , /* 21 */
PV_IFTIME , /* 22 */
PV_RANDOM , /* 23 */
PV_SWITCH , /* 24 */
PV_EXTENSION , /* 25 */
PV_IGNOREPAT , /* 26 */
PV_GLOBALS , /* 27 */
PV_LOCALVARDEC , /* 28 */
} pvaltype ;
/* why this horrible mess? It's always been a tradeoff-- tons of structs,
each storing it ' s specific lists of goodies , or a ' simple ' single struct ,
with lots of fields , that catches all uses at once . Either you have a long
list of struct names and subnames , or you have a long list of field names ,
and where / how they are used . I ' m going with a single struct , using unions
to reduce storage . Some simple generalizations , and a long list of types ,
and a book about what is used with what types . . . . Sorry !
*/
struct pval
{
pvaltype type ;
int startline ;
int endline ;
int startcol ;
int endcol ;
char * filename ;
union
{
char * str ; /* wow, used almost everywhere! */
struct pval * list ; /* used in SWITCHES, ESWITCHES, INCLUDES, STATEMENTBLOCK, GOTO */
struct pval * statements ; /* used in EXTENSION */
char * for_init ; /* used in FOR */
} u1 ;
struct pval * u1_last ; /* to build in-order lists -- looks like we only need one */
union
{
struct pval * arglist ; /* used in macro_call, application_call, MACRO def, also attached to PWORD, the 4 timevals for includes */
struct pval * statements ; /* used in case, default, catch, while's statement, CONTEXT elements, GLOBALS */
char * val ; /* used in VARDEC */
char * for_test ; /* used in FOR */
struct pval * goto_target ; /* used in GOTO */
} u2 ;
union
{
char * for_inc ; /* used in FOR */
struct pval * else_statements ; /* used in IF */
struct pval * macro_statements ; /* used in MACRO */
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
int abstract ; /* used for context 1=abstract; 2=extend; 3=both */
2007-08-15 21:25:13 +00:00
char * hints ; /* used in EXTENSION */
int goto_target_in_case ; /* used in GOTO */
struct ael_extension * compiled_label ;
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 pval * extend ; /* to link extended contexts to the 'original' */
2007-08-15 21:25:13 +00:00
} u3 ;
union
{
struct pval * for_statements ; /* used in PV_FOR */
int regexten ; /* used in EXTENSION */
} u4 ;
struct pval * next ; /* the pval at the end of this ptr will ALWAYS be of the same type as this one!
EXCEPT for objects of the different types , that are in the same list , like contexts & macros , etc */
struct pval * dad ; /* the 'container' of this struct instance */
struct pval * prev ; /* the opposite of the 'next' pointer */
} ;
typedef struct pval pval ;
# ifndef AAL_ARGCHECK
/* for the time being, short circuit all the AAL related structures
without permanently removing the code ; after / during the AAL
development , this code can be properly re - instated
*/
/* null definitions for structs passed down the infrastructure */
struct argapp
{
struct argapp * next ;
} ;
# endif
struct ast_context ;
# ifdef AAL_ARGCHECK
int option_matches_j ( struct argdesc * should , pval * is , struct argapp * app ) ;
int option_matches ( struct argdesc * should , pval * is , struct argapp * app ) ;
int ael_is_funcname ( char * name ) ;
# endif
int do_pbx_load_module ( void ) ;
int count_labels_in_current_context ( char * label ) ;
int check_app_args ( pval * appcall , pval * arglist , struct argapp * app ) ;
void check_pval ( pval * item , struct argapp * apps , int in_globals ) ;
void check_pval_item ( pval * item , struct argapp * apps , int in_globals ) ;
void check_switch_expr ( pval * item , struct argapp * apps ) ;
void ast_expr_register_extra_error_info ( char * errmsg ) ;
void ast_expr_clear_extra_error_info ( void ) ;
int ast_expr ( char * expr , char * buf , int length , struct ast_channel * chan ) ;
struct pval * find_macro ( char * name ) ;
struct pval * find_context ( char * name ) ;
struct pval * find_context ( char * name ) ;
struct pval * find_macro ( char * name ) ;
struct ael_priority * new_prio ( void ) ;
struct ael_extension * new_exten ( void ) ;
2008-03-27 04:47:12 +00:00
void linkprio ( struct ael_extension * exten , struct ael_priority * prio , struct ael_extension * mother_exten ) ;
2007-08-15 21:25:13 +00:00
void destroy_extensions ( struct ael_extension * exten ) ;
/* static void linkexten(struct ael_extension *exten, struct ael_extension *add);
static void gen_prios ( struct ael_extension * exten , char * label , pval * statement , struct ael_extension * mother_exten , struct ast_context * context ) ; */
void set_priorities ( struct ael_extension * exten ) ;
void add_extensions ( struct ael_extension * exten ) ;
2010-06-18 21:32:09 +00:00
int ast_compile_ael2 ( struct ast_context * * local_contexts , struct ast_hashtab * local_table , struct pval * root ) ;
2007-08-15 21:25:13 +00:00
void destroy_pval ( pval * item ) ;
void destroy_pval_item ( pval * item ) ;
int is_float ( char * arg ) ;
int is_int ( char * arg ) ;
int is_empty ( char * arg ) ;
/* PVAL PI */
pval * pvalCreateNode ( pvaltype type ) ;
pvaltype pvalObjectGetType ( pval * p ) ;
void pvalWordSetString ( pval * p , char * str ) ;
char * pvalWordGetString ( pval * p ) ;
void pvalMacroSetName ( pval * p , char * name ) ;
char * pvalMacroGetName ( pval * p ) ;
void pvalMacroSetArglist ( pval * p , pval * arglist ) ;
void pvalMacroAddArg ( pval * p , pval * arg ) ;
pval * pvalMacroWalkArgs ( pval * p , pval * * arg ) ;
void pvalMacroAddStatement ( pval * p , pval * statement ) ;
pval * pvalMacroWalkStatements ( pval * p , pval * * next_statement ) ;
void pvalContextSetName ( pval * p , char * name ) ;
char * pvalContextGetName ( pval * p ) ;
void pvalContextSetAbstract ( pval * p ) ;
void pvalContextUnsetAbstract ( pval * p ) ;
int pvalContextGetAbstract ( pval * p ) ;
void pvalContextAddStatement ( pval * p , pval * statement ) ;
pval * pvalContextWalkStatements ( pval * p , pval * * statements ) ;
void pvalMacroCallSetMacroName ( pval * p , char * name ) ;
char * pvalMacroCallGetMacroName ( pval * p ) ;
void pvalMacroCallSetArglist ( pval * p , pval * arglist ) ;
void pvalMacroCallAddArg ( pval * p , pval * arg ) ;
pval * pvalMacroCallWalkArgs ( pval * p , pval * * args ) ;
void pvalAppCallSetAppName ( pval * p , char * name ) ;
char * pvalAppCallGetAppName ( pval * p ) ;
void pvalAppCallSetArglist ( pval * p , pval * arglist ) ;
void pvalAppCallAddArg ( pval * p , pval * arg ) ;
pval * pvalAppCallWalkArgs ( pval * p , pval * * args ) ;
void pvalCasePatSetVal ( pval * p , char * val ) ;
char * pvalCasePatGetVal ( pval * p ) ;
void pvalCasePatDefAddStatement ( pval * p , pval * statement ) ;
pval * pvalCasePatDefWalkStatements ( pval * p , pval * * statement ) ;
void pvalCatchSetExtName ( pval * p , char * name ) ;
char * pvalCatchGetExtName ( pval * p ) ;
void pvalCatchSetStatement ( pval * p , pval * statement ) ;
pval * pvalCatchGetStatement ( pval * p ) ;
void pvalSwitchesAddSwitch ( pval * p , char * name ) ;
char * pvalSwitchesWalkNames ( pval * p , pval * * next_item ) ;
void pvalESwitchesAddSwitch ( pval * p , char * name ) ;
char * pvalESwitchesWalkNames ( pval * p , pval * * next_item ) ;
void pvalIncludesAddInclude ( pval * p , const char * include ) ;
void pvalIncludesAddIncludeWithTimeConstraints ( pval * p , const char * include , char * hour_range , char * dom_range , char * dow_range , char * month_range ) ;
void pvalIncludeGetTimeConstraints ( pval * p , char * * hour_range , char * * dom_range , char * * dow_range , char * * month_range ) ;
char * pvalIncludesWalk ( pval * p , pval * * next_item ) ;
void pvalStatementBlockAddStatement ( pval * p , pval * statement ) ;
pval * pvalStatementBlockWalkStatements ( pval * p , pval * * next_statement ) ;
void pvalVarDecSetVarname ( pval * p , char * name ) ;
void pvalVarDecSetValue ( pval * p , char * value ) ;
char * pvalVarDecGetVarname ( pval * p ) ;
char * pvalVarDecGetValue ( pval * p ) ;
void pvalGotoSetTarget ( pval * p , char * context , char * exten , char * label ) ;
void pvalGotoGetTarget ( pval * p , char * * context , char * * exten , char * * label ) ;
void pvalLabelSetName ( pval * p , char * name ) ;
char * pvalLabelGetName ( pval * p ) ;
void pvalForSetInit ( pval * p , char * init ) ;
void pvalForSetTest ( pval * p , char * test ) ;
void pvalForSetInc ( pval * p , char * inc ) ;
void pvalForSetStatement ( pval * p , pval * statement ) ;
char * pvalForGetInit ( pval * p ) ;
char * pvalForGetTest ( pval * p ) ;
char * pvalForGetInc ( pval * p ) ;
pval * pvalForGetStatement ( pval * p ) ;
void pvalIfSetCondition ( pval * p , char * expr ) ;
char * pvalIfGetCondition ( pval * p ) ;
void pvalIfTimeSetCondition ( pval * p , char * hour_range , char * dow_range , char * dom_range , char * mon_range ) ; /* time range format: 24-hour format begin-end|dow range|dom range|month range */
void pvalIfTimeGetCondition ( pval * p , char * * hour_range , char * * dow_range , char * * dom_range , char * * month_range ) ;
void pvalRandomSetCondition ( pval * p , char * percent ) ;
char * pvalRandomGetCondition ( pval * p ) ;
void pvalConditionalSetThenStatement ( pval * p , pval * statement ) ;
void pvalConditionalSetElseStatement ( pval * p , pval * statement ) ;
pval * pvalConditionalGetThenStatement ( pval * p ) ;
pval * pvalConditionalGetElseStatement ( pval * p ) ;
void pvalSwitchSetTestexpr ( pval * p , char * expr ) ;
char * pvalSwitchGetTestexpr ( pval * p ) ;
void pvalSwitchAddCase ( pval * p , pval * Case ) ;
pval * pvalSwitchWalkCases ( pval * p , pval * * next_case ) ;
void pvalExtenSetName ( pval * p , char * name ) ;
char * pvalExtenGetName ( pval * p ) ;
void pvalExtenSetRegexten ( pval * p ) ;
void pvalExtenUnSetRegexten ( pval * p ) ;
int pvalExtenGetRegexten ( pval * p ) ;
void pvalExtenSetHints ( pval * p , char * hints ) ;
char * pvalExtenGetHints ( pval * p ) ;
void pvalExtenSetStatement ( pval * p , pval * statement ) ;
pval * pvalExtenGetStatement ( pval * p ) ;
void pvalIgnorePatSetPattern ( pval * p , char * pat ) ;
char * pvalIgnorePatGetPattern ( pval * p ) ;
void pvalGlobalsAddStatement ( pval * p , pval * statement ) ;
pval * pvalGlobalsWalkStatements ( pval * p , pval * * next_statement ) ;
void pvalTopLevAddObject ( pval * p , pval * contextOrObj ) ;
pval * pvalTopLevWalkObjects ( pval * p , pval * * next_obj ) ;
int pvalCheckType ( pval * p , char * funcname , pvaltype type ) ;
# endif