struct ast_context;
-/*!\brief ast_exten: An extension
+/*!
+ \brief ast_exten: An extension
The dialplan is saved as a linked list with each context
having it's own linked list of extensions - one item per
priority.
*/
struct ast_exten {
- char *exten; /* Extension name */
- int matchcid; /* Match caller id ? */
- char *cidmatch; /* Caller id to match for this extension */
- int priority; /* Priority */
- char *label; /* Label */
- struct ast_context *parent; /* The context this extension belongs to */
- char *app; /* Application to execute */
- void *data; /* Data to use (arguments) */
- void (*datad)(void *); /* Data destructor */
- struct ast_exten *peer; /* Next higher priority with our extension */
- const char *registrar; /* Registrar */
- struct ast_exten *next; /* Extension with a greater ID */
+ char *exten; /*!< Extension name */
+ int matchcid; /*!< Match caller id ? */
+ char *cidmatch; /*!< Caller id to match for this extension */
+ int priority; /*!< Priority */
+ char *label; /*!< Label */
+ struct ast_context *parent; /*!< The context this extension belongs to */
+ char *app; /*!< Application to execute */
+ void *data; /*!< Data to use (arguments) */
+ void (*datad)(void *); /*!< Data destructor */
+ struct ast_exten *peer; /*!< Next higher priority with our extension */
+ const char *registrar; /*!< Registrar */
+ struct ast_exten *next; /*!< Extension with a greater ID */
char stuff[0];
};
/*! \brief ast_include: include= support in extensions.conf */
struct ast_include {
char *name;
- char *rname; /* Context to include */
- const char *registrar; /* Registrar */
- int hastime; /* If time construct exists */
- struct ast_timing timing; /* time construct */
- struct ast_include *next; /* Link them together */
+ char *rname; /*!< Context to include */
+ const char *registrar; /*!< Registrar */
+ int hastime; /*!< If time construct exists */
+ struct ast_timing timing; /*!< time construct */
+ struct ast_include *next; /*!< Link them together */
char stuff[0];
};
/*! \brief ast_sw: Switch statement in extensions.conf */
struct ast_sw {
char *name;
- const char *registrar; /* Registrar */
- char *data; /* Data load */
+ const char *registrar; /*!< Registrar */
+ char *data; /*!< Data load */
int eval;
- struct ast_sw *next; /* Link them together */
+ struct ast_sw *next; /*!< Link them together */
char *tmpdata;
char stuff[0];
};
/*! \brief ast_app: A registered application */
struct ast_app {
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>' */
- struct ast_app *next; /* Next app in list */
- char name[0]; /* Name of the application */
+ const char *synopsis; /*!< Synopsis text for 'show applications' */
+ const char *description; /*!< Description (help text) for 'show application <name>' */
+ struct ast_app *next; /*!< Next app in list */
+ char name[0]; /*!< Name of the application */
};
/*! \brief ast_state_cb: An extension state notify register item */
};
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;
-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;
-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;
struct ast_hint *hints = NULL;
struct ast_state_cb *statecbs = NULL;
ast_log(LOG_WARNING, "Unable to obtain application lock\n");
return NULL;
}
- tmp = apps;
- while(tmp) {
+ for (tmp = apps; tmp; tmp = tmp->next) {
if (!strcasecmp(tmp->name, app))
break;
- tmp = tmp->next;
}
ast_mutex_unlock(&applock);
return tmp;
ast_log(LOG_WARNING, "Unable to obtain application lock\n");
return NULL;
}
- asw = switches;
- while(asw) {
+ for (asw = switches; asw; asw = asw->next) {
if (!strcasecmp(asw->name, sw))
break;
- asw = asw->next;
}
ast_mutex_unlock(&switchlock);
return asw;
struct ast_context *tmp;
ast_mutex_lock(&conlock);
if (name) {
- tmp = contexts;
- while(tmp) {
+ for (tmp = contexts; tmp; tmp = tmp->next) {
if (!strcasecmp(name, tmp->name))
break;
- tmp = tmp->next;
}
} else
tmp = contexts;
return NULL;
}
/* Check first to see if we've already been checked */
- for (x=0; x<*stacklen; x++) {
+ for (x = 0; x < *stacklen; x++) {
if (!strcasecmp(incstack[x], context))
return NULL;
}
tmp = bypass;
else
tmp = contexts;
- while(tmp) {
+ for (; tmp; tmp = tmp->next) {
/* Match context */
if (bypass || !strcmp(tmp->name, context)) {
struct ast_exten *earlymatch = NULL;
if (*status < STATUS_NO_EXTENSION)
*status = STATUS_NO_EXTENSION;
- for (eroot = tmp->root; eroot; eroot=eroot->next) {
+ for (eroot = tmp->root; eroot; eroot = eroot->next) {
int match = 0;
/* Match extension */
if ((((action != HELPER_MATCHMORE) && ast_extension_match(eroot->exten, exten)) ||
((action == HELPER_CANMATCH) && (ast_extension_close(eroot->exten, exten, 0))) ||
((action == HELPER_MATCHMORE) && (match = ast_extension_close(eroot->exten, exten, 1)))) &&
- (!eroot->matchcid || matchcid(eroot->cidmatch, callerid))) {
+ (!eroot->matchcid || matchcid(eroot->cidmatch, callerid))) {
if (action == HELPER_MATCHMORE && match == 2 && !earlymatch) {
/* It matched an extension ending in a '!' wildcard
So ignore it for now, unless there's a better match */
earlymatch = eroot;
} else {
- e = eroot;
if (*status < STATUS_NO_PRIORITY)
*status = STATUS_NO_PRIORITY;
- while(e) {
+ for (e = eroot; e; e = e->peer) {
/* Match priority */
if (action == HELPER_FINDLABEL) {
if (*status < STATUS_NO_LABEL)
*foundcontext = context;
return e;
}
- e = e->peer;
}
}
}
return NULL;
}
/* Check alternative switches */
- sw = tmp->alts;
- while(sw) {
+ for (sw = tmp->alts; sw; sw = sw->next) {
if ((asw = pbx_findswitch(sw->name))) {
/* Substitute variables now */
if (sw->eval)
} else {
ast_log(LOG_WARNING, "No such switch '%s'\n", sw->name);
}
- sw = sw->next;
}
/* Setup the stack */
incstack[*stacklen] = tmp->name;
(*stacklen)++;
/* Now try any includes we have in this context */
- i = tmp->includes;
- while(i) {
+ for (i = tmp->includes; i; i = i->next) {
if (include_valid(i)) {
if ((e = pbx_find_extension(chan, bypass, i->rname, exten, priority, label, callerid, action, incstack, stacklen, status, swo, data, foundcontext)))
return e;
if (*swo)
return NULL;
}
- i = i->next;
}
break;
}
- tmp = tmp->next;
}
return NULL;
}
*offset = 0;
*length = DONT_HAVE_LENGTH;
*isfunc = 0;
- for (varchar=var; *varchar; varchar++) {
+ for (varchar = var; *varchar; varchar++) {
switch (*varchar) {
case '(':
(*isfunc)++;
{
struct ast_custom_function *acf;
int which = 0;
+ int wordlen;
+
+ wordlen = strlen(word);
/* try to lock functions list ... */
if (ast_mutex_lock(&acflock)) {
return NULL;
}
- acf = acf_root;
- while (acf) {
- if (!strncasecmp(word, acf->name, strlen(word))) {
+ for (acf = acf_root; acf; acf = acf->next) {
+ if (!strncasecmp(word, acf->name, wordlen)) {
if (++which > state) {
char *ret = strdup(acf->name);
ast_mutex_unlock(&acflock);
return ret;
}
}
- acf = acf->next;
}
ast_mutex_unlock(&acflock);
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;
return -1;
}
default:
- ast_log(LOG_WARNING, "Huh (%d)?\n", action); return -1;
+ ast_log(LOG_WARNING, "Huh (%d)?\n", action);
+ return -1;
}
} else if (sw) {
switch(action) {
if (!context && !exten) {
ast_mutex_lock(&hintlock);
- cblist = statecbs;
- while (cblist) {
+ for (cblist = statecbs; cblist; cblist = cblist->next) {
if (cblist->callback == callback) {
cblist->data = data;
ast_mutex_unlock(&hintlock);
return 0;
}
- cblist = cblist->next;
}
/* Now insert the callback */
- cblist = malloc(sizeof(struct ast_state_cb));
+ cblist = calloc(1, 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;
/* Find the hint in the list of hints */
ast_mutex_lock(&hintlock);
- list = hints;
-
- while (list) {
+
+ for (list = hints; list; list = list->next) {
if (list->exten == e)
break;
- list = list->next;
}
if (!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) {
ast_mutex_unlock(&hintlock);
return -1;
}
- memset(cblist, 0, sizeof(struct ast_state_cb));
cblist->id = stateid++; /* Unique ID for this callback */
cblist->callback = callback; /* Pointer to callback routine */
cblist->data = data; /* Data for the callback */
/* id is zero is a callback without extension */
if (!id) {
cbprev = NULL;
- cblist = statecbs;
- while (cblist) {
+ for (cblist = statecbs; cblist; cblist = cblist->next) {
if (cblist->callback == callback) {
if (!cbprev)
statecbs = cblist->next;
return 0;
}
cbprev = cblist;
- cblist = cblist->next;
}
ast_mutex_lock(&hintlock);
/* id greater than zero is a callback with extension */
/* Find the callback based on ID */
- list = hints;
- while (list) {
- cblist = list->callbacks;
+ for (list = hints; list; list = list->next) {
cbprev = NULL;
- while (cblist) {
+ for (cblist = list->callbacks; cblist; cblist = cblist->next) {
if (cblist->id==id) {
if (!cbprev)
list->callbacks = cblist->next;
return 0;
}
cbprev = cblist;
- cblist = cblist->next;
}
- list = list->next;
}
ast_mutex_unlock(&hintlock);
return -1;
ast_mutex_lock(&hintlock);
- list = hints;
/* Search if hint exists, do nothing */
- while (list) {
+ for (list = hints; list; list = list->next) {
if (list->exten == e) {
ast_mutex_unlock(&hintlock);
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;
}
- list = list->next;
}
if (option_debug > 1)
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) {
ast_mutex_unlock(&hintlock);
if (option_debug > 1)
return -1;
}
/* Initialize and insert new item at the top */
- memset(list, 0, sizeof(struct ast_hint));
list->exten = e;
list->laststate = ast_extension_state2(e);
list->next = hints;
struct ast_hint *list;
ast_mutex_lock(&hintlock);
- list = hints;
- while(list) {
+ for (list = hints; list; list = list->next) {
if (list->exten == oe) {
list->exten = ne;
ast_mutex_unlock(&hintlock);
return 0;
}
- list = list->next;
}
+
ast_mutex_unlock(&hintlock);
return -1;
ast_mutex_lock(&hintlock);
- list = hints;
- while(list) {
- if (list->exten==e) {
+ for (list = hints; list; list = list->next) {
+ if (list->exten == e) {
cbprev = NULL;
cblist = list->callbacks;
while (cblist) {
ast_mutex_unlock(&hintlock);
return 0;
- } else {
- prev = list;
- list = list->next;
}
+ prev = list;
}
ast_mutex_unlock(&hintlock);
if (tmp)
ast_copy_string(name, (char *) tmp, namesize);
}
- return -1;
+ return -1;
}
return 0;
}
/* 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));
+ c->pbx = calloc(1, sizeof(struct ast_pbx));
if (!c->pbx) {
ast_log(LOG_ERROR, "Out of memory\n");
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;
}
if (c->cdr && !c->cdr->start.tv_sec && !c->cdr->start.tv_usec)
ast_cdr_start(c->cdr);
- for(;;) {
+ for (;;) {
pos = 0;
digit = 0;
- while(ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
+ while (ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
memset(exten, 0, sizeof(exten));
if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
/* Something bad happened, or a hangup has been requested. */
if (ast_lock_contexts()) return -1;
/* walk contexts and search for the right one ...*/
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
/* we found one ... */
if (!strcmp(ast_get_context_name(c), context)) {
int ret;
/* ... return results */
return ret;
}
- c = ast_walk_contexts(c);
}
/* we can't find the right one context */
if (ast_mutex_lock(&con->lock)) return -1;
/* walk includes */
- i = con->includes;
- while (i) {
+ for (i = con->includes; i; i = i->next) {
/* find our include */
if (!strcmp(i->name, include) &&
(!registrar || !strcmp(i->registrar, registrar))) {
return 0;
}
pi = i;
- i = i->next;
}
/* we can't find the right include */
if (ast_lock_contexts()) return -1;
/* walk contexts and search for the right one ...*/
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
/* we found one ... */
if (!strcmp(ast_get_context_name(c), context)) {
int ret;
/* ... return results */
return ret;
}
- c = ast_walk_contexts(c);
}
/* we can't find the right one context */
if (ast_mutex_lock(&con->lock)) return -1;
/* walk switchs */
- i = con->alts;
- while (i) {
+ for (i = con->alts; i; i = i->next) {
/* find our switch */
if (!strcmp(i->name, sw) && !strcmp(i->data, data) &&
(!registrar || !strcmp(i->registrar, registrar))) {
return 0;
}
pi = i;
- i = i->next;
}
/* we can't find the right switch */
if (ast_lock_contexts()) return -1;
/* walk contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
/* ... search for the right one ... */
if (!strcmp(ast_get_context_name(c), context)) {
/* ... remove extension ... */
ast_unlock_contexts();
return ret;
}
- c = ast_walk_contexts(c);
}
/* we can't find the right context */
ast_log(LOG_ERROR, "Unable to lock application list\n");
return -1;
}
- tmp = apps;
- while(tmp) {
+ for (tmp = apps; tmp; tmp = tmp->next) {
if (!strcasecmp(app, tmp->name)) {
ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
ast_mutex_unlock(&applock);
return -1;
}
- tmp = tmp->next;
}
- tmp = malloc(length);
- if (tmp) {
- memset(tmp, 0, length);
- strcpy(tmp->name, app);
- tmp->execute = execute;
- tmp->synopsis = synopsis;
- tmp->description = description;
- /* Store in alphabetical order */
- cur = apps;
- prev = NULL;
- while(cur) {
- if (strcasecmp(tmp->name, cur->name) < 0)
- break;
- prev = cur;
- cur = cur->next;
- }
- if (prev) {
- tmp->next = prev->next;
- prev->next = tmp;
- } else {
- tmp->next = apps;
- apps = tmp;
- }
- } else {
+
+ tmp = calloc(1, length);
+ if (!tmp) {
ast_log(LOG_ERROR, "Out of memory\n");
ast_mutex_unlock(&applock);
return -1;
}
+
+ strcpy(tmp->name, app);
+ tmp->execute = execute;
+ tmp->synopsis = synopsis;
+ tmp->description = description;
+ /* Store in alphabetical order */
+ prev = NULL;
+ for (cur = apps; cur; cur = cur->next) {
+ if (strcasecmp(tmp->name, cur->name) < 0)
+ break;
+ prev = cur;
+ }
+ if (prev) {
+ tmp->next = prev->next;
+ prev->next = tmp;
+ } else {
+ tmp->next = apps;
+ apps = tmp;
+ }
+
if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
ast_mutex_unlock(&applock);
ast_log(LOG_ERROR, "Unable to lock switch lock\n");
return -1;
}
- tmp = switches;
- while(tmp) {
+ for (tmp = switches; tmp; tmp = tmp->next) {
if (!strcasecmp(tmp->name, sw->name))
break;
prev = tmp;
- tmp = tmp->next;
}
if (tmp) {
ast_mutex_unlock(&switchlock);
ast_log(LOG_ERROR, "Unable to lock switch lock\n");
return;
}
- tmp = switches;
- while(tmp) {
+ for (tmp = switches; tmp; tmp = tmp->next) {
if (tmp == sw) {
if (prev)
prev->next = tmp->next;
break;
}
prev = tmp;
- tmp = tmp->next;
}
ast_mutex_unlock(&switchlock);
}
}
/* ... walk all applications ... */
- a = apps;
- while (a) {
+ for (a = apps; a; a = a->next) {
/* ... check if word matches this application ... */
if (!strncasecmp(word, a->name, strlen(word))) {
/* ... if this is right app serve it ... */
return ret;
}
}
- a = a->next;
}
/* no application match */
}
/* ... go through all applications ... */
- a = apps;
- while (a) {
+ for (a = apps; a; a = a->next) {
/* ... compare this application name with all arguments given
* to 'show application' command ... */
for (app = 2; app < argc; app++) {
}
}
}
- a = a->next;
}
ast_mutex_unlock(&applock);
ast_log(LOG_ERROR, "Unable to lock hints\n");
return -1;
}
- hint = hints;
- while (hint) {
+ for (hint = hints; hint; hint = hint->next) {
watchers = 0;
for (watcher = hint->callbacks; watcher; watcher = watcher->next)
watchers++;
ast_get_extension_name(hint->exten), ast_get_extension_app(hint->exten),
ast_extension_state2str(hint->laststate), watchers);
num++;
- hint = hint->next;
}
ast_cli(fd, "----------------\n");
ast_cli(fd, "- %d hints registered\n", num);
ast_log(LOG_ERROR, "Unable to lock switches\n");
return -1;
}
- sw = switches;
- while (sw) {
+ for (sw = switches; sw; sw = sw->next) {
ast_cli(fd, "%s: %s\n", sw->name, sw->description);
- sw = sw->next;
}
ast_mutex_unlock(&switchlock);
return RESULT_SUCCESS;
static int handle_show_applications(int fd, int argc, char *argv[])
{
struct ast_app *a;
- int like=0, describing=0;
+ int like = 0, describing = 0;
int total_match = 0; /* Number of matches in like clause */
int total_apps = 0; /* Number of apps registered */
/* Match all words on command line */
int i;
printapp = 1;
- for (i=3; i<argc; i++) {
+ for (i = 3; i < argc; i++) {
if (!strcasestr(a->description, argv[i])) {
printapp = 0;
} else {
{
struct ast_context *c;
int which = 0;
+ int wordlen;
/* 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 ... */
if (ast_lock_contexts()) {
return NULL;
}
+ wordlen = strlen(word);
+
/* ... walk through all contexts ... */
- c = ast_walk_contexts(NULL);
- while(c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
/* ... 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? ... */
if (++which > state) {
/* ... yes, serve this context name ... */
return ret;
}
}
- c = ast_walk_contexts(c);
}
/* ... unlock and return */
static int show_dialplan_helper(int fd, char *context, char *exten, struct dialplan_counters *dpc, struct ast_include *rinclude, int includecount, char *includes[])
{
struct ast_context *c;
- int res=0, old_total_exten = dpc->total_exten;
+ int res = 0, old_total_exten = dpc->total_exten;
/* try to lock contexts */
if (ast_lock_contexts()) {
}
/* walk all contexts ... */
- for (c = ast_walk_contexts(NULL); c ; c = ast_walk_contexts(c)) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
/* show this context? */
if (!context ||
!strcmp(ast_get_context_name(c), context)) {
}
/* walk ignore patterns and write info ... */
- for (ip=ast_walk_context_ignorepats(c, NULL); ip; ip=ast_walk_context_ignorepats(c, ip)) {
+ for (ip = ast_walk_context_ignorepats(c, NULL); ip; ip = ast_walk_context_ignorepats(c, ip)) {
const char *ipname = ast_get_ignorepat_name(ip);
char ignorepat[AST_MAX_EXTENSION];
snprintf(buf, sizeof(buf), "'%s'", ipname);
ast_log(LOG_ERROR, "Unable to lock application list\n");
return -1;
}
- tmp = apps;
- while(tmp) {
+ for (tmp = apps; tmp; tmp = tmp->next) {
if (!strcasecmp(app, tmp->name)) {
if (tmpl)
tmpl->next = tmp->next;
return 0;
}
tmpl = tmp;
- tmp = tmp->next;
}
ast_mutex_unlock(&applock);
return -1;
} else
local_contexts = extcontexts;
- tmp = *local_contexts;
- while(tmp) {
+ for (tmp = *local_contexts; tmp; tmp = tmp->next) {
if (!strcasecmp(tmp->name, name)) {
ast_mutex_unlock(&conlock);
ast_log(LOG_WARNING, "Tried to register context '%s', already in use\n", name);
ast_mutex_unlock(&conlock);
return NULL;
}
- tmp = tmp->next;
}
- tmp = malloc(length);
+ tmp = calloc(1, length);
if (tmp) {
- memset(tmp, 0, length);
ast_mutex_init(&tmp->lock);
strcpy(tmp->name, name);
tmp->root = NULL;
}
/* walk contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
/* ... search for the right one ... */
if (!strcmp(ast_get_context_name(c), context)) {
int ret = ast_context_add_include2(c, include, registrar);
ast_unlock_contexts();
return ret;
}
- c = ast_walk_contexts(c);
}
/* we can't find the right context */
}
*e = '\0';
e++;
- while(*e && !isdigit(*e))
+ while (*e && !isdigit(*e))
e++;
if (!*e) {
ast_log(LOG_WARNING, "Invalid time range. Assuming no restrictions based on time.\n");
length += 2 * (strlen(value) + 1);
/* allocate new include structure ... */
- if (!(new_include = malloc(length))) {
+ if (!(new_include = calloc(1, length))) {
ast_log(LOG_ERROR, "Out of memory\n");
errno = ENOMEM;
return -1;
}
/* ... fill in this structure ... */
- memset(new_include, 0, length);
p = new_include->stuff;
new_include->name = p;
strcpy(new_include->name, value);
}
/* ... go to last include and check if context is already included too... */
- i = con->includes;
- while (i) {
+ for (i = con->includes; i; i = i->next) {
if (!strcasecmp(i->name, new_include->name)) {
free(new_include);
ast_mutex_unlock(&con->lock);
return -1;
}
il = i;
- i = i->next;
}
/* ... include new context into context list, unlock, return */
}
/* walk contexts ... */
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
/* ... search for the right one ... */
if (!strcmp(ast_get_context_name(c), context)) {
int ret = ast_context_add_switch2(c, sw, data, eval, registrar);
ast_unlock_contexts();
return ret;
}
- c = ast_walk_contexts(c);
}
/* we can't find the right context */
}
/* allocate new sw structure ... */
- if (!(new_sw = malloc(length))) {
+ if (!(new_sw = calloc(1, length))) {
ast_log(LOG_ERROR, "Out of memory\n");
errno = ENOMEM;
return -1;
}
/* ... fill in this structure ... */
- memset(new_sw, 0, length);
p = new_sw->stuff;
new_sw->name = p;
strcpy(new_sw->name, value);
}
/* ... go to last sw and check if context is already swd too... */
- i = con->alts;
- while (i) {
+ for (i = con->alts; i; i = i->next) {
if (!strcasecmp(i->name, new_sw->name) && !strcasecmp(i->data, new_sw->data)) {
free(new_sw);
ast_mutex_unlock(&con->lock);
return -1;
}
il = i;
- i = i->next;
}
/* ... sw new context into context list, unlock, return */
return -1;
}
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
if (!strcmp(ast_get_context_name(c), context)) {
int ret = ast_context_remove_ignorepat2(c, ignorepat, registrar);
ast_unlock_contexts();
return ret;
}
- c = ast_walk_contexts(c);
}
ast_unlock_contexts();
return -1;
}
- ip = con->ignorepats;
- while (ip) {
+ for (ip = con->ignorepats; ip; ip = ip->next) {
if (!strcmp(ip->pattern, ignorepat) &&
(!registrar || (registrar == ip->registrar))) {
if (ipl) {
ast_mutex_unlock(&con->lock);
return 0;
}
- ipl = ip; ip = ip->next;
+ ipl = ip;
}
ast_mutex_unlock(&con->lock);
return -1;
}
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
if (!strcmp(ast_get_context_name(c), con)) {
int ret = ast_context_add_ignorepat2(c, value, registrar);
ast_unlock_contexts();
return ret;
}
- c = ast_walk_contexts(c);
}
ast_unlock_contexts();
int length;
length = sizeof(struct ast_ignorepat);
length += strlen(value) + 1;
- ignorepat = malloc(length);
+ ignorepat = calloc(1, length);
if (!ignorepat) {
ast_log(LOG_ERROR, "Out of memory\n");
errno = ENOMEM;
return -1;
}
- memset(ignorepat, 0, length);
strcpy(ignorepat->pattern, value);
ignorepat->next = NULL;
ignorepat->registrar = registrar;
ast_mutex_lock(&con->lock);
- ignorepatc = con->ignorepats;
- while(ignorepatc) {
+ for (ignorepatc = con->ignorepats; ignorepatc; ignorepatc = ignorepatc->next) {
ignorepatl = ignorepatc;
if (!strcasecmp(ignorepatc->pattern, value)) {
/* Already there */
errno = EEXIST;
return -1;
}
- ignorepatc = ignorepatc->next;
}
if (ignorepatl)
ignorepatl->next = ignorepat;
con = ast_context_find(context);
if (con) {
- pat = con->ignorepats;
- while (pat) {
+ for (pat = con->ignorepats; pat; pat = pat->next) {
if (ast_extension_match(pat->pattern, pattern))
return 1;
- pat = pat->next;
}
}
return 0;
return -1;
}
- c = ast_walk_contexts(NULL);
- while (c) {
+ for (c = ast_walk_contexts(NULL); c; c = ast_walk_contexts(c)) {
if (!strcmp(context, ast_get_context_name(c))) {
int ret = ast_add_extension2(c, replace, extension, priority, label, callerid,
application, data, datad, registrar);
ast_unlock_contexts();
return ret;
}
- c = ast_walk_contexts(c);
}
ast_unlock_contexts();
{
int count=0;
- while(*src && (count < len - 1)) {
+ while (*src && (count < len - 1)) {
switch(*src) {
case ' ':
/* otherwise exten => [a-b],1,... doesn't work */
/* Be optimistic: Build the extension structure first */
if (datad == NULL)
datad = null_datad;
- tmp = malloc(length);
+ tmp = calloc(1, length);
if (tmp) {
- memset(tmp, 0, length);
p = tmp->stuff;
if (label) {
tmp->label = p;
errno = EBUSY;
return -1;
}
- e = con->root;
- while(e) {
+ for (e = con->root; e; e = e->next) {
/* Make sure patterns are always last! */
if ((e->exten[0] != '_') && (extension[0] == '_'))
res = -1;
}
el = e;
- e = e->next;
}
/* If we fall all the way through to here, then we need to be on the end. */
if (el)
struct ast_frame *f;
struct ast_app *app;
- while(timeout && (chan->_state != AST_STATE_UP)) {
+ while (timeout && (chan->_state != AST_STATE_UP)) {
res = ast_waitfor(chan, timeout);
if (res < 1)
break;
{
/* allocate a channel */
struct ast_channel *chan = ast_channel_alloc(0);
- if(!chan) {
+ if (!chan) {
/* allocation of the channel failed, let some peeps know */
ast_log(LOG_WARNING, "Unable to allocate channel structure for CDR record\n");
return -1; /* failure */
chan->cdr = ast_cdr_alloc(); /* allocate a cdr for the channel */
- if(!chan->cdr) {
+ if (!chan->cdr) {
/* allocation of the cdr failed */
ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
ast_channel_free(chan); /* free the channel */
{
/* Copy the AMA Flags as specified */
if (data)
- ast_cdr_setamaflags(chan, (char *)data);
+ ast_cdr_setamaflags(chan, data);
else
ast_cdr_setamaflags(chan, "");
return 0;
return -1;
}
- if ((s = ast_strdupa((char *) data))) {
+ if ((s = ast_strdupa(data))) {
ts = s;
/* Separate the Goto path */