@ -773,7 +773,7 @@ struct ast_exten {
int priority ; /*!< Priority */
const char * label ; /*!< Label */
struct ast_context * parent ; /*!< The context this extension belongs to */
const char * app ; /*!< Application to execute */
const char * app ; /*!< Application to execute */
struct ast_app * cached_app ; /*!< Cached location of application */
void * data ; /*!< Data to use (arguments) */
void ( * datad ) ( void * ) ; /*!< Data destructor */
@ -838,10 +838,10 @@ struct scoreboard /* make sure all fields are 0 before calling new_find_extensi
/*! \brief ast_context: An extension context */
struct ast_context {
ast_rwlock_t lock ; /*!< A lock to prevent multiple threads from clobbering the context */
ast_rwlock_t lock ; /*!< A lock to prevent multiple threads from clobbering the context */
struct ast_exten * root ; /*!< The root of the list of extensions */
struct ast_hashtab * root_table ; /*!< For exact matches on the extensions in the pattern tree, and for traversals of the pattern_tree */
struct match_char * pattern_tree ; /*!< A tree to speed up extension pattern matching */
struct match_char * pattern_tree ; /*!< A tree to speed up extension pattern matching */
struct ast_context * next ; /*!< Link them together */
struct ast_include * includes ; /*!< Include other contexts */
struct ast_ignorepat * ignorepats ; /*!< Patterns for which to continue playing dialtone */
@ -884,7 +884,7 @@ struct ast_state_cb {
*/
struct ast_hint {
struct ast_exten * exten ; /*!< Extension */
int laststate ; /*!< Last known state */
int laststate ; /*!< Last known state */
AST_LIST_HEAD_NOLOCK ( , ast_state_cb ) callbacks ; /*!< Callback list for this extension */
AST_RWLIST_ENTRY ( ast_hint ) list ; /*!< Pointer to next hint in list */
} ;
@ -1119,7 +1119,7 @@ static struct pbx_builtin {
static struct ast_context * contexts ;
static struct ast_hashtab * contexts_table = NULL ;
AST_RWLOCK_DEFINE_STATIC ( conlock ) ; /*!< Lock for the ast_context list */
AST_RWLOCK_DEFINE_STATIC ( conlock ) ; /*!< Lock for the ast_context list */
static AST_RWLIST_HEAD_STATIC ( apps , ast_app ) ;
@ -1319,9 +1319,9 @@ int check_contexts(char *file, int line )
/*
\ note This function is special . It saves the stack so that no matter
how many times it is called , it returns to the same place */
int pbx_exec ( struct ast_channel * c , /*!< Channel */
struct ast_app * app , /*!< Application */
void * data ) /*!< Data for execution */
int pbx_exec ( struct ast_channel * c , /*!< Channel */
struct ast_app * app , /*!< Application */
void * data ) /*!< Data for execution */
{
int res ;
struct ast_module_user * u = NULL ;
@ -1568,27 +1568,33 @@ static struct ast_exten *trie_find_next_match(struct match_char *node)
struct match_char * m4 ;
struct ast_exten * e3 ;
if ( node & & node - > x [ 0 ] = = ' . ' & & ! node - > x [ 1 ] ) /* dot and ! will ALWAYS be next match in a matchmore */
if ( node & & node - > x [ 0 ] = = ' . ' & & ! node - > x [ 1 ] ) { /* dot and ! will ALWAYS be next match in a matchmore */
return node - > exten ;
}
if ( node & & node - > x [ 0 ] = = ' ! ' & & ! node - > x [ 1 ] )
if ( node & & node - > x [ 0 ] = = ' ! ' & & ! node - > x [ 1 ] ) {
return node - > exten ;
}
if ( ! node | | ! node - > next_char )
if ( ! node | | ! node - > next_char ) {
return NULL ;
}
m3 = node - > next_char ;
if ( m3 - > exten )
if ( m3 - > exten ) {
return m3 - > exten ;
for ( m4 = m3 - > alt_char ; m4 ; m4 = m4 - > alt_char ) {
if ( m4 - > exten )
}
for ( m4 = m3 - > alt_char ; m4 ; m4 = m4 - > alt_char ) {
if ( m4 - > exten ) {
return m4 - > exten ;
}
}
for ( m4 = m3 ; m4 ; m4 = m4 - > alt_char ) {
for ( m4 = m3 ; m4 ; m4 = m4 - > alt_char ) {
e3 = trie_find_next_match ( m3 ) ;
if ( e3 )
if ( e3 ) {
return e3 ;
}
}
return NULL ;
}
@ -1596,8 +1602,7 @@ static struct ast_exten *trie_find_next_match(struct match_char *node)
# ifdef DEBUG_THIS
static char * action2str ( enum ext_match_t action )
{
switch ( action )
{
switch ( action ) {
case E_MATCH :
return " MATCH " ;
case E_CANMATCH :
@ -1625,13 +1630,13 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct
else
ast_log ( LOG_NOTICE , " new_find_extension called with %s on (sub)tree NULL action=%s \n " , str , action2str ( action ) ) ;
# endif
for ( p = tree ; p ; p = p - > alt_char ) {
for ( p = tree ; p ; p = p - > alt_char ) {
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 ( 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 ) ; \
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 ) ) { \
@ -1647,27 +1652,27 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct
}
# define NEW_MATCHER_RECURSE \
if ( p - > next_char & & ( * ( str + 1 ) | | ( p - > next_char - > x [ 0 ] = = ' / ' & & p - > next_char - > x [ 1 ] = = 0 ) \
| | p - > next_char - > x [ 0 ] = = ' ! ' ) ) { \
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 ( p - > next_char & & ( * ( str + 1 ) | | ( p - > next_char - > x [ 0 ] = = ' / ' & & p - > next_char - > x [ 1 ] = = 0 ) \
| | p - > next_char - > x [ 0 ] = = ' ! ' ) ) { \
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 ) { \
ast_debug ( 4 , " returning an exact match-- %s \n " , score - > exten - > exten ) ; \
ast_debug ( 4 , " returning an exact match-- %s \n " , score - > exten - > exten ) ; \
return ; /* the first match is all we need */ \
} \
} else { \
new_find_extension ( " / " , score , p - > next_char , length + 1 , spec + p - > specificity , callerid , label , action ) ; \
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 ) ) { \
ast_debug ( 4 , " returning a (can/more) match--- %s \n " , score - > exten ? score - > exten - > exten : \
" NULL " ) ; \
" NULL " ) ; \
return ; /* the first match is all we need */ \
} \
} \
} else if ( p - > next_char & & ! * ( str + 1 ) ) { \
} else if ( p - > next_char & & ! * ( str + 1 ) ) { \
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 ) ; \
ast_debug ( 4 , " returning a canmatch/matchmore--- str=%s \n " , str ) ; \
return ; \
} \
}
@ -1703,7 +1708,7 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct
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 ) ) {
ast_debug ( 4 , " return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set--- %s \n " , score - > exten ? score - > exten - > exten : " NULL " ) ;
ast_debug ( 4 , " return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set--- %s \n " , score - > exten ? score - > exten - > exten : " NULL " ) ;
return ; /* the first match is all we need */
}
}
@ -1716,14 +1721,14 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct
i + + ;
}
if ( p - > exten & & * str2 ! = ' / ' ) {
update_scoreboard ( score , length + 1 , spec + ( p - > specificity * i ) , p - > exten , ' ! ' , callerid , p - > deleted , p ) ;
update_scoreboard ( score , length + 1 , spec + ( p - > specificity * i ) , p - > exten , ' ! ' , callerid , p - > deleted , p ) ;
if ( score - > exten ) {
ast_debug ( 4 , " return because scoreboard has a '!' match--- %s \n " , score - > exten - > exten ) ;
ast_debug ( 4 , " return because scoreboard has a '!' match--- %s \n " , score - > exten - > exten ) ;
return ; /* the first match is all we need */
}
}
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 ) ;
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 ) ) {
ast_debug ( 4 , " return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/' and '!'--- %s \n " , score - > exten ? score - > exten - > exten : " NULL " ) ;
return ; /* the first match is all we need */
@ -1734,7 +1739,7 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct
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 ) ) {
ast_debug ( 4 , " return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/'--- %s \n " , score - > exten ? score - > exten - > exten : " NULL " ) ;
ast_debug ( 4 , " return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/'--- %s \n " , score - > exten ? score - > exten - > exten : " NULL " ) ;
return ; /* the first match is all we need */
}
}
@ -1744,7 +1749,7 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct
NEW_MATCHER_RECURSE ;
}
}
ast_debug ( 4 , " return at end of func \n " ) ;
ast_debug ( 4 , " return at end of func \n " ) ;
}
/* the algorithm for forming the extension pattern tree is also a bit simple; you
@ -1768,12 +1773,14 @@ static struct match_char *already_in_tree(struct match_char *current, char *pat)
{
struct match_char * t ;
if ( ! current )
if ( ! current ) {
return 0 ;
}
for ( t = current ; t ; t = t - > alt_char ) {
if ( ! strcmp ( pat , t - > x ) ) /* uh, we may want to sort exploded [] contents to make matching easy */
if ( ! strcmp ( pat , t - > x ) ) { /* uh, we may want to sort exploded [] contents to make matching easy */
return t ;
}
}
return 0 ;
@ -1792,13 +1799,13 @@ static void insert_in_next_chars_alt_char_list(struct match_char **parent_ptr, s
if ( ! ( * parent_ptr ) ) {
* parent_ptr = node ;
} else {
if ( ( * parent_ptr ) - > specificity > node - > specificity ) {
if ( ( * parent_ptr ) - > specificity > node - > specificity ) {
/* insert at head */
node - > alt_char = ( * parent_ptr ) ;
* parent_ptr = node ;
} else {
lcurr = * parent_ptr ;
for ( curr = ( * parent_ptr ) - > alt_char ; curr ; curr = curr - > alt_char ) {
for ( curr = ( * parent_ptr ) - > alt_char ; curr ; curr = curr - > alt_char ) {
if ( curr - > specificity > node - > specificity ) {
node - > alt_char = curr ;
lcurr - > alt_char = node ;
@ -1819,8 +1826,9 @@ static struct match_char *add_pattern_node(struct ast_context *con, struct match
{
struct match_char * m ;
if ( ! ( m = ast_calloc ( 1 , sizeof ( * m ) ) ) )
if ( ! ( m = ast_calloc ( 1 , sizeof ( * m ) ) ) ) {
return NULL ;
}
if ( ! ( m - > x = ast_strdup ( pattern ) ) ) {
ast_free ( m ) ;
@ -1871,14 +1879,14 @@ static struct match_char *add_exten_to_pattern_tree(struct ast_context *con, str
ast_copy_string ( extenbuf , e1 - > exten , sizeof ( extenbuf ) ) ;
if ( e1 - > matchcid & & l1 < = sizeof ( extenbuf ) ) {
strcat ( extenbuf , " / " ) ;
strcat ( extenbuf , e1 - > cidmatch ) ;
strcat ( extenbuf , " / " ) ;
strcat ( extenbuf , e1 - > cidmatch ) ;
} else if ( l1 > sizeof ( extenbuf ) ) {
ast_log ( LOG_ERROR , " The pattern %s/%s is too big to deal with: it will be ignored! Disaster! \n " , e1 - > exten , e1 - > cidmatch ) ;
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 0 ;
}
# ifdef NEED_DEBUG
ast_log ( LOG_DEBUG , " Adding exten %s%c%s to tree \n " , s1 , e1 - > matchcid ? ' / ' : ' ' , e1 - > matchcid ? e1 - > cidmatch : " " ) ;
ast_log ( LOG_DEBUG , " Adding exten %s%c%s to tree \n " , s1 , e1 - > matchcid ? ' / ' : ' ' , e1 - > matchcid ? e1 - > cidmatch : " " ) ;
# endif
m1 = con - > pattern_tree ; /* each pattern starts over at the root of the pattern tree */
m0 = & con - > pattern_tree ;
@ -1893,24 +1901,24 @@ static struct match_char *add_exten_to_pattern_tree(struct ast_context *con, str
char * s2 = buf ;
buf [ 0 ] = 0 ;
s1 + + ; /* get past the '[' */
while ( * s1 ! = ' ] ' & & * ( s1 - 1 ) ! = ' \\ ' ) {
while ( * s1 ! = ' ] ' & & * ( s1 - 1 ) ! = ' \\ ' ) {
if ( * s1 = = ' \\ ' ) {
if ( * ( s1 + 1 ) = = ' ] ' ) {
if ( * ( s1 + 1 ) = = ' ] ' ) {
* s2 + + = ' ] ' ;
s1 + + ; s1 + + ;
} else if ( * ( s1 + 1 ) = = ' \\ ' ) {
s1 + + ; s1 + + ;
} else if ( * ( s1 + 1 ) = = ' \\ ' ) {
* s2 + + = ' \\ ' ;
s1 + + ; s1 + + ;
} else if ( * ( s1 + 1 ) = = ' - ' ) {
s1 + + ; s1 + + ;
} else if ( * ( s1 + 1 ) = = ' - ' ) {
* s2 + + = ' - ' ;
s1 + + ; s1 + + ;
} else if ( * ( s1 + 1 ) = = ' [ ' ) {
} else if ( * ( s1 + 1 ) = = ' [ ' ) {
* s2 + + = ' [ ' ;
s1 + + ; s1 + + ;
}
} else if ( * s1 = = ' - ' ) { /* remember to add some error checking to all this! */
char s3 = * ( s1 - 1 ) ;
char s4 = * ( s1 + 1 ) ;
char s3 = * ( s1 - 1 ) ;
char s4 = * ( s1 + 1 ) ;
for ( s3 + + ; s3 < = s4 ; s3 + + ) {
* s2 + + = s3 ;
}
@ -1949,9 +1957,9 @@ static struct match_char *add_exten_to_pattern_tree(struct ast_context *con, str
specif = 1 ;
}
m2 = 0 ;
if ( already & & ( m2 = already_in_tree ( m1 , buf ) ) & & m2 - > next_char ) {
if ( ! ( * ( s1 + 1 ) ) ) { /* if this is the end of the pattern, but not the end of the tree, then mark this node with the exten...
a shorter pattern might win if the longer one doesn ' t match */
if ( already & & ( m2 = already_in_tree ( m1 , buf ) ) & & m2 - > next_char ) {
if ( ! ( * ( s1 + 1 ) ) ) { /* if this is the end of the pattern, but not the end of the tree, then mark this node with the exten...
* a shorter pattern might win if the longer one doesn ' t match */
m2 - > exten = e1 ;
m2 - > deleted = 0 ;
}
@ -1959,17 +1967,19 @@ static struct match_char *add_exten_to_pattern_tree(struct ast_context *con, str
m0 = & m2 - > next_char ; /* m0 points to the ptr that points to m1 */
} else { /* not already OR not m2 OR nor m2->next_char */
if ( m2 ) {
if ( findonly )
if ( findonly ) {
return m2 ;
}
m1 = m2 ; /* while m0 stays the same */
} else {
if ( findonly )
if ( findonly ) {
return m1 ;
}
m1 = add_pattern_node ( con , m1 , buf , pattern , already , specif , m0 ) ; /* m1 is the node just added */
m0 = & m1 - > next_char ;
}
if ( ! ( * ( s1 + 1 ) ) ) {
if ( ! ( * ( s1 + 1 ) ) ) {
m1 - > deleted = 0 ;
m1 - > exten = e1 ;
}
@ -1994,11 +2004,12 @@ static void create_match_char_tree(struct ast_context *con)
numobjs , numbucks , biggest_bucket , resizes ) ;
# endif
t1 = ast_hashtab_start_traversal ( con - > root_table ) ;
while ( ( e1 = ast_hashtab_next ( t1 ) ) ) {
if ( e1 - > exten )
while ( ( e1 = ast_hashtab_next ( t1 ) ) ) {
if ( e1 - > exten ) {
add_exten_to_pattern_tree ( con , e1 , 0 ) ;
else
ast_log ( LOG_ERROR , " Attempt to create extension with no extension name. \n " ) ;
} else {
ast_log ( LOG_ERROR , " Attempt to create extension with no extension name. \n " ) ;
}
}
ast_hashtab_end_traversal ( t1 ) ;
}
@ -2016,8 +2027,9 @@ static void destroy_pattern_tree(struct match_char *pattern_tree) /* pattern tre
pattern_tree - > next_char = 0 ;
}
pattern_tree - > exten = 0 ; /* never hurts to make sure there's no pointers laying around */
if ( pattern_tree - > x )
if ( pattern_tree - > x ) {
free ( pattern_tree - > x ) ;
}
free ( pattern_tree ) ;
}
@ -2062,12 +2074,12 @@ static void destroy_pattern_tree(struct match_char *pattern_tree) /* pattern tre
* This way more specific patterns ( smaller cardinality ) appear first .
* Wildcards have a special value , so that we can directly compare them to
* sets by subtracting the two values . In particular :
* 0x000 xx one character , xx
* 0x0 yyxx yy character set starting with xx
* 0x10000 ' . ' ( one or more of anything )
* 0x20000 ' ! ' ( zero or more of anything )
* 0x30000 NUL ( end of string )
* 0x40000 error in set .
* 0x000 xx one character , xx
* 0x0 yyxx yy character set starting with xx
* 0x10000 ' . ' ( one or more of anything )
* 0x20000 ' ! ' ( zero or more of anything )
* 0x30000 NUL ( end of string )
* 0x40000 error in set .
* The pointer to the string is advanced according to needs .
* NOTES :
* 1. the empty set is equivalent to NUL .
@ -2296,12 +2308,12 @@ static int _extension_match_core(const char *pattern, const char *data, enum ext
break ;
case ' . ' : /* Must match, even with more digits */
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (1) when '.' is matched \n " ) ;
ast_log ( LOG_NOTICE , " return (1) when '.' is matched \n " ) ;
# endif
return 1 ;
case ' ! ' : /* Early match */
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (2) when '!' is matched \n " ) ;
ast_log ( LOG_NOTICE , " return (2) when '!' is matched \n " ) ;
# endif
return 2 ;
case ' ' :
@ -2311,18 +2323,17 @@ static int _extension_match_core(const char *pattern, const char *data, enum ext
default :
if ( * data ! = * pattern ) {
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (0) when *data(%c) != *pattern(%c) \n " , * data , * pattern ) ;
ast_log ( LOG_NOTICE , " return (0) when *data(%c) != *pattern(%c) \n " , * data , * pattern ) ;
# endif
return 0 ;
}
}
data + + ;
pattern + + ;
}
if ( * data ) /* data longer than pattern, no match */ {
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " return (0) when data longer than pattern \n " ) ;
ast_log ( LOG_NOTICE , " return (0) when data longer than pattern \n " ) ;
# endif
return 0 ;
}
@ -2333,17 +2344,17 @@ static int _extension_match_core(const char *pattern, const char *data, enum ext
*/
if ( * pattern = = ' \0 ' | | * pattern = = ' / ' ) { /* exact match */
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " at end, return (%d) in 'exact match' \n " , ( mode = = E_MATCHMORE ) ? 0 : 1 ) ;
ast_log ( LOG_NOTICE , " at end, return (%d) in 'exact match' \n " , ( mode = = E_MATCHMORE ) ? 0 : 1 ) ;
# endif
return ( mode = = E_MATCHMORE ) ? 0 : 1 ; /* this is a failure for E_MATCHMORE */
} else if ( * pattern = = ' ! ' ) { /* early match */
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " at end, return (2) when '!' is matched \n " ) ;
ast_log ( LOG_NOTICE , " at end, return (2) when '!' is matched \n " ) ;
# endif
return 2 ;
} else { /* partial match */
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " at end, return (%d) which deps on E_MATCH \n " , ( mode = = E_MATCH ) ? 0 : 1 ) ;
ast_log ( LOG_NOTICE , " at end, return (%d) which deps on E_MATCH \n " , ( mode = = E_MATCH ) ? 0 : 1 ) ;
# endif
return ( mode = = E_MATCH ) ? 0 : 1 ; /* this is a failure for E_MATCH */
}
@ -2357,8 +2368,9 @@ static int extension_match_core(const char *pattern, const char *data, enum ext_
{
int i ;
static int prof_id = - 2 ; /* marker for 'unallocated' id */
if ( prof_id = = - 2 )
if ( prof_id = = - 2 ) {
prof_id = ast_add_profile ( " ext_match " , 0 ) ;
}
ast_mark ( prof_id , 1 ) ;
i = _extension_match_core ( pattern , data , mode ) ;
ast_mark ( prof_id , 0 ) ;
@ -2405,8 +2417,9 @@ struct ast_context *ast_context_find(const char *name)
tmp = ast_hashtab_lookup ( contexts_table , & item ) ;
} else {
while ( ( tmp = ast_walk_contexts ( tmp ) ) ) {
if ( ! name | | ! strcasecmp ( name , tmp - > name ) )
if ( ! name | | ! strcasecmp ( name , tmp - > name ) ) {
break ;
}
}
}
ast_unlock_contexts ( ) ;
@ -2424,8 +2437,9 @@ 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 */
if ( ast_strlen_zero ( callerid ) )
if ( ast_strlen_zero ( callerid ) ) {
return ast_strlen_zero ( cidpattern ) ? 1 : 0 ;
}
return ast_extension_match ( cidpattern , callerid ) ;
}
@ -2447,7 +2461,7 @@ struct ast_exten *pbx_find_extension(struct ast_channel *chan,
pattern . label = label ;
pattern . priority = priority ;
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d \n " , context , exten , priority , label , ( int ) action ) ;
ast_log ( LOG_NOTICE , " Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d \n " , context , exten , priority , label , ( int ) action ) ;
# endif
/* Initialize status if appropriate */
@ -2467,9 +2481,9 @@ struct ast_exten *pbx_find_extension(struct ast_channel *chan,
return NULL ;
}
if ( bypass ) /* bypass means we only look there */
if ( bypass ) { /* bypass means we only look there */
tmp = bypass ;
else { /* look in contexts */
} else { /* look in contexts */
struct fake_context item ;
ast_copy_string ( item . name , context , sizeof ( item . name ) ) ;
@ -2478,13 +2492,14 @@ struct ast_exten *pbx_find_extension(struct ast_channel *chan,
# ifdef NOTNOW
tmp = NULL ;
while ( ( tmp = ast_walk_contexts ( tmp ) ) ) {
if ( ! strcmp ( tmp - > name , context ) )
if ( ! strcmp ( tmp - > name , context ) ) {
break ;
}
}
# endif
if ( ! tmp )
if ( ! tmp ) {
return NULL ;
}
}
if ( q - > status < STATUS_NO_EXTENSION )
@ -2496,16 +2511,15 @@ struct ast_exten *pbx_find_extension(struct ast_channel *chan,
score . total_specificity = 0 ;
score . exten = 0 ;
score . total_length = 0 ;
if ( ! tmp - > pattern_tree & & tmp - > root_table )
{
if ( ! tmp - > pattern_tree & & tmp - > root_table ) {
create_match_char_tree ( tmp ) ;
# ifdef NEED_DEBUG
ast_log ( LOG_DEBUG , " Tree Created in context %s: \n " , context ) ;
ast_log ( LOG_DEBUG , " Tree Created in context %s: \n " , context ) ;
log_match_char_tree ( tmp - > pattern_tree , " " ) ;
# endif
}
# ifdef NEED_DEBUG
ast_log ( LOG_NOTICE , " The Trie we are searching in: \n " ) ;
ast_log ( LOG_NOTICE , " The Trie we are searching in: \n " ) ;
log_match_char_tree ( tmp - > pattern_tree , " :: " ) ;
# endif
@ -2612,7 +2626,7 @@ struct ast_exten *pbx_find_extension(struct ast_channel *chan,
return z ;
}
# ifdef NEED_DEBUG_HERE
ast_log ( LOG_NOTICE , " Returning CANMATCH/MATCHMORE NULL (no next_match) \n " ) ;
ast_log ( LOG_NOTICE , " Returning CANMATCH/MATCHMORE NULL (no next_match) \n " ) ;
# endif
return NULL ; /* according to the code, complete matches are null matches in MATCHMORE mode */
}
@ -2686,7 +2700,6 @@ struct ast_exten *pbx_find_extension(struct ast_channel *chan,
}
}
/* Check alternative switches */
AST_LIST_TRAVERSE ( & tmp - > alts , sw , list ) {
struct ast_switch * asw = pbx_findswitch ( sw - > name ) ;
@ -2697,8 +2710,8 @@ struct ast_exten *pbx_find_extension(struct ast_channel *chan,
ast_log ( LOG_WARNING , " No such switch '%s' \n " , sw - > name ) ;
continue ;
}
/* Substitute variables now */
/* Substitute variables now */
if ( sw - > eval ) {
if ( ! ( tmpdata = ast_str_thread_get ( & switch_data , 512 ) ) ) {
ast_log ( LOG_WARNING , " Can't evaluate switch?! " ) ;
@ -3148,7 +3161,7 @@ static char *handle_show_function(struct ast_cli_entry *e, int cmd, struct ast_c
term_color ( seealso , S_OR ( acf - > seealso , " Not available " ) , COLOR_CYAN , 0 , seealso_size ) ;
}
ast_cli ( a - > fd , " %s%s%s \n \n %s%s \n \n %s%s \n \n %s%s \n \n %s%s \n " ,
ast_cli ( a - > fd , " %s%s%s \n \n %s%s \n \n %s%s \n \n %s%s \n \n %s%s \n " ,
infotitle , syntitle , synopsis , destitle , description ,
stxtitle , syntax , argtitle , arguments , seealsotitle , seealso ) ;
@ -3179,8 +3192,9 @@ int ast_custom_function_unregister(struct ast_custom_function *acf)
{
struct ast_custom_function * cur ;
if ( ! acf )
if ( ! acf ) {
return - 1 ;
}
AST_RWLIST_WRLOCK ( & acf_root ) ;
if ( ( cur = AST_RWLIST_REMOVE ( & acf_root , acf , acflist ) ) ) {
@ -3300,15 +3314,16 @@ static char *func_args(char *function)
{
char * args = strchr ( function , ' ( ' ) ;
if ( ! args )
if ( ! args ) {
ast_log ( LOG_WARNING , " Function doesn't contain parentheses. Assuming null argument. \n " ) ;
else {
} else {
char * p ;
* args + + = ' \0 ' ;
if ( ( p = strrchr ( args , ' ) ' ) ) )
if ( ( p = strrchr ( args , ' ) ' ) ) ) {
* p = ' \0 ' ;
else
} else {
ast_log ( LOG_WARNING , " Can't find trailing parenthesis? \n " ) ;
}
}
return args ;
}
@ -3785,11 +3800,11 @@ int ast_extension_state(struct ast_channel *c, const char *context, const char *
{
struct ast_exten * e ;
e = ast_hint_extension ( c , context , exten ) ; /* Do we have a hint for this extension ? */
if ( ! e )
return - 1 ; /* No hint, return -1 */
if ( ! ( e = ast_hint_extension ( c , context , exten ) )) { /* Do we have a hint for this extension ? */
return - 1 ; /* No hint, return -1 */
}
return ast_extension_state2 ( e ) ; /* Check all devices in the hint */
return ast_extension_state2 ( e ) ; /* Check all devices in the hint */
}
static int handle_statechange ( void * datap )
@ -3809,17 +3824,20 @@ static int handle_statechange(void *datap)
ast_copy_string ( buf , ast_get_extension_app ( hint - > exten ) , sizeof ( buf ) ) ;
while ( ( cur = strsep ( & parse , " & " ) ) ) {
if ( ! strcasecmp ( cur , sc - > dev ) )
if ( ! strcasecmp ( cur , sc - > dev ) ) {
break ;
}
}
if ( ! cur )
if ( ! cur ) {
continue ;
}
/* Get device state for this hint */
state = ast_extension_state2 ( hint - > exten ) ;
if ( ( state = = - 1 ) | | ( state = = hint - > laststate ) )
if ( ( state = = - 1 ) | | ( state = = hint - > laststate ) ) {
continue ;
}
/* Device state changed since last check - notify the watchers */
@ -3944,7 +3962,7 @@ int ast_extension_state_del(int id, ast_state_cb_type callback)
if ( ! id ) { /* id == 0 is a callback without extension */
AST_LIST_TRAVERSE_SAFE_BEGIN ( & statecbs , p_cur , entry ) {
if ( p_cur - > callback = = callback ) {
if ( p_cur - > callback = = callback ) {
AST_LIST_REMOVE_CURRENT ( entry ) ;
break ;
}
@ -4026,7 +4044,7 @@ static int ast_change_hint(struct ast_exten *oe, struct ast_exten *ne)
AST_RWLIST_WRLOCK ( & hints ) ;
AST_RWLIST_TRAVERSE ( & hints , hint , list ) {
if ( hint - > exten = = oe ) {
hint - > exten = ne ;
hint - > exten = ne ;
res = 0 ;
break ;
}
@ -4061,7 +4079,7 @@ static int ast_remove_hint(struct ast_exten *e)
AST_RWLIST_REMOVE_CURRENT ( list ) ;
ast_free ( hint ) ;
res = 0 ;
res = 0 ;
break ;
}
@ -4441,7 +4459,7 @@ static int increase_call_count(const struct ast_channel *c)
/* make sure that the free system memory is above the configured low watermark
* convert the amount of freeram from mem_units to MB */
curfreemem = sys_info . freeram / sys_info . mem_unit ;
curfreemem / = 1024 * 1024 ;
curfreemem / = 1024 * 1024 ;
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 ;
@ -4805,7 +4823,6 @@ int ast_context_remove_extension_callerid2(struct ast_context *con, const char *
if ( ! exten2 )
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 ) ;
if ( con - > pattern_tree ) {
struct match_char * x = add_exten_to_pattern_tree ( con , exten , 1 ) ;
if ( x - > exten ) { /* this test for safety purposes */
@ -4959,8 +4976,9 @@ int ast_context_lockmacro(const char *context)
ast_unlock_contexts ( ) ;
/* if we found context, lock macrolock */
if ( ret = = 0 )
if ( ret = = 0 ) {
ret = ast_mutex_lock ( & c - > macrolock ) ;
}
return ret ;
}
@ -4996,8 +5014,9 @@ int ast_context_unlockmacro(const char *context)
ast_unlock_contexts ( ) ;
/* if we found context, unlock macrolock */
if ( ret = = 0 )
if ( ret = = 0 ) {
ret = ast_mutex_unlock ( & c - > macrolock ) ;
}
return ret ;
}
@ -5425,8 +5444,8 @@ static char *handle_show_applications(struct ast_cli_entry *e, int cmd, struct a
{
struct ast_app * aa ;
int like = 0 , describing = 0 ;
int total_match = 0 ; /* Number of matches in like clause */
int total_apps = 0 ; /* Number of apps registered */
int total_match = 0 ; /* Number of matches in like clause */
int total_apps = 0 ; /* Number of apps registered */
static char * choices [ ] = { " like " , " describing " , NULL } ;
switch ( cmd ) {
@ -7455,7 +7474,7 @@ static int add_pri_lockopt(struct ast_context *con, struct ast_exten *tmp,
ast_hashtab_remove_object_via_lookup ( con - > root_table , e ) ;
ast_hashtab_insert_safe ( con - > root_table , tmp ) ;
con - > root = tmp ;
con - > root = tmp ;
/* The pattern trie points to this exten; replace the pointer,
and all will be well */
if ( x ) { /* if the trie isn't formed yet; no problem */