@ -102,45 +102,46 @@ AST_APP_OPTIONS(waitexten_opts, {
struct ast_context ;
struct ast_context ;
/*!\brief ast_exten: An extension
/*!
\ brief ast_exten : An extension
The dialplan is saved as a linked list with each context
The dialplan is saved as a linked list with each context
having it ' s own linked list of extensions - one item per
having it ' s own linked list of extensions - one item per
priority .
priority .
*/
*/
struct ast_exten {
struct ast_exten {
char * exten ; /* Extension name */
char * exten ; /* !< Extension name */
int matchcid ; /* Match caller id ? */
int matchcid ; /* !< Match caller id ? */
char * cidmatch ; /* Caller id to match for this extension */
char * cidmatch ; /* !< Caller id to match for this extension */
int priority ; /* Priority */
int priority ; /* !< Priority */
char * label ; /* Label */
char * label ; /* !< Label */
struct ast_context * parent ; /* The context this extension belongs to */
struct ast_context * parent ; /* !< The context this extension belongs to */
char * app ; /* Application to execute */
char * app ; /* !< Application to execute */
void * data ; /* Data to use (arguments) */
void * data ; /* !< Data to use (arguments) */
void ( * datad ) ( void * ) ; /* Data destructor */
void ( * datad ) ( void * ) ; /* !< Data destructor */
struct ast_exten * peer ; /* Next higher priority with our extension */
struct ast_exten * peer ; /* !< Next higher priority with our extension */
const char * registrar ; /* Registrar */
const char * registrar ; /* !< Registrar */
struct ast_exten * next ; /* Extension with a greater ID */
struct ast_exten * next ; /* !< Extension with a greater ID */
char stuff [ 0 ] ;
char stuff [ 0 ] ;
} ;
} ;
/*! \brief ast_include: include= support in extensions.conf */
/*! \brief ast_include: include= support in extensions.conf */
struct ast_include {
struct ast_include {
char * name ;
char * name ;
char * rname ; /* Context to include */
char * rname ; /* !< Context to include */
const char * registrar ; /* Registrar */
const char * registrar ; /* !< Registrar */
int hastime ; /* If time construct exists */
int hastime ; /* !< If time construct exists */
struct ast_timing timing ; /* time construct */
struct ast_timing timing ; /* !< time construct */
struct ast_include * next ; /* Link them together */
struct ast_include * next ; /* !< Link them together */
char stuff [ 0 ] ;
char stuff [ 0 ] ;
} ;
} ;
/*! \brief ast_sw: Switch statement in extensions.conf */
/*! \brief ast_sw: Switch statement in extensions.conf */
struct ast_sw {
struct ast_sw {
char * name ;
char * name ;
const char * registrar ; /* Registrar */
const char * registrar ; /* !< Registrar */
char * data ; /* Data load */
char * data ; /* !< Data load */
int eval ;
int eval ;
struct ast_sw * next ; /* Link them together */
struct ast_sw * next ; /* !< Link them together */
char * tmpdata ;
char * tmpdata ;
char stuff [ 0 ] ;
char stuff [ 0 ] ;
} ;
} ;
@ -168,10 +169,10 @@ struct ast_context {
/*! \brief ast_app: A registered application */
/*! \brief ast_app: A registered application */
struct ast_app {
struct ast_app {
int ( * execute ) ( struct ast_channel * chan , void * data ) ;
int ( * execute ) ( struct ast_channel * chan , void * data ) ;
const char * synopsis ; /* Synopsis text for 'show applications' */
const char * synopsis ; /* !< Synopsis text for 'show applications' */
const char * description ; /* Description (help text) for 'show application <name>' */
const char * description ; /* !< Description (help text) for 'show application <name>' */
struct ast_app * next ; /* Next app in list */
struct ast_app * next ; /* !< Next app in list */
char name [ 0 ] ; /* Name of the application */
char name [ 0 ] ; /* !< Name of the application */
} ;
} ;
/*! \brief ast_state_cb: An extension state notify register item */
/*! \brief ast_state_cb: An extension state notify register item */
@ -443,14 +444,14 @@ static struct pbx_builtin {
} ;
} ;
static struct ast_context * contexts = NULL ;
static struct ast_context * contexts = NULL ;
AST_MUTEX_DEFINE_STATIC ( conlock ) ; /* Lock for the ast_context list */
AST_MUTEX_DEFINE_STATIC ( conlock ) ; /* !< Lock for the ast_context list */
static struct ast_app * apps = NULL ;
static struct ast_app * apps = NULL ;
AST_MUTEX_DEFINE_STATIC ( applock ) ; /* Lock for the application list */
AST_MUTEX_DEFINE_STATIC ( applock ) ; /* !< Lock for the application list */
struct ast_switch * switches = NULL ;
struct ast_switch * switches = NULL ;
AST_MUTEX_DEFINE_STATIC ( switchlock ) ; /* Lock for switches */
AST_MUTEX_DEFINE_STATIC ( switchlock ) ; /* !< Lock for switches */
AST_MUTEX_DEFINE_STATIC ( hintlock ) ; /* Lock for extension state notifys */
AST_MUTEX_DEFINE_STATIC ( hintlock ) ; /* !< Lock for extension state notifys */
static int stateid = 1 ;
static int stateid = 1 ;
struct ast_hint * hints = NULL ;
struct ast_hint * hints = NULL ;
struct ast_state_cb * statecbs = NULL ;
struct ast_state_cb * statecbs = NULL ;
@ -511,11 +512,9 @@ struct ast_app *pbx_findapp(const char *app)
ast_log ( LOG_WARNING , " Unable to obtain application lock \n " ) ;
ast_log ( LOG_WARNING , " Unable to obtain application lock \n " ) ;
return NULL ;
return NULL ;
}
}
tmp = apps ;
for ( tmp = apps ; tmp ; tmp = tmp - > next ) {
while ( tmp ) {
if ( ! strcasecmp ( tmp - > name , app ) )
if ( ! strcasecmp ( tmp - > name , app ) )
break ;
break ;
tmp = tmp - > next ;
}
}
ast_mutex_unlock ( & applock ) ;
ast_mutex_unlock ( & applock ) ;
return tmp ;
return tmp ;
@ -529,11 +528,9 @@ static struct ast_switch *pbx_findswitch(const char *sw)
ast_log ( LOG_WARNING , " Unable to obtain application lock \n " ) ;
ast_log ( LOG_WARNING , " Unable to obtain application lock \n " ) ;
return NULL ;
return NULL ;
}
}
asw = switches ;
for ( asw = switches ; asw ; asw = asw - > next ) {
while ( asw ) {
if ( ! strcasecmp ( asw - > name , sw ) )
if ( ! strcasecmp ( asw - > name , sw ) )
break ;
break ;
asw = asw - > next ;
}
}
ast_mutex_unlock ( & switchlock ) ;
ast_mutex_unlock ( & switchlock ) ;
return asw ;
return asw ;
@ -668,11 +665,9 @@ struct ast_context *ast_context_find(const char *name)
struct ast_context * tmp ;
struct ast_context * tmp ;
ast_mutex_lock ( & conlock ) ;
ast_mutex_lock ( & conlock ) ;
if ( name ) {
if ( name ) {
tmp = contexts ;
for ( tmp = contexts ; tmp ; tmp = tmp - > next ) {
while ( tmp ) {
if ( ! strcasecmp ( name , tmp - > name ) )
if ( ! strcasecmp ( name , tmp - > name ) )
break ;
break ;
tmp = tmp - > next ;
}
}
} else
} else
tmp = contexts ;
tmp = contexts ;
@ -733,7 +728,7 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan, struct ast
tmp = bypass ;
tmp = bypass ;
else
else
tmp = contexts ;
tmp = contexts ;
while( tmp ) {
for ( ; tmp ; tmp = tmp - > next ) {
/* Match context */
/* Match context */
if ( bypass | | ! strcmp ( tmp - > name , context ) ) {
if ( bypass | | ! strcmp ( tmp - > name , context ) ) {
struct ast_exten * earlymatch = NULL ;
struct ast_exten * earlymatch = NULL ;
@ -753,10 +748,9 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan, struct ast
So ignore it for now , unless there ' s a better match */
So ignore it for now , unless there ' s a better match */
earlymatch = eroot ;
earlymatch = eroot ;
} else {
} else {
e = eroot ;
if ( * status < STATUS_NO_PRIORITY )
if ( * status < STATUS_NO_PRIORITY )
* status = STATUS_NO_PRIORITY ;
* status = STATUS_NO_PRIORITY ;
while( e ) {
for ( e = eroot ; e ; e = e - > peer ) {
/* Match priority */
/* Match priority */
if ( action = = HELPER_FINDLABEL ) {
if ( action = = HELPER_FINDLABEL ) {
if ( * status < STATUS_NO_LABEL )
if ( * status < STATUS_NO_LABEL )
@ -771,7 +765,6 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan, struct ast
* foundcontext = context ;
* foundcontext = context ;
return e ;
return e ;
}
}
e = e - > peer ;
}
}
}
}
}
}
@ -784,8 +777,7 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan, struct ast
return NULL ;
return NULL ;
}
}
/* Check alternative switches */
/* Check alternative switches */
sw = tmp - > alts ;
for ( sw = tmp - > alts ; sw ; sw = sw - > next ) {
while ( sw ) {
if ( ( asw = pbx_findswitch ( sw - > name ) ) ) {
if ( ( asw = pbx_findswitch ( sw - > name ) ) ) {
/* Substitute variables now */
/* Substitute variables now */
if ( sw - > eval )
if ( sw - > eval )
@ -806,25 +798,21 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan, struct ast
} else {
} else {
ast_log ( LOG_WARNING , " No such switch '%s' \n " , sw - > name ) ;
ast_log ( LOG_WARNING , " No such switch '%s' \n " , sw - > name ) ;
}
}
sw = sw - > next ;
}
}
/* Setup the stack */
/* Setup the stack */
incstack [ * stacklen ] = tmp - > name ;
incstack [ * stacklen ] = tmp - > name ;
( * stacklen ) + + ;
( * stacklen ) + + ;
/* Now try any includes we have in this context */
/* Now try any includes we have in this context */
i = tmp - > includes ;
for ( i = tmp - > includes ; i ; i = i - > next ) {
while ( i ) {
if ( include_valid ( i ) ) {
if ( include_valid ( i ) ) {
if ( ( e = pbx_find_extension ( chan , bypass , i - > rname , exten , priority , label , callerid , action , incstack , stacklen , status , swo , data , foundcontext ) ) )
if ( ( e = pbx_find_extension ( chan , bypass , i - > rname , exten , priority , label , callerid , action , incstack , stacklen , status , swo , data , foundcontext ) ) )
return e ;
return e ;
if ( * swo )
if ( * swo )
return NULL ;
return NULL ;
}
}
i = i - > next ;
}
}
break ;
break ;
}
}
tmp = tmp - > next ;
}
}
return NULL ;
return NULL ;
}
}
@ -1194,6 +1182,9 @@ static char *complete_show_function(char *line, char *word, int pos, int state)
{
{
struct ast_custom_function * acf ;
struct ast_custom_function * acf ;
int which = 0 ;
int which = 0 ;
int wordlen ;
wordlen = strlen ( word ) ;
/* try to lock functions list ... */
/* try to lock functions list ... */
if ( ast_mutex_lock ( & acflock ) ) {
if ( ast_mutex_lock ( & acflock ) ) {
@ -1201,23 +1192,21 @@ static char *complete_show_function(char *line, char *word, int pos, int state)
return NULL ;
return NULL ;
}
}
acf = acf_root ;
for ( acf = acf_root ; acf ; acf = acf - > next ) {
while ( acf ) {
if ( ! strncasecmp ( word , acf - > name , wordlen ) ) {
if ( ! strncasecmp ( word , acf - > name , strlen ( word ) ) ) {
if ( + + which > state ) {
if ( + + which > state ) {
char * ret = strdup ( acf - > name ) ;
char * ret = strdup ( acf - > name ) ;
ast_mutex_unlock ( & acflock ) ;
ast_mutex_unlock ( & acflock ) ;
return ret ;
return ret ;
}
}
}
}
acf = acf - > next ;
}
}
ast_mutex_unlock ( & acflock ) ;
ast_mutex_unlock ( & acflock ) ;
return NULL ;
return NULL ;
}
}
struct ast_custom_function * ast_custom_function_find ( char * name )
struct ast_custom_function * ast_custom_function_find ( const char * name )
{
{
struct ast_custom_function * acfptr ;
struct ast_custom_function * acfptr ;
@ -1677,7 +1666,8 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
return - 1 ;
return - 1 ;
}
}
default :
default :
ast_log ( LOG_WARNING , " Huh (%d)? \n " , action ) ; return - 1 ;
ast_log ( LOG_WARNING , " Huh (%d)? \n " , action ) ;
return - 1 ;
}
}
} else if ( sw ) {
} else if ( sw ) {
switch ( action ) {
switch ( action ) {
@ -1913,23 +1903,20 @@ int ast_extension_state_add(const char *context, const char *exten,
if ( ! context & & ! exten ) {
if ( ! context & & ! exten ) {
ast_mutex_lock ( & hintlock ) ;
ast_mutex_lock ( & hintlock ) ;
cblist = statecbs ;
for ( cblist = statecbs ; cblist ; cblist = cblist - > next ) {
while ( cblist ) {
if ( cblist - > callback = = callback ) {
if ( cblist - > callback = = callback ) {
cblist - > data = data ;
cblist - > data = data ;
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
return 0 ;
return 0 ;
}
}
cblist = cblist - > next ;
}
}
/* Now insert the callback */
/* Now insert the callback */
cblist = malloc( sizeof ( struct ast_state_cb ) ) ;
cblist = calloc( 1 , sizeof ( struct ast_state_cb ) ) ;
if ( ! cblist ) {
if ( ! cblist ) {
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
return - 1 ;
return - 1 ;
}
}
memset ( cblist , 0 , sizeof ( struct ast_state_cb ) ) ;
cblist - > id = 0 ;
cblist - > id = 0 ;
cblist - > callback = callback ;
cblist - > callback = callback ;
cblist - > data = data ;
cblist - > data = data ;
@ -1952,12 +1939,10 @@ int ast_extension_state_add(const char *context, const char *exten,
/* Find the hint in the list of hints */
/* Find the hint in the list of hints */
ast_mutex_lock ( & hintlock ) ;
ast_mutex_lock ( & hintlock ) ;
list = hints ;
while ( lis t) {
for ( list = hints ; list ; list = list - > nex t) {
if ( list - > exten = = e )
if ( list - > exten = = e )
break ;
break ;
list = list - > next ;
}
}
if ( ! list ) {
if ( ! list ) {
@ -1967,12 +1952,11 @@ int ast_extension_state_add(const char *context, const char *exten,
}
}
/* Now insert the callback in the callback list */
/* Now insert the callback in the callback list */
cblist = malloc( sizeof ( struct ast_state_cb ) ) ;
cblist = calloc( 1 , sizeof ( struct ast_state_cb ) ) ;
if ( ! cblist ) {
if ( ! cblist ) {
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
return - 1 ;
return - 1 ;
}
}
memset ( cblist , 0 , sizeof ( struct ast_state_cb ) ) ;
cblist - > id = stateid + + ; /* Unique ID for this callback */
cblist - > id = stateid + + ; /* Unique ID for this callback */
cblist - > callback = callback ; /* Pointer to callback routine */
cblist - > callback = callback ; /* Pointer to callback routine */
cblist - > data = data ; /* Data for the callback */
cblist - > data = data ; /* Data for the callback */
@ -1998,8 +1982,7 @@ int ast_extension_state_del(int id, ast_state_cb_type callback)
/* id is zero is a callback without extension */
/* id is zero is a callback without extension */
if ( ! id ) {
if ( ! id ) {
cbprev = NULL ;
cbprev = NULL ;
cblist = statecbs ;
for ( cblist = statecbs ; cblist ; cblist = cblist - > next ) {
while ( cblist ) {
if ( cblist - > callback = = callback ) {
if ( cblist - > callback = = callback ) {
if ( ! cbprev )
if ( ! cbprev )
statecbs = cblist - > next ;
statecbs = cblist - > next ;
@ -2012,7 +1995,6 @@ int ast_extension_state_del(int id, ast_state_cb_type callback)
return 0 ;
return 0 ;
}
}
cbprev = cblist ;
cbprev = cblist ;
cblist = cblist - > next ;
}
}
ast_mutex_lock ( & hintlock ) ;
ast_mutex_lock ( & hintlock ) ;
@ -2021,11 +2003,9 @@ int ast_extension_state_del(int id, ast_state_cb_type callback)
/* id greater than zero is a callback with extension */
/* id greater than zero is a callback with extension */
/* Find the callback based on ID */
/* Find the callback based on ID */
list = hints ;
for ( list = hints ; list ; list = list - > next ) {
while ( list ) {
cblist = list - > callbacks ;
cbprev = NULL ;
cbprev = NULL ;
while ( cblis t) {
for ( cblist = list - > callbacks ; cblist ; cblist = cblist - > next ) {
if ( cblist - > id = = id ) {
if ( cblist - > id = = id ) {
if ( ! cbprev )
if ( ! cbprev )
list - > callbacks = cblist - > next ;
list - > callbacks = cblist - > next ;
@ -2038,9 +2018,7 @@ int ast_extension_state_del(int id, ast_state_cb_type callback)
return 0 ;
return 0 ;
}
}
cbprev = cblist ;
cbprev = cblist ;
cblist = cblist - > next ;
}
}
list = list - > next ;
}
}
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
@ -2056,23 +2034,21 @@ static int ast_add_hint(struct ast_exten *e)
return - 1 ;
return - 1 ;
ast_mutex_lock ( & hintlock ) ;
ast_mutex_lock ( & hintlock ) ;
list = hints ;
/* Search if hint exists, do nothing */
/* Search if hint exists, do nothing */
while ( lis t) {
for ( list = hints ; list ; list = list - > nex t) {
if ( list - > exten = = e ) {
if ( list - > exten = = e ) {
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
if ( option_debug > 1 )
if ( option_debug > 1 )
ast_log ( LOG_DEBUG , " HINTS: Not re-adding existing hint %s: %s \n " , ast_get_extension_name ( e ) , ast_get_extension_app ( e ) ) ;
ast_log ( LOG_DEBUG , " HINTS: Not re-adding existing hint %s: %s \n " , ast_get_extension_name ( e ) , ast_get_extension_app ( e ) ) ;
return - 1 ;
return - 1 ;
}
}
list = list - > next ;
}
}
if ( option_debug > 1 )
if ( option_debug > 1 )
ast_log ( LOG_DEBUG , " HINTS: Adding hint %s: %s \n " , ast_get_extension_name ( e ) , ast_get_extension_app ( e ) ) ;
ast_log ( LOG_DEBUG , " HINTS: Adding hint %s: %s \n " , ast_get_extension_name ( e ) , ast_get_extension_app ( e ) ) ;
list = malloc( sizeof ( struct ast_hint ) ) ;
list = calloc( 1 , sizeof ( struct ast_hint ) ) ;
if ( ! list ) {
if ( ! list ) {
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
if ( option_debug > 1 )
if ( option_debug > 1 )
@ -2080,7 +2056,6 @@ static int ast_add_hint(struct ast_exten *e)
return - 1 ;
return - 1 ;
}
}
/* Initialize and insert new item at the top */
/* Initialize and insert new item at the top */
memset ( list , 0 , sizeof ( struct ast_hint ) ) ;
list - > exten = e ;
list - > exten = e ;
list - > laststate = ast_extension_state2 ( e ) ;
list - > laststate = ast_extension_state2 ( e ) ;
list - > next = hints ;
list - > next = hints ;
@ -2096,16 +2071,15 @@ static int ast_change_hint(struct ast_exten *oe, struct ast_exten *ne)
struct ast_hint * list ;
struct ast_hint * list ;
ast_mutex_lock ( & hintlock ) ;
ast_mutex_lock ( & hintlock ) ;
list = hints ;
while( lis t) {
for ( list = hints ; list ; list = list - > nex t) {
if ( list - > exten = = oe ) {
if ( list - > exten = = oe ) {
list - > exten = ne ;
list - > exten = ne ;
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
return 0 ;
return 0 ;
}
}
list = list - > next ;
}
}
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
return - 1 ;
return - 1 ;
@ -2123,8 +2097,7 @@ static int ast_remove_hint(struct ast_exten *e)
ast_mutex_lock ( & hintlock ) ;
ast_mutex_lock ( & hintlock ) ;
list = hints ;
for ( list = hints ; list ; list = list - > next ) {
while ( list ) {
if ( list - > exten = = e ) {
if ( list - > exten = = e ) {
cbprev = NULL ;
cbprev = NULL ;
cblist = list - > callbacks ;
cblist = list - > callbacks ;
@ -2145,10 +2118,8 @@ static int ast_remove_hint(struct ast_exten *e)
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
return 0 ;
return 0 ;
} else {
prev = list ;
list = list - > next ;
}
}
prev = list ;
}
}
ast_mutex_unlock ( & hintlock ) ;
ast_mutex_unlock ( & hintlock ) ;
@ -2224,7 +2195,7 @@ static int __ast_pbx_run(struct ast_channel *c)
/* A little initial setup here */
/* A little initial setup here */
if ( c - > pbx )
if ( c - > pbx )
ast_log ( LOG_WARNING , " %s already has PBX structure?? \n " , c - > name ) ;
ast_log ( LOG_WARNING , " %s already has PBX structure?? \n " , c - > name ) ;
c - > pbx = malloc( sizeof ( struct ast_pbx ) ) ;
c - > pbx = calloc( 1 , sizeof ( struct ast_pbx ) ) ;
if ( ! c - > pbx ) {
if ( ! c - > pbx ) {
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
return - 1 ;
return - 1 ;
@ -2240,7 +2211,6 @@ static int __ast_pbx_run(struct ast_channel *c)
ast_cdr_init ( c - > cdr , c ) ;
ast_cdr_init ( c - > cdr , c ) ;
}
}
}
}
memset ( c - > pbx , 0 , sizeof ( struct ast_pbx ) ) ;
/* Set reasonable defaults */
/* Set reasonable defaults */
c - > pbx - > rtimeout = 10 ;
c - > pbx - > rtimeout = 10 ;
c - > pbx - > dtimeout = 5 ;
c - > pbx - > dtimeout = 5 ;
@ -2561,8 +2531,7 @@ int ast_context_remove_include(const char *context, const char *include, const c
if ( ast_lock_contexts ( ) ) return - 1 ;
if ( ast_lock_contexts ( ) ) return - 1 ;
/* walk contexts and search for the right one ...*/
/* walk contexts and search for the right one ...*/
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
/* we found one ... */
/* we found one ... */
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
int ret ;
int ret ;
@ -2574,7 +2543,6 @@ int ast_context_remove_include(const char *context, const char *include, const c
/* ... return results */
/* ... return results */
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
/* we can't find the right one context */
/* we can't find the right one context */
@ -2597,8 +2565,7 @@ int ast_context_remove_include2(struct ast_context *con, const char *include, co
if ( ast_mutex_lock ( & con - > lock ) ) return - 1 ;
if ( ast_mutex_lock ( & con - > lock ) ) return - 1 ;
/* walk includes */
/* walk includes */
i = con - > includes ;
for ( i = con - > includes ; i ; i = i - > next ) {
while ( i ) {
/* find our include */
/* find our include */
if ( ! strcmp ( i - > name , include ) & &
if ( ! strcmp ( i - > name , include ) & &
( ! registrar | | ! strcmp ( i - > registrar , registrar ) ) ) {
( ! registrar | | ! strcmp ( i - > registrar , registrar ) ) ) {
@ -2613,7 +2580,6 @@ int ast_context_remove_include2(struct ast_context *con, const char *include, co
return 0 ;
return 0 ;
}
}
pi = i ;
pi = i ;
i = i - > next ;
}
}
/* we can't find the right include */
/* we can't find the right include */
@ -2633,8 +2599,7 @@ int ast_context_remove_switch(const char *context, const char *sw, const char *d
if ( ast_lock_contexts ( ) ) return - 1 ;
if ( ast_lock_contexts ( ) ) return - 1 ;
/* walk contexts and search for the right one ...*/
/* walk contexts and search for the right one ...*/
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
/* we found one ... */
/* we found one ... */
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
int ret ;
int ret ;
@ -2646,7 +2611,6 @@ int ast_context_remove_switch(const char *context, const char *sw, const char *d
/* ... return results */
/* ... return results */
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
/* we can't find the right one context */
/* we can't find the right one context */
@ -2669,8 +2633,7 @@ int ast_context_remove_switch2(struct ast_context *con, const char *sw, const ch
if ( ast_mutex_lock ( & con - > lock ) ) return - 1 ;
if ( ast_mutex_lock ( & con - > lock ) ) return - 1 ;
/* walk switchs */
/* walk switchs */
i = con - > alts ;
for ( i = con - > alts ; i ; i = i - > next ) {
while ( i ) {
/* find our switch */
/* find our switch */
if ( ! strcmp ( i - > name , sw ) & & ! strcmp ( i - > data , data ) & &
if ( ! strcmp ( i - > name , sw ) & & ! strcmp ( i - > data , data ) & &
( ! registrar | | ! strcmp ( i - > registrar , registrar ) ) ) {
( ! registrar | | ! strcmp ( i - > registrar , registrar ) ) ) {
@ -2685,7 +2648,6 @@ int ast_context_remove_switch2(struct ast_context *con, const char *sw, const ch
return 0 ;
return 0 ;
}
}
pi = i ;
pi = i ;
i = i - > next ;
}
}
/* we can't find the right switch */
/* we can't find the right switch */
@ -2705,8 +2667,7 @@ int ast_context_remove_extension(const char *context, const char *extension, int
if ( ast_lock_contexts ( ) ) return - 1 ;
if ( ast_lock_contexts ( ) ) return - 1 ;
/* walk contexts ... */
/* walk contexts ... */
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
/* ... search for the right one ... */
/* ... search for the right one ... */
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
/* ... remove extension ... */
/* ... remove extension ... */
@ -2716,7 +2677,6 @@ int ast_context_remove_extension(const char *context, const char *extension, int
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
/* we can't find the right context */
/* we can't find the right context */
@ -2850,30 +2810,31 @@ int ast_register_application(const char *app, int (*execute)(struct ast_channel
ast_log ( LOG_ERROR , " Unable to lock application list \n " ) ;
ast_log ( LOG_ERROR , " Unable to lock application list \n " ) ;
return - 1 ;
return - 1 ;
}
}
tmp = apps ;
for ( tmp = apps ; tmp ; tmp = tmp - > next ) {
while ( tmp ) {
if ( ! strcasecmp ( app , tmp - > name ) ) {
if ( ! strcasecmp ( app , tmp - > name ) ) {
ast_log ( LOG_WARNING , " Already have an application '%s' \n " , app ) ;
ast_log ( LOG_WARNING , " Already have an application '%s' \n " , app ) ;
ast_mutex_unlock ( & applock ) ;
ast_mutex_unlock ( & applock ) ;
return - 1 ;
return - 1 ;
}
}
tmp = tmp - > next ;
}
}
tmp = malloc ( length ) ;
if ( tmp ) {
tmp = calloc ( 1 , length ) ;
memset ( tmp , 0 , length ) ;
if ( ! tmp ) {
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
ast_mutex_unlock ( & applock ) ;
return - 1 ;
}
strcpy ( tmp - > name , app ) ;
strcpy ( tmp - > name , app ) ;
tmp - > execute = execute ;
tmp - > execute = execute ;
tmp - > synopsis = synopsis ;
tmp - > synopsis = synopsis ;
tmp - > description = description ;
tmp - > description = description ;
/* Store in alphabetical order */
/* Store in alphabetical order */
cur = apps ;
prev = NULL ;
prev = NULL ;
while ( cur ) {
for ( cur = apps ; cur ; cur = cur - > next ) {
if ( strcasecmp ( tmp - > name , cur - > name ) < 0 )
if ( strcasecmp ( tmp - > name , cur - > name ) < 0 )
break ;
break ;
prev = cur ;
prev = cur ;
cur = cur - > next ;
}
}
if ( prev ) {
if ( prev ) {
tmp - > next = prev - > next ;
tmp - > next = prev - > next ;
@ -2882,11 +2843,7 @@ int ast_register_application(const char *app, int (*execute)(struct ast_channel
tmp - > next = apps ;
tmp - > next = apps ;
apps = tmp ;
apps = tmp ;
}
}
} else {
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
ast_mutex_unlock ( & applock ) ;
return - 1 ;
}
if ( option_verbose > 1 )
if ( option_verbose > 1 )
ast_verbose ( VERBOSE_PREFIX_2 " Registered application '%s' \n " , term_color ( tmps , tmp - > name , COLOR_BRCYAN , 0 , sizeof ( tmps ) ) ) ;
ast_verbose ( VERBOSE_PREFIX_2 " Registered application '%s' \n " , term_color ( tmps , tmp - > name , COLOR_BRCYAN , 0 , sizeof ( tmps ) ) ) ;
ast_mutex_unlock ( & applock ) ;
ast_mutex_unlock ( & applock ) ;
@ -2900,12 +2857,10 @@ int ast_register_switch(struct ast_switch *sw)
ast_log ( LOG_ERROR , " Unable to lock switch lock \n " ) ;
ast_log ( LOG_ERROR , " Unable to lock switch lock \n " ) ;
return - 1 ;
return - 1 ;
}
}
tmp = switches ;
for ( tmp = switches ; tmp ; tmp = tmp - > next ) {
while ( tmp ) {
if ( ! strcasecmp ( tmp - > name , sw - > name ) )
if ( ! strcasecmp ( tmp - > name , sw - > name ) )
break ;
break ;
prev = tmp ;
prev = tmp ;
tmp = tmp - > next ;
}
}
if ( tmp ) {
if ( tmp ) {
ast_mutex_unlock ( & switchlock ) ;
ast_mutex_unlock ( & switchlock ) ;
@ -2928,8 +2883,7 @@ void ast_unregister_switch(struct ast_switch *sw)
ast_log ( LOG_ERROR , " Unable to lock switch lock \n " ) ;
ast_log ( LOG_ERROR , " Unable to lock switch lock \n " ) ;
return ;
return ;
}
}
tmp = switches ;
for ( tmp = switches ; tmp ; tmp = tmp - > next ) {
while ( tmp ) {
if ( tmp = = sw ) {
if ( tmp = = sw ) {
if ( prev )
if ( prev )
prev - > next = tmp - > next ;
prev - > next = tmp - > next ;
@ -2939,7 +2893,6 @@ void ast_unregister_switch(struct ast_switch *sw)
break ;
break ;
}
}
prev = tmp ;
prev = tmp ;
tmp = tmp - > next ;
}
}
ast_mutex_unlock ( & switchlock ) ;
ast_mutex_unlock ( & switchlock ) ;
}
}
@ -3005,8 +2958,7 @@ static char *complete_show_application(char *line, char *word,
}
}
/* ... walk all applications ... */
/* ... walk all applications ... */
a = apps ;
for ( a = apps ; a ; a = a - > next ) {
while ( a ) {
/* ... check if word matches this application ... */
/* ... check if word matches this application ... */
if ( ! strncasecmp ( word , a - > name , strlen ( word ) ) ) {
if ( ! strncasecmp ( word , a - > name , strlen ( word ) ) ) {
/* ... if this is right app serve it ... */
/* ... if this is right app serve it ... */
@ -3016,7 +2968,6 @@ static char *complete_show_application(char *line, char *word,
return ret ;
return ret ;
}
}
}
}
a = a - > next ;
}
}
/* no application match */
/* no application match */
@ -3038,8 +2989,7 @@ static int handle_show_application(int fd, int argc, char *argv[])
}
}
/* ... go through all applications ... */
/* ... go through all applications ... */
a = apps ;
for ( a = apps ; a ; a = a - > next ) {
while ( a ) {
/* ... compare this application name with all arguments given
/* ... compare this application name with all arguments given
* to ' show application ' command . . . */
* to ' show application ' command . . . */
for ( app = 2 ; app < argc ; app + + ) {
for ( app = 2 ; app < argc ; app + + ) {
@ -3087,7 +3037,6 @@ static int handle_show_application(int fd, int argc, char *argv[])
}
}
}
}
}
}
a = a - > next ;
}
}
ast_mutex_unlock ( & applock ) ;
ast_mutex_unlock ( & applock ) ;
@ -3119,8 +3068,7 @@ static int handle_show_hints(int fd, int argc, char *argv[])
ast_log ( LOG_ERROR , " Unable to lock hints \n " ) ;
ast_log ( LOG_ERROR , " Unable to lock hints \n " ) ;
return - 1 ;
return - 1 ;
}
}
hint = hints ;
for ( hint = hints ; hint ; hint = hint - > next ) {
while ( hint ) {
watchers = 0 ;
watchers = 0 ;
for ( watcher = hint - > callbacks ; watcher ; watcher = watcher - > next )
for ( watcher = hint - > callbacks ; watcher ; watcher = watcher - > next )
watchers + + ;
watchers + + ;
@ -3128,7 +3076,6 @@ static int handle_show_hints(int fd, int argc, char *argv[])
ast_get_extension_name ( hint - > exten ) , ast_get_extension_app ( hint - > exten ) ,
ast_get_extension_name ( hint - > exten ) , ast_get_extension_app ( hint - > exten ) ,
ast_extension_state2str ( hint - > laststate ) , watchers ) ;
ast_extension_state2str ( hint - > laststate ) , watchers ) ;
num + + ;
num + + ;
hint = hint - > next ;
}
}
ast_cli ( fd , " ---------------- \n " ) ;
ast_cli ( fd , " ---------------- \n " ) ;
ast_cli ( fd , " - %d hints registered \n " , num ) ;
ast_cli ( fd , " - %d hints registered \n " , num ) ;
@ -3150,10 +3097,8 @@ static int handle_show_switches(int fd, int argc, char *argv[])
ast_log ( LOG_ERROR , " Unable to lock switches \n " ) ;
ast_log ( LOG_ERROR , " Unable to lock switches \n " ) ;
return - 1 ;
return - 1 ;
}
}
sw = switches ;
for ( sw = switches ; sw ; sw = sw - > next ) {
while ( sw ) {
ast_cli ( fd , " %s: %s \n " , sw - > name , sw - > description ) ;
ast_cli ( fd , " %s: %s \n " , sw - > name , sw - > description ) ;
sw = sw - > next ;
}
}
ast_mutex_unlock ( & switchlock ) ;
ast_mutex_unlock ( & switchlock ) ;
return RESULT_SUCCESS ;
return RESULT_SUCCESS ;
@ -3276,9 +3221,11 @@ static char *complete_show_dialplan_context(char *line, char *word, int pos,
{
{
struct ast_context * c ;
struct ast_context * c ;
int which = 0 ;
int which = 0 ;
int wordlen ;
/* we are do completion of [exten@]context on second position only */
/* we are do completion of [exten@]context on second position only */
if ( pos ! = 2 ) return NULL ;
if ( pos ! = 2 )
return NULL ;
/* try to lock contexts list ... */
/* try to lock contexts list ... */
if ( ast_lock_contexts ( ) ) {
if ( ast_lock_contexts ( ) ) {
@ -3286,11 +3233,12 @@ static char *complete_show_dialplan_context(char *line, char *word, int pos,
return NULL ;
return NULL ;
}
}
wordlen = strlen ( word ) ;
/* ... walk through all contexts ... */
/* ... walk through all contexts ... */
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
/* ... word matches context name? yes? ... */
/* ... word matches context name? yes? ... */
if ( ! strncasecmp ( word , ast_get_context_name ( c ) , strlen ( word ) ) ) {
if ( ! strncasecmp ( word , ast_get_context_name ( c ) , wordlen ) ) {
/* ... for serve? ... */
/* ... for serve? ... */
if ( + + which > state ) {
if ( + + which > state ) {
/* ... yes, serve this context name ... */
/* ... yes, serve this context name ... */
@ -3299,7 +3247,6 @@ static char *complete_show_dialplan_context(char *line, char *word, int pos,
return ret ;
return ret ;
}
}
}
}
c = ast_walk_contexts ( c ) ;
}
}
/* ... unlock and return */
/* ... unlock and return */
@ -3593,8 +3540,7 @@ int ast_unregister_application(const char *app)
ast_log ( LOG_ERROR , " Unable to lock application list \n " ) ;
ast_log ( LOG_ERROR , " Unable to lock application list \n " ) ;
return - 1 ;
return - 1 ;
}
}
tmp = apps ;
for ( tmp = apps ; tmp ; tmp = tmp - > next ) {
while ( tmp ) {
if ( ! strcasecmp ( app , tmp - > name ) ) {
if ( ! strcasecmp ( app , tmp - > name ) ) {
if ( tmpl )
if ( tmpl )
tmpl - > next = tmp - > next ;
tmpl - > next = tmp - > next ;
@ -3607,7 +3553,6 @@ int ast_unregister_application(const char *app)
return 0 ;
return 0 ;
}
}
tmpl = tmp ;
tmpl = tmp ;
tmp = tmp - > next ;
}
}
ast_mutex_unlock ( & applock ) ;
ast_mutex_unlock ( & applock ) ;
return - 1 ;
return - 1 ;
@ -3625,8 +3570,7 @@ struct ast_context *ast_context_create(struct ast_context **extcontexts, const c
} else
} else
local_contexts = extcontexts ;
local_contexts = extcontexts ;
tmp = * local_contexts ;
for ( tmp = * local_contexts ; tmp ; tmp = tmp - > next ) {
while ( tmp ) {
if ( ! strcasecmp ( tmp - > name , name ) ) {
if ( ! strcasecmp ( tmp - > name , name ) ) {
ast_mutex_unlock ( & conlock ) ;
ast_mutex_unlock ( & conlock ) ;
ast_log ( LOG_WARNING , " Tried to register context '%s', already in use \n " , name ) ;
ast_log ( LOG_WARNING , " Tried to register context '%s', already in use \n " , name ) ;
@ -3634,11 +3578,9 @@ struct ast_context *ast_context_create(struct ast_context **extcontexts, const c
ast_mutex_unlock ( & conlock ) ;
ast_mutex_unlock ( & conlock ) ;
return NULL ;
return NULL ;
}
}
tmp = tmp - > next ;
}
}
tmp = malloc( length ) ;
tmp = calloc( 1 , length ) ;
if ( tmp ) {
if ( tmp ) {
memset ( tmp , 0 , length ) ;
ast_mutex_init ( & tmp - > lock ) ;
ast_mutex_init ( & tmp - > lock ) ;
strcpy ( tmp - > name , name ) ;
strcpy ( tmp - > name , name ) ;
tmp - > root = NULL ;
tmp - > root = NULL ;
@ -3779,8 +3721,7 @@ int ast_context_add_include(const char *context, const char *include, const char
}
}
/* walk contexts ... */
/* walk contexts ... */
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
/* ... search for the right one ... */
/* ... search for the right one ... */
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
int ret = ast_context_add_include2 ( c , include , registrar ) ;
int ret = ast_context_add_include2 ( c , include , registrar ) ;
@ -3788,7 +3729,6 @@ int ast_context_add_include(const char *context, const char *include, const char
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
/* we can't find the right context */
/* we can't find the right context */
@ -4147,14 +4087,13 @@ int ast_context_add_include2(struct ast_context *con, const char *value,
length + = 2 * ( strlen ( value ) + 1 ) ;
length + = 2 * ( strlen ( value ) + 1 ) ;
/* allocate new include structure ... */
/* allocate new include structure ... */
if ( ! ( new_include = malloc( length ) ) ) {
if ( ! ( new_include = calloc( 1 , length ) ) ) {
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
errno = ENOMEM ;
errno = ENOMEM ;
return - 1 ;
return - 1 ;
}
}
/* ... fill in this structure ... */
/* ... fill in this structure ... */
memset ( new_include , 0 , length ) ;
p = new_include - > stuff ;
p = new_include - > stuff ;
new_include - > name = p ;
new_include - > name = p ;
strcpy ( new_include - > name , value ) ;
strcpy ( new_include - > name , value ) ;
@ -4181,8 +4120,7 @@ int ast_context_add_include2(struct ast_context *con, const char *value,
}
}
/* ... go to last include and check if context is already included too... */
/* ... go to last include and check if context is already included too... */
i = con - > includes ;
for ( i = con - > includes ; i ; i = i - > next ) {
while ( i ) {
if ( ! strcasecmp ( i - > name , new_include - > name ) ) {
if ( ! strcasecmp ( i - > name , new_include - > name ) ) {
free ( new_include ) ;
free ( new_include ) ;
ast_mutex_unlock ( & con - > lock ) ;
ast_mutex_unlock ( & con - > lock ) ;
@ -4190,7 +4128,6 @@ int ast_context_add_include2(struct ast_context *con, const char *value,
return - 1 ;
return - 1 ;
}
}
il = i ;
il = i ;
i = i - > next ;
}
}
/* ... include new context into context list, unlock, return */
/* ... include new context into context list, unlock, return */
@ -4220,8 +4157,7 @@ int ast_context_add_switch(const char *context, const char *sw, const char *data
}
}
/* walk contexts ... */
/* walk contexts ... */
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
/* ... search for the right one ... */
/* ... search for the right one ... */
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
int ret = ast_context_add_switch2 ( c , sw , data , eval , registrar ) ;
int ret = ast_context_add_switch2 ( c , sw , data , eval , registrar ) ;
@ -4229,7 +4165,6 @@ int ast_context_add_switch(const char *context, const char *sw, const char *data
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
/* we can't find the right context */
/* we can't find the right context */
@ -4265,14 +4200,13 @@ int ast_context_add_switch2(struct ast_context *con, const char *value,
}
}
/* allocate new sw structure ... */
/* allocate new sw structure ... */
if ( ! ( new_sw = malloc( length ) ) ) {
if ( ! ( new_sw = calloc( 1 , length ) ) ) {
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
errno = ENOMEM ;
errno = ENOMEM ;
return - 1 ;
return - 1 ;
}
}
/* ... fill in this structure ... */
/* ... fill in this structure ... */
memset ( new_sw , 0 , length ) ;
p = new_sw - > stuff ;
p = new_sw - > stuff ;
new_sw - > name = p ;
new_sw - > name = p ;
strcpy ( new_sw - > name , value ) ;
strcpy ( new_sw - > name , value ) ;
@ -4299,8 +4233,7 @@ int ast_context_add_switch2(struct ast_context *con, const char *value,
}
}
/* ... go to last sw and check if context is already swd too... */
/* ... go to last sw and check if context is already swd too... */
i = con - > alts ;
for ( i = con - > alts ; i ; i = i - > next ) {
while ( i ) {
if ( ! strcasecmp ( i - > name , new_sw - > name ) & & ! strcasecmp ( i - > data , new_sw - > data ) ) {
if ( ! strcasecmp ( i - > name , new_sw - > name ) & & ! strcasecmp ( i - > data , new_sw - > data ) ) {
free ( new_sw ) ;
free ( new_sw ) ;
ast_mutex_unlock ( & con - > lock ) ;
ast_mutex_unlock ( & con - > lock ) ;
@ -4308,7 +4241,6 @@ int ast_context_add_switch2(struct ast_context *con, const char *value,
return - 1 ;
return - 1 ;
}
}
il = i ;
il = i ;
i = i - > next ;
}
}
/* ... sw new context into context list, unlock, return */
/* ... sw new context into context list, unlock, return */
@ -4336,14 +4268,12 @@ int ast_context_remove_ignorepat(const char *context, const char *ignorepat, con
return - 1 ;
return - 1 ;
}
}
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
if ( ! strcmp ( ast_get_context_name ( c ) , context ) ) {
int ret = ast_context_remove_ignorepat2 ( c , ignorepat , registrar ) ;
int ret = ast_context_remove_ignorepat2 ( c , ignorepat , registrar ) ;
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
@ -4360,8 +4290,7 @@ int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat
return - 1 ;
return - 1 ;
}
}
ip = con - > ignorepats ;
for ( ip = con - > ignorepats ; ip ; ip = ip - > next ) {
while ( ip ) {
if ( ! strcmp ( ip - > pattern , ignorepat ) & &
if ( ! strcmp ( ip - > pattern , ignorepat ) & &
( ! registrar | | ( registrar = = ip - > registrar ) ) ) {
( ! registrar | | ( registrar = = ip - > registrar ) ) ) {
if ( ipl ) {
if ( ipl ) {
@ -4374,7 +4303,7 @@ int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat
ast_mutex_unlock ( & con - > lock ) ;
ast_mutex_unlock ( & con - > lock ) ;
return 0 ;
return 0 ;
}
}
ipl = ip ; ip = ip - > next ;
ipl = ip ;
}
}
ast_mutex_unlock ( & con - > lock ) ;
ast_mutex_unlock ( & con - > lock ) ;
@ -4395,14 +4324,12 @@ int ast_context_add_ignorepat(const char *con, const char *value, const char *re
return - 1 ;
return - 1 ;
}
}
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
if ( ! strcmp ( ast_get_context_name ( c ) , con ) ) {
if ( ! strcmp ( ast_get_context_name ( c ) , con ) ) {
int ret = ast_context_add_ignorepat2 ( c , value , registrar ) ;
int ret = ast_context_add_ignorepat2 ( c , value , registrar ) ;
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
@ -4416,19 +4343,17 @@ int ast_context_add_ignorepat2(struct ast_context *con, const char *value, const
int length ;
int length ;
length = sizeof ( struct ast_ignorepat ) ;
length = sizeof ( struct ast_ignorepat ) ;
length + = strlen ( value ) + 1 ;
length + = strlen ( value ) + 1 ;
ignorepat = malloc( length ) ;
ignorepat = calloc( 1 , length ) ;
if ( ! ignorepat ) {
if ( ! ignorepat ) {
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
ast_log ( LOG_ERROR , " Out of memory \n " ) ;
errno = ENOMEM ;
errno = ENOMEM ;
return - 1 ;
return - 1 ;
}
}
memset ( ignorepat , 0 , length ) ;
strcpy ( ignorepat - > pattern , value ) ;
strcpy ( ignorepat - > pattern , value ) ;
ignorepat - > next = NULL ;
ignorepat - > next = NULL ;
ignorepat - > registrar = registrar ;
ignorepat - > registrar = registrar ;
ast_mutex_lock ( & con - > lock ) ;
ast_mutex_lock ( & con - > lock ) ;
ignorepatc = con - > ignorepats ;
for ( ignorepatc = con - > ignorepats ; ignorepatc ; ignorepatc = ignorepatc - > next ) {
while ( ignorepatc ) {
ignorepatl = ignorepatc ;
ignorepatl = ignorepatc ;
if ( ! strcasecmp ( ignorepatc - > pattern , value ) ) {
if ( ! strcasecmp ( ignorepatc - > pattern , value ) ) {
/* Already there */
/* Already there */
@ -4436,7 +4361,6 @@ int ast_context_add_ignorepat2(struct ast_context *con, const char *value, const
errno = EEXIST ;
errno = EEXIST ;
return - 1 ;
return - 1 ;
}
}
ignorepatc = ignorepatc - > next ;
}
}
if ( ignorepatl )
if ( ignorepatl )
ignorepatl - > next = ignorepat ;
ignorepatl - > next = ignorepat ;
@ -4454,11 +4378,9 @@ int ast_ignore_pattern(const char *context, const char *pattern)
con = ast_context_find ( context ) ;
con = ast_context_find ( context ) ;
if ( con ) {
if ( con ) {
pat = con - > ignorepats ;
for ( pat = con - > ignorepats ; pat ; pat = pat - > next ) {
while ( pat ) {
if ( ast_extension_match ( pat - > pattern , pattern ) )
if ( ast_extension_match ( pat - > pattern , pattern ) )
return 1 ;
return 1 ;
pat = pat - > next ;
}
}
}
}
return 0 ;
return 0 ;
@ -4479,15 +4401,13 @@ int ast_add_extension(const char *context, int replace, const char *extension, i
return - 1 ;
return - 1 ;
}
}
c = ast_walk_contexts ( NULL ) ;
for ( c = ast_walk_contexts ( NULL ) ; c ; c = ast_walk_contexts ( c ) ) {
while ( c ) {
if ( ! strcmp ( context , ast_get_context_name ( c ) ) ) {
if ( ! strcmp ( context , ast_get_context_name ( c ) ) ) {
int ret = ast_add_extension2 ( c , replace , extension , priority , label , callerid ,
int ret = ast_add_extension2 ( c , replace , extension , priority , label , callerid ,
application , data , datad , registrar ) ;
application , data , datad , registrar ) ;
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
return ret ;
return ret ;
}
}
c = ast_walk_contexts ( c ) ;
}
}
ast_unlock_contexts ( ) ;
ast_unlock_contexts ( ) ;
@ -4661,9 +4581,8 @@ int ast_add_extension2(struct ast_context *con,
/* Be optimistic: Build the extension structure first */
/* Be optimistic: Build the extension structure first */
if ( datad = = NULL )
if ( datad = = NULL )
datad = null_datad ;
datad = null_datad ;
tmp = malloc( length ) ;
tmp = calloc( 1 , length ) ;
if ( tmp ) {
if ( tmp ) {
memset ( tmp , 0 , length ) ;
p = tmp - > stuff ;
p = tmp - > stuff ;
if ( label ) {
if ( label ) {
tmp - > label = p ;
tmp - > label = p ;
@ -4703,8 +4622,7 @@ int ast_add_extension2(struct ast_context *con,
errno = EBUSY ;
errno = EBUSY ;
return - 1 ;
return - 1 ;
}
}
e = con - > root ;
for ( e = con - > root ; e ; e = e - > next ) {
while ( e ) {
/* Make sure patterns are always last! */
/* Make sure patterns are always last! */
if ( ( e - > exten [ 0 ] ! = ' _ ' ) & & ( extension [ 0 ] = = ' _ ' ) )
if ( ( e - > exten [ 0 ] ! = ' _ ' ) & & ( extension [ 0 ] = = ' _ ' ) )
res = - 1 ;
res = - 1 ;
@ -4827,7 +4745,6 @@ int ast_add_extension2(struct ast_context *con,
}
}
el = e ;
el = e ;
e = e - > next ;
}
}
/* If we fall all the way through to here, then we need to be on the end. */
/* If we fall all the way through to here, then we need to be on the end. */
if ( el )
if ( el )
@ -5455,7 +5372,7 @@ static int pbx_builtin_setamaflags(struct ast_channel *chan, void *data)
{
{
/* Copy the AMA Flags as specified */
/* Copy the AMA Flags as specified */
if ( data )
if ( data )
ast_cdr_setamaflags ( chan , ( char * ) data ) ;
ast_cdr_setamaflags ( chan , data ) ;
else
else
ast_cdr_setamaflags ( chan , " " ) ;
ast_cdr_setamaflags ( chan , " " ) ;
return 0 ;
return 0 ;
@ -5486,7 +5403,7 @@ static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data)
return - 1 ;
return - 1 ;
}
}
if ( ( s = ast_strdupa ( ( char * ) data ) ) ) {
if ( ( s = ast_strdupa ( data ) ) ) {
ts = s ;
ts = s ;
/* Separate the Goto path */
/* Separate the Goto path */