another function restructured

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@25749 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Luigi Rizzo 19 years ago
parent 481cde0294
commit eb4ba3b888

70
pbx.c

@ -1810,8 +1810,8 @@ int ast_extension_state_add(const char *context, const char *exten,
/*! \brief ast_extension_state_del: Remove a watcher from the callback list */ /*! \brief ast_extension_state_del: Remove a watcher from the callback list */
int ast_extension_state_del(int id, ast_state_cb_type callback) int ast_extension_state_del(int id, ast_state_cb_type callback)
{ {
struct ast_hint *hint; struct ast_state_cb **p_cur = NULL; /* address of pointer to us */
struct ast_state_cb *cblist, *cbprev; int ret = -1;
if (!id && !callback) if (!id && !callback)
return -1; return -1;
@ -1819,49 +1819,30 @@ int ast_extension_state_del(int id, ast_state_cb_type callback)
AST_LIST_LOCK(&hints); AST_LIST_LOCK(&hints);
/* id is zero is a callback without extension */ /* id is zero is a callback without extension */
if (!id) { if (!id) { /* id == 0 is a callback without extension */
cbprev = NULL; for (p_cur = &statecbs; *p_cur; p_cur = &(*p_cur)->next) {
for (cblist = statecbs; cblist; cblist = cblist->next) { if ((*p_cur)->callback == callback)
if (cblist->callback == callback) { break;
if (!cbprev)
statecbs = cblist->next;
else
cbprev->next = cblist->next;
free(cblist);
AST_LIST_UNLOCK(&hints);
return 0;
}
cbprev = cblist;
} }
} else { /* callback with extension, find the callback based on ID */
AST_LIST_UNLOCK(&hints); struct ast_hint *hint;
return -1; AST_LIST_TRAVERSE(&hints, hint, list) {
} for (p_cur = &hint->callbacks; *p_cur; p_cur = &(*p_cur)->next) {
if ((*p_cur)->id == id)
/* id greater than zero is a callback with extension */ break;
/* Find the callback based on ID */ }
AST_LIST_TRAVERSE(&hints, hint, list) { if (*p_cur) /* found in the inner loop */
cbprev = NULL; break;
for (cblist = hint->callbacks; cblist; cblist = cblist->next) {
if (cblist->id==id) {
if (!cbprev)
hint->callbacks = cblist->next;
else
cbprev->next = cblist->next;
free(cblist);
AST_LIST_UNLOCK(&hints);
return 0;
}
cbprev = cblist;
} }
} }
if (p_cur && *p_cur) {
struct ast_state_cb *cur = *p_cur;
*p_cur = cur->next;
free(cur);
ret = 0;
}
AST_LIST_UNLOCK(&hints); AST_LIST_UNLOCK(&hints);
return -1; return ret;
} }
/*! \brief ast_add_hint: Add hint to hint list, check initial extension state */ /*! \brief ast_add_hint: Add hint to hint list, check initial extension state */
@ -2022,8 +2003,11 @@ static int __ast_pbx_run(struct ast_channel *c)
int autoloopflag; int autoloopflag;
/* 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);
/* XXX and now what ? */
free(c->pbx);
}
if (!(c->pbx = ast_calloc(1, sizeof(*c->pbx)))) if (!(c->pbx = ast_calloc(1, sizeof(*c->pbx))))
return -1; return -1;
if (c->amaflags) { if (c->amaflags) {
@ -2041,7 +2025,7 @@ static int __ast_pbx_run(struct ast_channel *c)
c->pbx->rtimeout = 10; c->pbx->rtimeout = 10;
c->pbx->dtimeout = 5; c->pbx->dtimeout = 5;
autoloopflag = ast_test_flag(c, AST_FLAG_IN_AUTOLOOP); autoloopflag = ast_test_flag(c, AST_FLAG_IN_AUTOLOOP); /* save value to restore at the end */
ast_set_flag(c, AST_FLAG_IN_AUTOLOOP); ast_set_flag(c, AST_FLAG_IN_AUTOLOOP);
/* Start by trying whatever the channel is set to */ /* Start by trying whatever the channel is set to */

Loading…
Cancel
Save