more code restructuring

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@25746 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo
2006-05-08 22:06:50 +00:00
parent 3a9bd2a478
commit a8379be554

93
pbx.c
View File

@@ -4766,63 +4766,56 @@ static void destroy_exten(struct ast_exten *e)
void __ast_context_destroy(struct ast_context *con, const char *registrar) void __ast_context_destroy(struct ast_context *con, const char *registrar)
{ {
struct ast_context *tmp, *tmpl=NULL; struct ast_context *tmp, *tmpl=NULL;
struct ast_include *tmpi, *tmpil= NULL; struct ast_include *tmpi;
struct ast_sw *sw; struct ast_sw *sw;
struct ast_exten *e, *el, *en; struct ast_exten *e, *el, *en;
struct ast_ignorepat *ipi, *ipl = NULL; struct ast_ignorepat *ipi;
ast_mutex_lock(&conlock); ast_mutex_lock(&conlock);
tmp = contexts; for (tmp = contexts; tmp; ) {
while(tmp) { struct ast_context *next; /* next starting point */
if (((tmp->name && con && con->name && !strcasecmp(tmp->name, con->name)) || !con) && for (; tmp; tmpl = tmp, tmp = tmp->next) {
(!registrar || !strcasecmp(registrar, tmp->registrar))) { if ( (!registrar || !strcasecmp(registrar, tmp->registrar)) &&
/* Okay, let's lock the structure to be sure nobody else (!con || !strcasecmp(tmp->name, con->name)) )
is searching through it. */ break; /* found it */
ast_mutex_lock(&tmp->lock); }
if (tmpl) if (!tmp) /* not found, we are done */
tmpl->next = tmp->next; break;
else ast_mutex_lock(&tmp->lock);
contexts = tmp->next; next = tmp->next;
/* Okay, now we're safe to let it go -- in a sense, we were if (tmpl)
ready to let it go as soon as we locked it. */ tmpl->next = next;
ast_mutex_unlock(&tmp->lock); else
for (tmpi = tmp->includes; tmpi; ) { contexts = next;
/* Free includes */ /* Okay, now we're safe to let it go -- in a sense, we were
tmpil = tmpi; ready to let it go as soon as we locked it. */
tmpi = tmpi->next; ast_mutex_unlock(&tmp->lock);
free(tmpil); for (tmpi = tmp->includes; tmpi; ) { /* Free includes */
} struct ast_include *tmpil = tmpi;
for (ipi = tmp->ignorepats; ipi; ) { tmpi = tmpi->next;
/* Free ignorepats */ free(tmpil);
ipl = ipi; }
ipi = ipi->next; for (ipi = tmp->ignorepats; ipi; ) { /* Free ignorepats */
free(ipl); struct ast_ignorepat *ipl = ipi;
} ipi = ipi->next;
while ((sw = AST_LIST_REMOVE_HEAD(&tmp->alts, list))) free(ipl);
free(sw); }
for (e = tmp->root; e;) { while ((sw = AST_LIST_REMOVE_HEAD(&tmp->alts, list)))
for (en = e->peer; en;) { free(sw);
el = en; for (e = tmp->root; e;) {
en = en->peer; for (en = e->peer; en;) {
destroy_exten(el); el = en;
} en = en->peer;
el = e;
e = e->next;
destroy_exten(el); destroy_exten(el);
} }
ast_mutex_destroy(&tmp->lock); el = e;
free(tmp); e = e->next;
if (!con) { destroy_exten(el);
/* Might need to get another one -- restart */
tmp = contexts;
tmpl = NULL;
tmpil = NULL;
continue;
}
break;
} }
tmpl = tmp; ast_mutex_destroy(&tmp->lock);
tmp = tmp->next; free(tmp);
/* if we have a specific match, we are done, otherwise continue */
tmp = con ? NULL : next;
} }
ast_mutex_unlock(&conlock); ast_mutex_unlock(&conlock);
} }