Newer
Older
/* Substitutes variables into cp2, based on string cp1, and assuming cp2 to be
zero-filled */
whereweare=tmp=cp1;
while(!ast_strlen_zero(whereweare) && count) {
/* Assume we're copying the whole remaining string */
pos = strlen(whereweare);
/* Look for a variable */
nextvar = strstr(whereweare, "${");
nextexp = strstr(whereweare, "$[");
if (nextvar && nextexp) {
if (nextvar < nextexp)
nextexp = NULL;
else
nextvar = NULL;
}
/* If there is one, we only go that far */
if (nextvar)
pos = nextvar - whereweare;
else if (nextexp)
pos = nextexp - whereweare;
/* Can't copy more than 'count' bytes */
if (pos > count)
pos = count;
/* Copy that many bytes */
memcpy(cp2, whereweare, pos);
count -= pos;
cp2 += pos;
whereweare += pos;
/* We have a variable. Find the start and end, and determine
if we are going to have to recursively call ourselves on the
contents */
vars = vare = nextvar + 2;
/* Find the end of it */
while(brackets && *vare) {
if ((vare[0] == '$') && (vare[1] == '{')) {
needsub++;
brackets++;
} else if (vare[0] == '}') {
brackets--;
} else if ((vare[0] == '$') && (vare[1] == '['))
if (brackets)
ast_log(LOG_NOTICE, "Error in extension logic (missing '}')\n");
len = vare - vars - 1;
/* Skip totally over variable name */
whereweare += ( len + 3);
/* Store variable name (and truncate) */
memset(var, 0, sizeof(var));
strncpy(var, vars, sizeof(var) - 1);
var[len] = '\0';
/* Substitute if necessary */
if (needsub) {
memset(ltmp, 0, sizeof(ltmp));
pbx_substitute_variables_helper(c, var, ltmp, sizeof(ltmp) - 1);
vars = ltmp;
} else {
vars = var;
pbx_substitute_variables_temp(c,vars,&cp4, workspace, sizeof(workspace));
if (cp4) {
length = strlen(cp4);
if (length > count)
length = count;
memcpy(cp2, cp4, length);
count -= length;
cp2 += length;
} else if (nextexp) {
/* We have an expression. Find the start and end, and determine
if we are going to have to recursively call ourselves on the
contents */
vars = vare = nextexp + 2;
brackets = 1;
needsub = 0;
/* Find the end of it */
while(brackets && *vare) {
if ((vare[0] == '$') && (vare[1] == '[')) {
needsub++;
brackets++;
vare++;
} else if (vare[0] == '[') {
brackets++;
} else if (vare[0] == ']') {
brackets--;
} else if ((vare[0] == '$') && (vare[1] == '{')) {
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
vare++;
}
if (brackets)
ast_log(LOG_NOTICE, "Error in extension logic (missing ']')\n");
len = vare - vars - 1;
/* Skip totally over variable name */
whereweare += ( len + 3);
/* Store variable name (and truncate) */
memset(var, 0, sizeof(var));
strncpy(var, vars, sizeof(var) - 1);
var[len] = '\0';
/* Substitute if necessary */
if (needsub) {
memset(ltmp, 0, sizeof(ltmp));
pbx_substitute_variables_helper(c, var, ltmp, sizeof(ltmp) - 1);
vars = ltmp;
} else {
vars = var;
}
/* Evaluate expression */
cp4 = ast_expr(vars);
ast_log(LOG_DEBUG, "Expression is '%s'\n", cp4);
if (cp4) {
length = strlen(cp4);
if (length > count)
length = count;
memcpy(cp2, cp4, length);
count -= length;
cp2 += length;
free(cp4);
}
static void pbx_substitute_variables(char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e) {
memset(passdata, 0, datalen);
/* No variables or expressions in e->data, so why scan it? */
if (!strstr(e->data,"${") && !strstr(e->data,"$[")) {
strncpy(passdata, e->data, datalen - 1);
passdata[datalen-1] = '\0';
return;
}
pbx_substitute_variables_helper(c,e->data,passdata, datalen - 1);
}
static int pbx_extension_helper(struct ast_channel *c, char *context, char *exten, int priority, char *callerid, int action)
int status = 0;
char *incstack[AST_PBX_MAX_STACK];
char passdata[EXT_DATA_SIZE];
char tmp3[EXT_DATA_SIZE];
if (ast_mutex_lock(&conlock)) {
if ((action == HELPER_EXISTS) || (action == HELPER_CANMATCH) || (action == HELPER_MATCHMORE))
e = pbx_find_extension(c, context, exten, priority, callerid, action, incstack, &stacklen, &status, &sw, &data);
if (e) {
switch(action) {
case HELPER_CANMATCH:
ast_mutex_unlock(&conlock);
ast_mutex_unlock(&conlock);
ast_mutex_unlock(&conlock);
case HELPER_SPAWN:
newstack++;
/* Fall through */
case HELPER_EXEC:
app = pbx_findapp(e->app);
ast_mutex_unlock(&conlock);
strncpy(c->context, context, sizeof(c->context)-1);
if (c->exten != exten)
strncpy(c->exten, exten, sizeof(c->exten)-1);
pbx_substitute_variables(passdata, sizeof(passdata), c, e);
if (option_debug)
ast_log(LOG_DEBUG, "Launching '%s'\n", app->name);
else if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Executing %s(\"%s\", \"%s\") %s\n",
term_color(tmp, app->name, COLOR_BRCYAN, 0, sizeof(tmp)),
term_color(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
term_color(tmp3, (!ast_strlen_zero(passdata) ? (char *)passdata : ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)),
res = pbx_exec(c, app, passdata, newstack);
return res;
} else {
ast_log(LOG_WARNING, "No application '%s' for extension (%s, %s, %d)\n", e->app, context, exten, priority);
return -1;
}
default:
ast_log(LOG_WARNING, "Huh (%d)?\n", action); return -1;
} else if (sw) {
switch(action) {
case HELPER_CANMATCH:
ast_mutex_unlock(&conlock);
ast_mutex_unlock(&conlock);
ast_mutex_unlock(&conlock);
case HELPER_SPAWN:
newstack++;
/* Fall through */
case HELPER_EXEC:
ast_mutex_unlock(&conlock);
if (sw->exec)
res = sw->exec(c, context, exten, priority, callerid, newstack, data);
else {
ast_log(LOG_WARNING, "No execution engine for switch %s\n", sw->name);
res = -1;
}
return res;
default:
ast_log(LOG_WARNING, "Huh (%d)?\n", action);
return -1;
}
ast_mutex_unlock(&conlock);
if ((action != HELPER_EXISTS) && (action != HELPER_MATCHMORE))
ast_log(LOG_NOTICE, "Cannot find extension context '%s'\n", context);
break;
case STATUS_NO_EXTENSION:
if ((action != HELPER_EXISTS) && (action != HELPER_CANMATCH) && (action != HELPER_MATCHMORE))
ast_log(LOG_NOTICE, "Cannot find extension '%s' in context '%s'\n", exten, context);
break;
case STATUS_NO_PRIORITY:
if ((action != HELPER_EXISTS) && (action != HELPER_CANMATCH) && (action != HELPER_MATCHMORE))
ast_log(LOG_NOTICE, "No such priority %d in extension '%s' in context '%s'\n", priority, exten, context);
break;
default:
ast_log(LOG_DEBUG, "Shouldn't happen!\n");
}
if ((action != HELPER_EXISTS) && (action != HELPER_CANMATCH) && (action != HELPER_MATCHMORE))
static struct ast_exten *ast_hint_extension(struct ast_channel *c, char *context, char *exten)
{
struct ast_exten *e;
struct ast_switch *sw;
char *data;
int status = 0;
char *incstack[AST_PBX_MAX_STACK];
int stacklen = 0;
if (ast_mutex_lock(&conlock)) {
ast_log(LOG_WARNING, "Unable to obtain lock\n");
return NULL;
}
e = pbx_find_extension(c, context, exten, PRIORITY_HINT, "", HELPER_EXISTS, incstack, &stacklen, &status, &sw, &data);
ast_mutex_unlock(&conlock);
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
return e;
}
static int ast_extension_state2(struct ast_exten *e)
{
char hint[AST_MAX_EXTENSION] = "";
char *cur, *rest;
int res = -1;
int allunavailable = 1, allbusy = 1, allfree = 1;
int busy = 0;
strncpy(hint, ast_get_extension_app(e), sizeof(hint)-1);
cur = hint;
do {
rest = strchr(cur, '&');
if (rest) {
*rest = 0;
rest++;
}
res = ast_device_state(cur);
switch (res) {
allunavailable = 0;
allbusy = 0;
break;
return AST_EXTENSION_INUSE;
allunavailable = 0;
allfree = 0;
busy = 1;
break;
case AST_DEVICE_UNAVAILABLE:
case AST_DEVICE_INVALID:
allbusy = 0;
allfree = 0;
break;
allunavailable = 0;
allbusy = 0;
allfree = 0;
}
cur = rest;
} while (cur);
if (allfree)
if (allbusy)
if (allunavailable)
return AST_EXTENSION_NOT_INUSE;
}
int ast_extension_state(struct ast_channel *c, char *context, char *exten)
{
e = ast_hint_extension(c, context, exten);
if (!e)
return -1;
return ast_extension_state2(e);
int ast_device_state_changed(const char *fmt, ...)
struct ast_hint *list;
struct ast_state_cb *cblist;
char hint[AST_MAX_EXTENSION];
char device[AST_MAX_EXTENSION];
char *cur, *rest;
int state;
va_list ap;
va_start(ap, fmt);
vsnprintf(device, sizeof(device)-1, fmt, ap);
va_end(ap);
rest = strchr(device, '-');
if (rest) {
*rest = 0;
}
ast_mutex_lock(&hintlock);
list = hints;
while (list) {
strcpy(hint, ast_get_extension_app(list->exten));
cur = hint;
do {
rest = strchr(cur, '&');
if (rest) {
*rest = 0;
rest++;
}
// Found extension execute callbacks
state = ast_extension_state2(list->exten);
if ((state != -1) && (state != list->laststate)) {
// For general callbacks
cblist = statecbs;
while (cblist) {
cblist->callback(list->exten->parent->name, list->exten->exten, state, cblist->data);
cblist = cblist->next;
}
// For extension callbacks
cblist = list->callbacks;
while (cblist) {
cblist->callback(list->exten->parent->name, list->exten->exten, state, cblist->data);
cblist = cblist->next;
}
list->laststate = state;
}
break;
}
cur = rest;
} while (cur);
list = list->next;
}
ast_mutex_unlock(&hintlock);
return 1;
}
int ast_extension_state_add(char *context, char *exten,
ast_state_cb_type callback, void *data)
struct ast_hint *list;
struct ast_state_cb *cblist;
struct ast_exten *e;
/* No context and extension add callback to statecbs list */
if (!context && !exten) {
ast_mutex_lock(&hintlock);
cblist = statecbs;
while (cblist) {
if (cblist->callback == callback) {
cblist->data = data;
ast_mutex_unlock(&hintlock);
}
cblist = cblist->next;
}
/* Now inserts the callback */
cblist = malloc(sizeof(struct ast_state_cb));
if (!cblist) {
ast_mutex_unlock(&hintlock);
return -1;
}
memset(cblist, 0, sizeof(struct ast_state_cb));
cblist->id = 0;
cblist->callback = callback;
cblist->data = data;
cblist->next = statecbs;
statecbs = cblist;
ast_mutex_unlock(&hintlock);
return 0;
}
if (!context || !exten)
return -1;
/* This callback type is for only one hint */
e = ast_hint_extension(NULL, context, exten);
if (!e) {
return -1;
}
ast_mutex_lock(&hintlock);
list = hints;
while (list) {
break;
list = list->next;
}
if (!list) {
ast_mutex_unlock(&hintlock);
/* Now inserts the callback */
cblist = malloc(sizeof(struct ast_state_cb));
if (!cblist) {
ast_mutex_unlock(&hintlock);
return -1;
}
memset(cblist, 0, sizeof(struct ast_state_cb));
cblist->id = stateid++;
cblist->callback = callback;
cblist->data = data;
cblist->next = list->callbacks;
list->callbacks = cblist;
ast_mutex_unlock(&hintlock);
return cblist->id;
}
int ast_extension_state_del(int id, ast_state_cb_type callback)
{
struct ast_hint *list;
struct ast_state_cb *cblist, *cbprev;
if (!id && !callback)
return -1;
ast_mutex_lock(&hintlock);
/* id is zero is a callback without extension */
if (!id) {
cbprev = NULL;
cblist = statecbs;
while (cblist) {
if (cblist->callback == callback) {
if (!cbprev)
statecbs = cblist->next;
else
cbprev->next = cblist->next;
free(cblist);
ast_mutex_unlock(&hintlock);
return 0;
}
cbprev = cblist;
cblist = cblist->next;
}
ast_mutex_lock(&hintlock);
return -1;
}
/* id greater zero is a callback with extension */
list = hints;
while (list) {
cblist = list->callbacks;
cbprev = NULL;
while (cblist) {
if (cblist->id==id) {
if (!cbprev)
list->callbacks = cblist->next;
else
cbprev->next = cblist->next;
free(cblist);
ast_mutex_unlock(&hintlock);
return 0;
}
cbprev = cblist;
cblist = cblist->next;
}
list = list->next;
}
ast_mutex_unlock(&hintlock);
return -1;
}
static int ast_add_hint(struct ast_exten *e)
{
struct ast_hint *list;
if (!e) return -1;
ast_mutex_lock(&hintlock);
list = hints;
/* Search if hint exists, do nothing */
while (list) {
if (list->exten == e) {
ast_mutex_unlock(&hintlock);
return -1;
}
list = list->next;
}
list = malloc(sizeof(struct ast_hint));
if (!list) {
ast_mutex_unlock(&hintlock);
return -1;
}
/* Initialize and insert new item */
memset(list, 0, sizeof(struct ast_hint));
list->exten = e;
list->laststate = ast_extension_state2(e);
list->next = hints;
hints = list;
ast_mutex_unlock(&hintlock);
return 0;
}
static int ast_change_hint(struct ast_exten *oe, struct ast_exten *ne)
{
struct ast_hint *list;
ast_mutex_lock(&hintlock);
list = hints;
while(list) {
if (list->exten == oe) {
list->exten = ne;
ast_mutex_unlock(&hintlock);
return 0;
}
list = list->next;
}
ast_mutex_unlock(&hintlock);
return -1;
}
static int ast_remove_hint(struct ast_exten *e)
{
/* Cleanup the Notifys if hint is removed */
struct ast_hint *list, *prev = NULL;
struct ast_state_cb *cblist, *cbprev;
if (!e)
return -1;
ast_mutex_lock(&hintlock);
list = hints;
while(list) {
if (list->exten==e) {
cbprev = NULL;
cblist = list->callbacks;
while (cblist) {
/* Notify with -1 and remove all callbacks */
cbprev = cblist;
cblist = cblist->next;
cbprev->callback(list->exten->parent->name, list->exten->exten, -1, cbprev->data);
free(cbprev);
}
list->callbacks = NULL;
if (!prev)
hints = list->next;
else
prev->next = list->next;
free(list);
ast_mutex_unlock(&hintlock);
} else {
prev = list;
list = list->next;
}
}
ast_mutex_unlock(&hintlock);
}
int ast_get_hint(char *hint, int maxlen, struct ast_channel *c, char *context, char *exten)
{
struct ast_exten *e;
e = ast_hint_extension(c, context, exten);
if (e) {
strncpy(hint, ast_get_extension_app(e), maxlen);
return -1;
}
return 0;
}
int ast_exists_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid)
return pbx_extension_helper(c, context, exten, priority, callerid, HELPER_EXISTS);
int ast_canmatch_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid)
return pbx_extension_helper(c, context, exten, priority, callerid, HELPER_CANMATCH);
int ast_matchmore_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid)
{
return pbx_extension_helper(c, context, exten, priority, callerid, HELPER_MATCHMORE);
}
int ast_spawn_extension(struct ast_channel *c, char *context, char *exten, int priority, char *callerid)
return pbx_extension_helper(c, context, exten, priority, callerid, HELPER_SPAWN);
{
int firstpass = 1;
char digit;
char exten[256];
int pos;
int waittime;
/* A little initial setup here */
if (c->pbx)
ast_log(LOG_WARNING, "%s already has PBX structure??\n", c->name);
c->pbx = malloc(sizeof(struct ast_pbx));
if (!c->pbx) {
ast_log(LOG_ERROR, "Out of memory\n");
ast_log(LOG_WARNING, "%s already has a call record??\n", c->name);
} else {
c->cdr = ast_cdr_alloc();
if (!c->cdr) {
ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
free(c->pbx);
return -1;
}
ast_cdr_init(c->cdr, c);
}
}
memset(c->pbx, 0, sizeof(struct ast_pbx));
/* Set reasonable defaults */
c->pbx->rtimeout = 10;
c->pbx->dtimeout = 5;
/* Start by trying whatever the channel is set to */
if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
/* JK02: And finally back to default if everything else failed */
strncpy(c->context, "default", sizeof(c->context)-1);
}
while(ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
manager_event(EVENT_FLAG_CALL, "Newexten",
"Channel: %s\r\n"
"Context: %s\r\n"
"Extension: %s\r\n"
"Priority: %d\r\n"
"Uniqueid: %s\r\n",
c->name, c->context, c->exten, c->priority, c->uniqueid);
if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->callerid))) {
/* Something bad happened, or a hangup has been requested. */
if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
(res == '*') || (res == '#')) {
ast_log(LOG_DEBUG, "Oooh, got something to jump out with ('%c')!\n", res);
switch(res) {
case AST_PBX_KEEPALIVE:
if (option_debug)
ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
else if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
default:
if (option_debug)
ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
else if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
c->_softhangup =0;
break;
}
/* atimeout */
if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
break;
}
if (c->cdr) {
ast_cdr_update(c);
}
if ((c->_softhangup == AST_SOFTHANGUP_TIMEOUT) && (ast_exists_extension(c,c->context,"T",1,c->callerid))) {
strncpy(c->exten,"T",sizeof(c->exten) - 1);
/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
c->whentohangup = 0;
c->priority = 0;
c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
ast_log(LOG_DEBUG, "Extension %s, priority %d returned normally even though call was hung up\n",
if (!ast_exists_extension(c, c->context, c->exten, 1, c->callerid)) {
if (ast_exists_extension(c, c->context, "i", 1, c->callerid)) {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
pbx_builtin_setvar_helper(c, "INVALID_EXTEN", c->exten);
c->priority = 1;
} else {
ast_log(LOG_WARNING, "Channel '%s' sent into invalid extension '%s' in context '%s', but no invalid handler\n",
c->name, c->exten, c->context);
} else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
/* If we get this far with AST_SOFTHANGUP_TIMEOUT, then we know that the "T" extension is next. */
c->_softhangup = 0;
/* Done, wait for an extension */
if (digit)
waittime = c->pbx->dtimeout;
else
waittime = c->pbx->rtimeout;
while (ast_matchmore_extension(c, c->context, exten, 1, c->callerid)) {
/* As long as we're willing to wait, and as long as it's not defined,
keep reading digits until we can't possibly get a right answer anymore. */
digit = ast_waitfordigit(c, waittime * 1000);
if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
c->_softhangup = 0;
} else {
if (!digit)
/* No entry */
break;
if (digit < 0)
/* Error, maybe a hangup */
goto out;
exten[pos++] = digit;
waittime = c->pbx->dtimeout;
}
if (ast_exists_extension(c, c->context, exten, 1, c->callerid)) {
if (!ast_strlen_zero(exten)) {
if (ast_exists_extension(c, c->context, "i", 1, c->callerid)) {
if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Invalid extension '%s' in context '%s' on %s\n", exten, c->context, c->name);
pbx_builtin_setvar_helper(c, "INVALID_EXTEN", exten);
c->priority = 1;
} else {
ast_log(LOG_WARNING, "Invalid extension, but no rule 'i' in context '%s'\n", c->context);
goto out;
}
if (ast_exists_extension(c, c->context, "t", 1, c->callerid)) {
if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Timeout on %s\n", c->name);
c->priority = 1;
} else {
ast_log(LOG_WARNING, "Timeout, but no rule 't' in context '%s'\n", c->context);
goto out;
}
}
}
if (c->cdr) {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_2 "CDR updated on %s\n",c->name);
}
}
if (firstpass)
ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name);
out:
if ((res != AST_PBX_KEEPALIVE) && ast_exists_extension(c, c->context, "h", 1, c->callerid)) {
strcpy(c->exten, "h");
c->priority = 1;
while(ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->callerid))) {
/* Something bad happened, or a hangup has been requested. */
if (option_debug)
ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
else if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
break;
}
c->priority++;
}
}
if (res != AST_PBX_KEEPALIVE)
ast_hangup(c);
return 0;
}
static void *pbx_thread(void *data)
{
/* Oh joyeous kernel, we're a new thread, with nothing to do but
answer this channel and get it going. The setjmp stuff is fairly
confusing, but necessary to get smooth transitions between
the execution of different applications (without the use of
additional threads) */
struct ast_channel *c = data;
ast_pbx_run(c);
}
int ast_pbx_start(struct ast_channel *c)
{
pthread_t t;
if (!c) {
ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
return -1;
}
/* Start a new thread, and get something handling this channel. */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (pthread_create(&t, &attr, pbx_thread, c)) {
ast_log(LOG_WARNING, "Failed to create new channel thread\n");
return -1;
}
return 0;
}
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
/*
* This function locks contexts list by &conlist, search for the rigt context
* structure, leave context list locked and call ast_context_remove_include2
* which removes include, unlock contexts list and return ...
*/
int ast_context_remove_include(char *context, char *include, char *registrar)
{
struct ast_context *c;
if (ast_lock_contexts()) return -1;
/* walk contexts and search for the right one ...*/
c = ast_walk_contexts(NULL);
while (c) {
/* we found one ... */
if (!strcmp(ast_get_context_name(c), context)) {
int ret;
/* remove include from this context ... */
ret = ast_context_remove_include2(c, include, registrar);
ast_unlock_contexts();
/* ... return results */
return ret;
}
c = ast_walk_contexts(c);
}
/* we can't find the right one context */
ast_unlock_contexts();
return -1;
}
/*
* When we call this function, &conlock lock must be locked, because when
* we giving *con argument, some process can remove/change this context
* and after that there can be segfault.
*
* This function locks given context, removes include, unlock context and
* return.
*/
int ast_context_remove_include2(struct ast_context *con, char *include, char *registrar)
{
struct ast_include *i, *pi = NULL;