int (*execute)(struct ast_channel *chan, void *data);
const char *synopsis; /*!< Synopsis text for 'show applications' */
const char *description; /*!< Description (help text) for 'show application <name>' */
- AST_LIST_ENTRY(ast_app) list; /*!< Next app in list */
+ AST_RWLIST_ENTRY(ast_app) list; /*!< Next app in list */
struct module *module; /*!< Module this app belongs to */
char name[0]; /*!< Name of the application */
};
struct ast_exten *exten; /*!< Extension */
int laststate; /*!< Last known state */
struct ast_state_cb *callbacks; /*!< Callback list for this extension */
- AST_LIST_ENTRY(ast_hint) list; /*!< Pointer to next hint in list */
+ AST_RWLIST_ENTRY(ast_hint) list;/*!< Pointer to next hint in list */
};
static const struct cfextension_states {
AST_MUTEX_DEFINE_STATIC(maxcalllock);
static int countcalls = 0;
-static AST_LIST_HEAD_STATIC(acf_root, ast_custom_function);
+static AST_RWLIST_HEAD_STATIC(acf_root, ast_custom_function);
/*! \brief Declaration of builtin applications */
static struct pbx_builtin {
static struct ast_context *contexts = NULL;
AST_MUTEX_DEFINE_STATIC(conlock); /*!< Lock for the ast_context list */
-static AST_LIST_HEAD_STATIC(apps, ast_app);
+static AST_RWLIST_HEAD_STATIC(apps, ast_app);
static AST_LIST_HEAD_STATIC(switches, ast_switch);
function will take the locks in conlock/hints order, so any other
paths that require both locks must also take them in that order.
*/
-static AST_LIST_HEAD_STATIC(hints, ast_hint);
+static AST_RWLIST_HEAD_STATIC(hints, ast_hint);
struct ast_state_cb *statecbs = NULL;
/*
{
struct ast_app *tmp;
- AST_LIST_LOCK(&apps);
- AST_LIST_TRAVERSE(&apps, tmp, list) {
+ AST_RWLIST_RDLOCK(&apps);
+ AST_RWLIST_TRAVERSE(&apps, tmp, list) {
if (!strcasecmp(tmp->name, app))
break;
}
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
return tmp;
}
ast_cli(fd, "%s Custom Functions:\n--------------------------------------------------------------------------------\n", like ? "Matching" : "Installed");
- AST_LIST_LOCK(&acf_root);
- AST_LIST_TRAVERSE(&acf_root, acf, acflist) {
+ AST_RWLIST_RDLOCK(&acf_root);
+ AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
if (!like || strstr(acf->name, argv[4])) {
count_acf++;
ast_cli(fd, "%-20.20s %-35.35s %s\n", acf->name, acf->syntax, acf->synopsis);
}
}
- AST_LIST_UNLOCK(&acf_root);
+ AST_RWLIST_UNLOCK(&acf_root);
ast_cli(fd, "%d %scustom functions installed.\n", count_acf, like ? "matching " : "");
int wordlen = strlen(word);
/* case-insensitive for convenience in this 'complete' function */
- AST_LIST_LOCK(&acf_root);
- AST_LIST_TRAVERSE(&acf_root, acf, acflist) {
+ AST_RWLIST_RDLOCK(&acf_root);
+ AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
if (!strncasecmp(word, acf->name, wordlen) && ++which > state) {
ret = strdup(acf->name);
break;
}
}
- AST_LIST_UNLOCK(&acf_root);
+ AST_RWLIST_UNLOCK(&acf_root);
return ret;
}
{
struct ast_custom_function *acf = NULL;
- AST_LIST_LOCK(&acf_root);
- AST_LIST_TRAVERSE(&acf_root, acf, acflist) {
+ AST_RWLIST_RDLOCK(&acf_root);
+ AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
if (!strcmp(name, acf->name))
break;
}
- AST_LIST_UNLOCK(&acf_root);
+ AST_RWLIST_UNLOCK(&acf_root);
return acf;
}
if (!acf)
return -1;
- AST_LIST_LOCK(&acf_root);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
+ AST_RWLIST_WRLOCK(&acf_root);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
if (cur == acf) {
- AST_LIST_REMOVE_CURRENT(&acf_root, acflist);
+ AST_RWLIST_REMOVE_CURRENT(&acf_root, acflist);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Unregistered custom function %s\n", acf->name);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
- AST_LIST_UNLOCK(&acf_root);
+ AST_RWLIST_TRAVERSE_SAFE_END
+ AST_RWLIST_UNLOCK(&acf_root);
return acf ? 0 : -1;
}
if (!acf)
return -1;
- AST_LIST_LOCK(&acf_root);
+ AST_RWLIST_WRLOCK(&acf_root);
- if (ast_custom_function_find(acf->name)) {
- ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
- AST_LIST_UNLOCK(&acf_root);
- return -1;
+ AST_RWLIST_TRAVERSE(&acf_root, cur, acflist) {
+ if (!strcmp(acf->name, cur->name)) {
+ ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
+ AST_RWLIST_UNLOCK(&acf_root);
+ return -1;
+ }
}
/* Store in alphabetical order */
- AST_LIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
if (strcasecmp(acf->name, cur->name) < 0) {
- AST_LIST_INSERT_BEFORE_CURRENT(&acf_root, acf, acflist);
+ AST_RWLIST_INSERT_BEFORE_CURRENT(&acf_root, acf, acflist);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
+ AST_RWLIST_TRAVERSE_SAFE_END
if (!cur)
- AST_LIST_INSERT_TAIL(&acf_root, acf, acflist);
+ AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist);
- AST_LIST_UNLOCK(&acf_root);
+ AST_RWLIST_UNLOCK(&acf_root);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Registered custom function %s\n", acf->name);
{
struct ast_hint *hint;
- AST_LIST_LOCK(&hints);
+ AST_RWLIST_RDLOCK(&hints);
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
struct ast_state_cb *cblist;
char buf[AST_MAX_EXTENSION];
char *parse = buf;
hint->laststate = state; /* record we saw the change */
}
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
}
/*! \brief ast_extension_state_add: Add watcher for extension states */
/* If there's no context and extension: add callback to statecbs list */
if (!context && !exten) {
- AST_LIST_LOCK(&hints);
+ AST_RWLIST_WRLOCK(&hints);
for (cblist = statecbs; cblist; cblist = cblist->next) {
if (cblist->callback == callback) {
cblist->data = data;
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return 0;
}
}
/* Now insert the callback */
if (!(cblist = ast_calloc(1, sizeof(*cblist)))) {
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return -1;
}
cblist->id = 0;
cblist->next = statecbs;
statecbs = cblist;
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return 0;
}
}
/* Find the hint in the list of hints */
- AST_LIST_LOCK(&hints);
+ AST_RWLIST_WRLOCK(&hints);
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
if (hint->exten == e)
break;
}
if (!hint) {
/* We have no hint, sorry */
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return -1;
}
/* Now insert the callback in the callback list */
if (!(cblist = ast_calloc(1, sizeof(*cblist)))) {
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return -1;
}
cblist->id = stateid++; /* Unique ID for this callback */
cblist->next = hint->callbacks;
hint->callbacks = cblist;
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return cblist->id;
}
if (!id && !callback)
return -1;
- AST_LIST_LOCK(&hints);
+ AST_RWLIST_WRLOCK(&hints);
if (!id) { /* id == 0 is a callback without extension */
for (p_cur = &statecbs; *p_cur; p_cur = &(*p_cur)->next) {
}
} else { /* callback with extension, find the callback based on ID */
struct ast_hint *hint;
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
for (p_cur = &hint->callbacks; *p_cur; p_cur = &(*p_cur)->next) {
if ((*p_cur)->id == id)
break;
free(cur);
ret = 0;
}
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return ret;
}
if (!e)
return -1;
- AST_LIST_LOCK(&hints);
+ AST_RWLIST_WRLOCK(&hints);
/* Search if hint exists, do nothing */
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
if (hint->exten == e) {
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
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));
return -1;
ast_log(LOG_DEBUG, "HINTS: Adding hint %s: %s\n", ast_get_extension_name(e), ast_get_extension_app(e));
if (!(hint = ast_calloc(1, sizeof(*hint)))) {
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return -1;
}
/* Initialize and insert new item at the top */
hint->exten = e;
hint->laststate = ast_extension_state2(e);
- AST_LIST_INSERT_HEAD(&hints, hint, list);
+ AST_RWLIST_INSERT_HEAD(&hints, hint, list);
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return 0;
}
struct ast_hint *hint;
int res = -1;
- AST_LIST_LOCK(&hints);
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_WRLOCK(&hints);
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
if (hint->exten == oe) {
hint->exten = ne;
res = 0;
break;
}
}
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return res;
}
if (!e)
return -1;
- AST_LIST_LOCK(&hints);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&hints, hint, list) {
+ AST_RWLIST_WRLOCK(&hints);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&hints, hint, list) {
if (hint->exten == e) {
cbprev = NULL;
cblist = hint->callbacks;
free(cbprev);
}
hint->callbacks = NULL;
- AST_LIST_REMOVE_CURRENT(&hints, list);
+ AST_RWLIST_REMOVE_CURRENT(&hints, list);
free(hint);
res = 0;
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_TRAVERSE_SAFE_END
+ AST_RWLIST_UNLOCK(&hints);
return res;
}
char tmps[80];
int length;
- AST_LIST_LOCK(&apps);
- AST_LIST_TRAVERSE(&apps, tmp, list) {
+ AST_RWLIST_WRLOCK(&apps);
+ AST_RWLIST_TRAVERSE(&apps, tmp, list) {
if (!strcasecmp(app, tmp->name)) {
ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
return -1;
}
}
length = sizeof(*tmp) + strlen(app) + 1;
if (!(tmp = ast_calloc(1, length))) {
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
return -1;
}
tmp->description = description;
/* Store in alphabetical order */
- AST_LIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
if (strcasecmp(tmp->name, cur->name) < 0) {
- AST_LIST_INSERT_BEFORE_CURRENT(&apps, tmp, list);
+ AST_RWLIST_INSERT_BEFORE_CURRENT(&apps, tmp, list);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
+ AST_RWLIST_TRAVERSE_SAFE_END
if (!cur)
- AST_LIST_INSERT_TAIL(&apps, tmp, list);
+ AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
return 0;
}
int wordlen = strlen(word);
/* return the n-th [partial] matching entry */
- AST_LIST_LOCK(&apps);
- AST_LIST_TRAVERSE(&apps, a, list) {
+ AST_RWLIST_RDLOCK(&apps);
+ AST_RWLIST_TRAVERSE(&apps, a, list) {
if (!strncasecmp(word, a->name, wordlen) && ++which > state) {
ret = strdup(a->name);
break;
}
}
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
return ret;
}
return RESULT_SHOWUSAGE;
/* ... go through all applications ... */
- AST_LIST_LOCK(&apps);
- AST_LIST_TRAVERSE(&apps, a, list) {
+ AST_RWLIST_RDLOCK(&apps);
+ AST_RWLIST_TRAVERSE(&apps, a, list) {
/* ... compare this application name with all arguments given
* to 'show application' command ... */
for (app = 3; app < argc; app++) {
}
}
}
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
/* we found at least one app? no? */
if (no_registered_app) {
int watchers;
struct ast_state_cb *watcher;
- if (AST_LIST_EMPTY(&hints)) {
+ AST_RWLIST_RDLOCK(&hints);
+ if (AST_RWLIST_EMPTY(&hints)) {
ast_cli(fd, "There are no registered dialplan hints\n");
+ AST_RWLIST_UNLOCK(&hints);
return RESULT_SUCCESS;
}
/* ... we have hints ... */
ast_cli(fd, "\n -= Registered Asterisk Dial Plan Hints =-\n");
- AST_LIST_LOCK(&hints);
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
watchers = 0;
for (watcher = hint->callbacks; watcher; watcher = watcher->next)
watchers++;
}
ast_cli(fd, "----------------\n");
ast_cli(fd, "- %d hints registered\n", num);
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
return RESULT_SUCCESS;
}
int total_match = 0; /* Number of matches in like clause */
int total_apps = 0; /* Number of apps registered */
- AST_LIST_LOCK(&apps);
+ AST_RWLIST_RDLOCK(&apps);
- if (AST_LIST_EMPTY(&apps)) {
+ if (AST_RWLIST_EMPTY(&apps)) {
ast_cli(fd, "There are no registered applications\n");
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
return -1;
}
ast_cli(fd, " -= Matching Asterisk Applications =-\n");
}
- AST_LIST_TRAVERSE(&apps, a, list) {
+ AST_RWLIST_TRAVERSE(&apps, a, list) {
int printapp = 0;
total_apps++;
if (like) {
ast_cli(fd, " -= %d Applications Matching =-\n",total_match);
}
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_UNLOCK(&apps);
return RESULT_SUCCESS;
}
{
struct ast_app *tmp;
- AST_LIST_LOCK(&apps);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
+ AST_RWLIST_WRLOCK(&apps);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
if (!strcasecmp(app, tmp->name)) {
unreference_cached_app(tmp);
- AST_LIST_REMOVE_CURRENT(&apps, list);
+ AST_RWLIST_REMOVE_CURRENT(&apps, list);
if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Unregistered application '%s'\n", tmp->name);
free(tmp);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
- AST_LIST_UNLOCK(&apps);
+ AST_RWLIST_TRAVERSE_SAFE_END
+ AST_RWLIST_UNLOCK(&apps);
return tmp ? 0 : -1;
}
other code paths that use this order
*/
ast_mutex_lock(&conlock);
- AST_LIST_LOCK(&hints);
+ AST_RWLIST_WRLOCK(&hints);
/* preserve all watchers for hints associated with this registrar */
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
if (hint->callbacks && !strcmp(registrar, hint->exten->parent->registrar)) {
length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2 + sizeof(*this);
if (!(this = ast_calloc(1, length)))
while ((this = AST_LIST_REMOVE_HEAD(&store, list))) {
exten = ast_hint_extension(NULL, this->context, this->exten);
/* Find the hint in the list of hints */
- AST_LIST_TRAVERSE(&hints, hint, list) {
+ AST_RWLIST_TRAVERSE(&hints, hint, list) {
if (hint->exten == exten)
break;
}
free(this);
}
- AST_LIST_UNLOCK(&hints);
+ AST_RWLIST_UNLOCK(&hints);
ast_mutex_unlock(&conlock);
return;