summaryrefslogtreecommitdiff
path: root/pbx
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2016-07-14 14:51:42 -0400
committerCorey Farrell <git@cfware.com>2016-07-15 05:34:29 -0400
commitbe36bd7ca565531c09ca444e59b6d057131a9ab0 (patch)
tree85595a26df4bbfcfc39a78c5c2474984c8c894ce /pbx
parent273052f40498378d3f2d3548347a243df68ee9a4 (diff)
pbx: Create pbx_include.c for management of 'struct ast_include'.
This changes context includes from a linked list to a vector, makes 'struct ast_include' opaque to pbx.c. Although ast_walk_context_includes is maintained the procedure is no longer efficient except for the first call (inc==NULL). This functionality is replaced by two new functions implemented by vector macros. * ast_context_includes_count (AST_VECTOR_SIZE) * ast_context_includes_get (AST_VECTOR_GET) As with ast_walk_context_includes callers of these functions are expected to have locked contexts. Only a few places in Asterisk walked the includes, they have been converted to use the new functions. const have been applied where possible to parameters for ast_include functions. Change-Id: Ib5c882e27cf96fb2aec67a39c18b4c71c9c83b60
Diffstat (limited to 'pbx')
-rw-r--r--pbx/pbx_config.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c
index eb2a64f70..478c0a321 100644
--- a/pbx/pbx_config.c
+++ b/pbx/pbx_config.c
@@ -189,15 +189,25 @@ static char *handle_cli_dialplan_remove_include(struct ast_cli_entry *e, int cmd
/*! \brief return true if 'name' is included by context c */
static int lookup_ci(struct ast_context *c, const char *name)
{
- struct ast_include *i = NULL;
+ int idx;
+ int ret = 0;
- if (ast_rdlock_context(c)) /* error, skip */
+ if (ast_rdlock_context(c)) {
+ /* error, skip */
return 0;
- while ( (i = ast_walk_context_includes(c, i)) )
- if (!strcmp(name, ast_get_include_name(i)))
+ }
+
+ for (idx = 0; idx < ast_context_includes_count(c); idx++) {
+ const struct ast_include *i = ast_context_includes_get(c, idx);
+
+ if (!strcmp(name, ast_get_include_name(i))) {
+ ret = -1;
break;
+ }
+ }
ast_unlock_context(c);
- return i ? -1 /* success */ : 0;
+
+ return ret;
}
/*! \brief return true if 'name' is in the ignorepats for context c */
@@ -282,12 +292,13 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
}
/* walk contexts and their includes, return the n-th match */
while (!res && (c = ast_walk_contexts(c))) {
- struct ast_include *i = NULL;
+ int idx;
if (ast_rdlock_context(c)) /* error ? skip this one */
continue;
- while ( !res && (i = ast_walk_context_includes(c, i)) ) {
+ for (idx = 0; idx < ast_context_includes_count(c); idx++) {
+ const struct ast_include *i = ast_context_includes_get(c, idx);
const char *i_name = ast_get_include_name(i);
struct ast_context *nc = NULL;
int already_served = 0;
@@ -906,7 +917,7 @@ static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct a
for (c = NULL; (c = ast_walk_contexts(c)); ) {
int context_header_written = 0;
struct ast_exten *ext, *last_written_e = NULL;
- struct ast_include *i;
+ int idx;
struct ast_ignorepat *ip;
struct ast_sw *sw;
@@ -983,14 +994,17 @@ static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct a
fprintf(output, "\n");
/* walk through includes */
- for (i = NULL; (i = ast_walk_context_includes(c, i)) ; ) {
+ for (idx = 0; idx < ast_context_includes_count(c); idx++) {
+ const struct ast_include *i = ast_context_includes_get(c, idx);
+
if (strcmp(ast_get_include_registrar(i), registrar) != 0)
continue; /* not mine */
PUT_CTX_HDR;
fprintf(output, "include => %s\n", ast_get_include_name(i));
}
- if (ast_walk_context_includes(c, NULL))
+ if (ast_context_includes_count(c)) {
fprintf(output, "\n");
+ }
/* walk through switches */
for (sw = NULL; (sw = ast_walk_context_switches(c, sw)) ; ) {