2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Populate and remember extensions from static config file
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include "asterisk/paths.h" /* ast_config_AST_CONFIG_DIR */
33 #include "asterisk/pbx.h"
34 #include "asterisk/config.h"
35 #include "asterisk/module.h"
36 #include "asterisk/logger.h"
37 #include "asterisk/cli.h"
38 #include "asterisk/channel.h" /* AST_MAX_EXTENSION */
39 #include "asterisk/callerid.h"
41 static char *config = "extensions.conf";
42 static char *registrar = "pbx_config";
43 static char userscontext[AST_MAX_EXTENSION] = "default";
45 static int static_config = 0;
46 static int write_protect_config = 1;
47 static int autofallthrough_config = 1;
48 static int clearglobalvars_config = 0;
49 static int extenpatternmatchnew_config = 0;
50 static char *overrideswitch_config = NULL;
52 AST_MUTEX_DEFINE_STATIC(save_dialplan_lock);
54 static struct ast_context *local_contexts = NULL;
55 static struct ast_hashtab *local_table = NULL;
57 * Prototypes for our completion functions
59 static char *complete_dialplan_remove_include(struct ast_cli_args *);
60 static char *complete_dialplan_add_include(struct ast_cli_args *);
61 static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *);
62 static char *complete_dialplan_add_ignorepat(struct ast_cli_args *);
63 static char *complete_dialplan_remove_extension(struct ast_cli_args *);
64 static char *complete_dialplan_add_extension(struct ast_cli_args *);
67 * Implementation of functions provided by this module
71 * REMOVE INCLUDE command stuff
73 static char *handle_cli_dialplan_remove_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
77 e->command = "dialplan remove include";
79 "Usage: dialplan remove include <context> from <context>\n"
80 " Remove an included context from another context.\n";
83 return complete_dialplan_remove_include(a);
86 if (strcmp(a->argv[4], "from"))
89 if (!ast_context_remove_include(a->argv[5], a->argv[3], registrar)) {
90 ast_cli(a->fd, "We are not including '%s' into '%s' now\n",
91 a->argv[3], a->argv[5]);
95 ast_cli(a->fd, "Failed to remove '%s' include from '%s' context\n",
96 a->argv[3], a->argv[5]);
100 /*! \brief return true if 'name' is included by context c */
101 static int lookup_ci(struct ast_context *c, const char *name)
103 struct ast_include *i = NULL;
105 if (ast_rdlock_context(c)) /* error, skip */
107 while ( (i = ast_walk_context_includes(c, i)) )
108 if (!strcmp(name, ast_get_include_name(i)))
110 ast_unlock_context(c);
111 return i ? -1 /* success */ : 0;
114 /*! \brief return true if 'name' is in the ignorepats for context c */
115 static int lookup_c_ip(struct ast_context *c, const char *name)
117 struct ast_ignorepat *ip = NULL;
119 if (ast_rdlock_context(c)) /* error, skip */
121 while ( (ip = ast_walk_context_ignorepats(c, ip)) )
122 if (!strcmp(name, ast_get_ignorepat_name(ip)))
124 ast_unlock_context(c);
125 return ip ? -1 /* success */ : 0;
128 /*! \brief moves to the n-th word in the string, or empty string if none */
129 static const char *skip_words(const char *p, int n)
132 for (;n && *p; p++) {
133 if (isblank(*p) /* XXX order is important */ && !in_blank) {
134 n--; /* one word is gone */
136 } else if (/* !is_blank(*p), we know already, && */ in_blank) {
143 /*! \brief match the first 'len' chars of word. len==0 always succeeds */
144 static int partial_match(const char *s, const char *word, int len)
146 return (len == 0 || !strncmp(s, word, len));
149 /*! \brief split extension\@context in two parts, return -1 on error.
150 * The return string is malloc'ed and pointed by *ext
152 static int split_ec(const char *src, char **ext, char ** const ctx, char ** const cid)
154 char *i, *c, *e = ast_strdup(src); /* now src is not used anymore */
157 return -1; /* malloc error */
158 /* now, parse values from 'exten@context' */
161 if (c == NULL) /* no context part */
162 *ctx = ""; /* it is not overwritten, anyways */
163 else { /* found context, check for duplicity ... */
166 if (strchr(c, '@')) { /* two @, not allowed */
171 if (cid && (i = strchr(e, '/'))) {
175 /* Signal none detected */
181 /* _X_ is the string we need to complete */
182 static char *complete_dialplan_remove_include(struct ast_cli_args *a)
186 int len = strlen(a->word); /* how many bytes to match */
187 struct ast_context *c = NULL;
189 if (a->pos == 3) { /* "dialplan remove include _X_" */
190 if (ast_wrlock_contexts()) {
191 ast_log(LOG_ERROR, "Failed to lock context list\n");
194 /* walk contexts and their includes, return the n-th match */
195 while (!res && (c = ast_walk_contexts(c))) {
196 struct ast_include *i = NULL;
198 if (ast_rdlock_context(c)) /* error ? skip this one */
201 while ( !res && (i = ast_walk_context_includes(c, i)) ) {
202 const char *i_name = ast_get_include_name(i);
203 struct ast_context *nc = NULL;
204 int already_served = 0;
206 if (!partial_match(i_name, a->word, len))
207 continue; /* not matched */
209 /* check if this include is already served or not */
211 /* go through all contexts again till we reach actual
212 * context or already_served = 1
214 while ( (nc = ast_walk_contexts(nc)) && nc != c && !already_served)
215 already_served = lookup_ci(nc, i_name);
217 if (!already_served && ++which > a->n)
218 res = strdup(i_name);
220 ast_unlock_context(c);
223 ast_unlock_contexts();
225 } else if (a->pos == 4) { /* "dialplan remove include CTX _X_" */
227 * complete as 'from', but only if previous context is really
230 char *context, *dupline;
231 const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
235 context = dupline = strdup(s);
237 ast_log(LOG_ERROR, "Out of free memory\n");
240 strsep(&dupline, " ");
242 if (ast_rdlock_contexts()) {
243 ast_log(LOG_ERROR, "Failed to lock contexts list\n");
248 /* go through all contexts and check if is included ... */
249 while (!res && (c = ast_walk_contexts(c)))
250 if (lookup_ci(c, context)) /* context is really included, complete "from" command */
251 res = strdup("from");
252 ast_unlock_contexts();
254 ast_log(LOG_WARNING, "%s not included anywhere\n", context);
257 } else if (a->pos == 5) { /* "dialplan remove include CTX from _X_" */
259 * Context from which we removing include ...
261 char *context, *dupline, *from;
262 const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
263 context = dupline = strdup(s);
265 ast_log(LOG_ERROR, "Out of free memory\n");
269 strsep(&dupline, " "); /* skip context */
271 /* fourth word must be 'from' */
272 from = strsep(&dupline, " ");
273 if (!from || strcmp(from, "from")) {
278 if (ast_rdlock_contexts()) {
279 ast_log(LOG_ERROR, "Failed to lock context list\n");
284 /* walk through all contexts ... */
286 while ( !res && (c = ast_walk_contexts(c))) {
287 const char *c_name = ast_get_context_name(c);
288 if (!partial_match(c_name, a->word, len)) /* not a good target */
290 /* walk through all includes and check if it is our context */
291 if (lookup_ci(c, context) && ++which > a->n)
292 res = strdup(c_name);
294 ast_unlock_contexts();
303 * REMOVE EXTENSION command stuff
305 static char *handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
307 int removing_priority = 0;
308 char *exten, *context, *cid;
309 char *ret = CLI_FAILURE;
313 e->command = "dialplan remove extension";
315 "Usage: dialplan remove extension exten[/cid]@context [priority]\n"
316 " Remove an extension from a given context. If a priority\n"
317 " is given, only that specific priority from the given extension\n"
318 " will be removed.\n";
321 return complete_dialplan_remove_extension(a);
324 if (a->argc != 5 && a->argc != 4)
325 return CLI_SHOWUSAGE;
328 * Priority input checking ...
331 char *c = a->argv[4];
333 /* check for digits in whole parameter for right priority ...
334 * why? because atoi (strtol) returns 0 if any characters in
335 * string and whole extension will be removed, it's not good
337 if (!strcmp("hint", c))
338 removing_priority = PRIORITY_HINT;
340 while (*c && isdigit(*c))
342 if (*c) { /* non-digit in string */
343 ast_cli(a->fd, "Invalid priority '%s'\n", a->argv[4]);
346 removing_priority = atoi(a->argv[4]);
349 if (removing_priority == 0) {
350 ast_cli(a->fd, "If you want to remove whole extension, please " \
351 "omit priority argument\n");
356 /* XXX original overwrote argv[3] */
358 * Format exten@context checking ...
360 if (split_ec(a->argv[3], &exten, &context, &cid))
361 return CLI_FAILURE; /* XXX malloc failure */
362 if ((!strlen(exten)) || (!(strlen(context)))) {
363 ast_cli(a->fd, "Missing extension or context name in third argument '%s'\n",
369 if (!ast_context_remove_extension_callerid(context, exten, removing_priority,
370 /* Do NOT substitute S_OR; it is NOT the same thing */
371 cid ? cid : (removing_priority ? "" : NULL), cid ? 1 : 0, registrar)) {
372 if (!removing_priority)
373 ast_cli(a->fd, "Whole extension %s@%s removed\n",
376 ast_cli(a->fd, "Extension %s@%s with priority %d removed\n",
377 exten, context, removing_priority);
382 ast_cli(a->fd, "Failed to remove extension %s/%s@%s\n", exten, cid, context);
384 ast_cli(a->fd, "Failed to remove extension %s@%s\n", exten, context);
392 #define BROKEN_READLINE 1
394 #ifdef BROKEN_READLINE
396 * There is one funny thing, when you have word like 300@ and you hit
397 * <tab>, you arguments will act as your word is '300 ', so the '@'
398 * character acts sometimes as a word delimiter and sometimes as a part
401 * This fix function allocates a new word variable and stores it every
402 * time as xxx@yyy. The correct pos is set, too.
404 * It's ugly, I know, but I'm waiting for Mark's suggestion if the
405 * previous is a bug or a feature ...
407 static int fix_complete_args(const char *line, char **word, int *pos)
409 char *_line, *_strsep_line, *_previous_word = NULL, *_word = NULL;
412 _line = strdup(line);
414 _strsep_line = _line;
415 while (_strsep_line) {
416 _previous_word = _word;
417 _word = strsep(&_strsep_line, " ");
419 if (_word && strlen(_word)) words++;
423 if (_word || _previous_word) {
425 if (!strlen(_word)) words++;
426 *word = strdup(_word);
428 *word = strdup(_previous_word);
437 #endif /* BROKEN_READLINE */
439 static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
444 #ifdef BROKEN_READLINE
447 * Fix arguments, *word is a new allocated structure, REMEMBER to
448 * free *word when you want to return from this function ...
450 if (fix_complete_args(a->line, &word2, &a->pos)) {
451 ast_log(LOG_ERROR, "Out of free memory\n");
457 if (a->pos == 3) { /* 'dialplan remove extension _X_' (exten@context ... */
458 struct ast_context *c = NULL;
459 char *context = NULL, *exten = NULL, *cid = NULL;
460 int le = 0; /* length of extension */
461 int lc = 0; /* length of context */
462 int lcid = 0; /* length of cid */
464 lc = split_ec(a->word, &exten, &context, &cid);
465 if (lc) { /* error */
466 #ifdef BROKEN_READLINE
472 lc = strlen(context);
473 lcid = cid ? strlen(cid) : -1;
475 if (ast_rdlock_contexts()) {
476 ast_log(LOG_ERROR, "Failed to lock context list\n");
480 /* find our context ... */
481 while ( (c = ast_walk_contexts(c)) ) { /* match our context if any */
482 struct ast_exten *e = NULL;
484 if (!partial_match(ast_get_context_name(c), context, lc))
485 continue; /* context not matched */
486 while ( (e = ast_walk_context_extensions(c, e)) ) { /* try to complete extensions ... */
487 if ( !strchr(a->word, '/') ||
488 (!strchr(a->word, '@') && partial_match(ast_get_extension_cidmatch(e), cid, lcid)) ||
489 (strchr(a->word, '@') && !strcmp(ast_get_extension_cidmatch(e), cid))) {
490 if ( ((strchr(a->word, '/') || strchr(a->word, '@')) && !strcmp(ast_get_extension_name(e), exten)) ||
491 (!strchr(a->word, '/') && !strchr(a->word, '@') && partial_match(ast_get_extension_name(e), exten, le))) { /* n-th match */
492 if (++which > a->n) {
493 /* If there is an extension then return exten@context. */
494 if (ast_get_extension_matchcid(e) && (!strchr(a->word, '@') || strchr(a->word, '/'))) {
495 asprintf(&ret, "%s/%s@%s", ast_get_extension_name(e), ast_get_extension_cidmatch(e), ast_get_context_name(c));
497 } else if (!ast_get_extension_matchcid(e) && !strchr(a->word, '/')) {
498 asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c));
505 if (e) /* got a match */
509 ast_unlock_contexts();
513 } else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
514 char *exten = NULL, *context, *cid, *p;
515 struct ast_context *c;
516 int le, lc, lcid, len;
517 const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'extension' */
518 int i = split_ec(s, &exten, &context, &cid); /* parse ext@context */
522 if ( (p = strchr(exten, ' ')) ) /* remove space after extension */
524 if ( (p = strchr(context, ' ')) ) /* remove space after context */
527 lc = strlen(context);
529 len = strlen(a->word);
530 if (le == 0 || lc == 0)
533 if (ast_rdlock_contexts()) {
534 ast_log(LOG_ERROR, "Failed to lock context list\n");
540 while ( (c = ast_walk_contexts(c)) ) {
541 /* XXX locking on c ? */
543 if (strcmp(ast_get_context_name(c), context) != 0)
545 /* got it, we must match here */
547 while ( (e = ast_walk_context_extensions(c, e)) ) {
548 struct ast_exten *priority;
551 if (cid && strcmp(ast_get_extension_cidmatch(e), cid) != 0) {
554 if (strcmp(ast_get_extension_name(e), exten) != 0)
558 while ( !ret && (priority = ast_walk_extension_priorities(e, priority)) ) {
559 snprintf(buffer, sizeof(buffer), "%u", ast_get_extension_priority(priority));
560 if (partial_match(buffer, a->word, len) && ++which > a->n) /* n-th match */
561 ret = strdup(buffer);
567 ast_unlock_contexts();
572 #ifdef BROKEN_READLINE
579 * Include context ...
581 static char *handle_cli_dialplan_add_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
585 e->command = "dialplan add include";
587 "Usage: dialplan add include <context> into <context>\n"
588 " Include a context in another context.\n";
591 return complete_dialplan_add_include(a);
594 if (a->argc != 6) /* dialplan add include CTX in CTX */
595 return CLI_SHOWUSAGE;
597 /* fifth arg must be 'into' ... */
598 if (strcmp(a->argv[4], "into"))
599 return CLI_SHOWUSAGE;
601 if (ast_context_add_include(a->argv[5], a->argv[3], registrar)) {
604 ast_cli(a->fd, "Out of memory for context addition\n");
608 ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
612 ast_cli(a->fd, "Context '%s' already included in '%s' context\n",
613 a->argv[3], a->argv[5]);
618 ast_cli(a->fd, "There is no existence of context '%s'\n",
619 errno == ENOENT ? a->argv[5] : a->argv[3]);
623 ast_cli(a->fd, "Failed to include '%s' in '%s' context\n",
624 a->argv[3], a->argv[5]);
630 /* show some info ... */
631 ast_cli(a->fd, "Context '%s' included in '%s' context\n",
632 a->argv[3], a->argv[5]);
637 static char *complete_dialplan_add_include(struct ast_cli_args *a)
639 struct ast_context *c;
642 int len = strlen(a->word);
644 if (a->pos == 3) { /* 'dialplan add include _X_' (context) ... */
645 if (ast_rdlock_contexts()) {
646 ast_log(LOG_ERROR, "Failed to lock context list\n");
649 for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
650 if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
651 ret = strdup(ast_get_context_name(c));
652 ast_unlock_contexts();
654 } else if (a->pos == 4) { /* dialplan add include CTX _X_ */
655 /* complete as 'into' if context exists or we are unable to check */
656 char *context, *dupline;
657 struct ast_context *c;
658 const char *s = skip_words(a->line, 3); /* should not fail */
660 if (a->n != 0) /* only once */
663 /* parse context from line ... */
664 context = dupline = strdup(s);
666 ast_log(LOG_ERROR, "Out of free memory\n");
667 return strdup("into");
669 strsep(&dupline, " ");
671 /* check for context existence ... */
672 if (ast_rdlock_contexts()) {
673 ast_log(LOG_ERROR, "Failed to lock context list\n");
674 /* our fault, we can't check, so complete 'into' ... */
675 ret = strdup("into");
677 for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
678 if (!strcmp(context, ast_get_context_name(c)))
679 ret = strdup("into"); /* found */
680 ast_unlock_contexts();
684 } else if (a->pos == 5) { /* 'dialplan add include CTX into _X_' (dst context) */
685 char *context, *dupline, *into;
686 const char *s = skip_words(a->line, 3); /* should not fail */
687 context = dupline = strdup(s);
689 ast_log(LOG_ERROR, "Out of free memory\n");
692 strsep(&dupline, " "); /* skip context */
693 into = strsep(&dupline, " ");
694 /* error if missing context or fifth word is not 'into' */
695 if (!strlen(context) || strcmp(into, "into")) {
696 ast_log(LOG_ERROR, "bad context %s or missing into %s\n",
701 if (ast_rdlock_contexts()) {
702 ast_log(LOG_ERROR, "Failed to lock context list\n");
706 for (c = NULL; (c = ast_walk_contexts(c)); )
707 if (!strcmp(context, ast_get_context_name(c)))
709 if (c) { /* first context exists, go on... */
710 /* go through all contexts ... */
711 for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
712 if (!strcmp(context, ast_get_context_name(c)))
713 continue; /* skip ourselves */
714 if (partial_match(ast_get_context_name(c), a->word, len) &&
715 !lookup_ci(c, context) /* not included yet */ &&
717 ret = strdup(ast_get_context_name(c));
720 ast_log(LOG_ERROR, "context %s not found\n", context);
722 ast_unlock_contexts();
732 * \brief 'save dialplan' CLI command implementation functions ...
734 static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
736 char filename[256], overrideswitch[256] = "";
737 struct ast_context *c;
738 struct ast_config *cfg;
739 struct ast_variable *v;
740 int incomplete = 0; /* incomplete config write? */
742 struct ast_flags config_flags = { 0 };
743 const char *base, *slash, *file;
747 e->command = "dialplan save";
749 "Usage: dialplan save [/path/to/extension/file]\n"
750 " Save dialplan created by pbx_config module.\n"
752 "Example: dialplan save (/etc/asterisk/extensions.conf)\n"
753 " dialplan save /home/markster (/home/markster/extensions.conf)\n";
759 if (! (static_config && !write_protect_config)) {
761 "I can't save dialplan now, see '%s' example file.\n",
766 if (a->argc != 2 && a->argc != 3)
767 return CLI_SHOWUSAGE;
769 if (ast_mutex_lock(&save_dialplan_lock)) {
771 "Failed to lock dialplan saving (another proccess saving?)\n");
774 /* XXX the code here is quite loose, a pathname with .conf in it
775 * is assumed to be a complete pathname
777 if (a->argc == 3) { /* have config path. Look for *.conf */
779 if (!strstr(a->argv[2], ".conf")) { /*no, this is assumed to be a pathname */
780 /* if filename ends with '/', do not add one */
781 slash = (*(a->argv[2] + strlen(a->argv[2]) -1) == '/') ? "/" : "";
782 file = config; /* default: 'extensions.conf' */
783 } else { /* yes, complete file name */
788 /* no config file, default one */
789 base = ast_config_AST_CONFIG_DIR;
793 snprintf(filename, sizeof(filename), "%s%s%s", base, slash, config);
795 cfg = ast_config_load("extensions.conf", config_flags);
797 /* try to lock contexts list */
798 if (ast_rdlock_contexts()) {
799 ast_cli(a->fd, "Failed to lock contexts list\n");
800 ast_mutex_unlock(&save_dialplan_lock);
801 ast_config_destroy(cfg);
805 /* create new file ... */
806 if (!(output = fopen(filename, "wt"))) {
807 ast_cli(a->fd, "Failed to create file '%s'\n",
809 ast_unlock_contexts();
810 ast_mutex_unlock(&save_dialplan_lock);
811 ast_config_destroy(cfg);
815 /* fireout general info */
816 if (overrideswitch_config) {
817 snprintf(overrideswitch, sizeof(overrideswitch), "overrideswitch=%s\n", overrideswitch_config);
819 fprintf(output, "[general]\nstatic=%s\nwriteprotect=%s\nautofallthrough=%s\nclearglobalvars=%s\n%sextenpatternmatchnew=%s\n\n",
820 static_config ? "yes" : "no",
821 write_protect_config ? "yes" : "no",
822 autofallthrough_config ? "yes" : "no",
823 clearglobalvars_config ? "yes" : "no",
824 overrideswitch_config ? overrideswitch : "",
825 extenpatternmatchnew_config ? "yes" : "no");
827 if ((v = ast_variable_browse(cfg, "globals"))) {
828 fprintf(output, "[globals]\n");
830 fprintf(output, "%s => %s\n", v->name, v->value);
833 fprintf(output, "\n");
836 ast_config_destroy(cfg);
838 #define PUT_CTX_HDR do { \
839 if (!context_header_written) { \
840 fprintf(output, "[%s]\n", ast_get_context_name(c)); \
841 context_header_written = 1; \
845 /* walk all contexts */
846 for (c = NULL; (c = ast_walk_contexts(c)); ) {
847 int context_header_written = 0;
848 struct ast_exten *e, *last_written_e = NULL;
849 struct ast_include *i;
850 struct ast_ignorepat *ip;
853 /* try to lock context and fireout all info */
854 if (ast_rdlock_context(c)) { /* lock failure */
858 /* registered by this module? */
859 /* XXX do we need this ? */
860 if (!strcmp(ast_get_context_registrar(c), registrar)) {
861 fprintf(output, "[%s]\n", ast_get_context_name(c));
862 context_header_written = 1;
865 /* walk extensions ... */
866 for (e = NULL; (e = ast_walk_context_extensions(c, e)); ) {
867 struct ast_exten *p = NULL;
869 /* fireout priorities */
870 while ( (p = ast_walk_extension_priorities(e, p)) ) {
871 if (strcmp(ast_get_extension_registrar(p), registrar) != 0) /* not this source */
874 /* make empty line between different extensions */
875 if (last_written_e != NULL &&
876 strcmp(ast_get_extension_name(last_written_e),
877 ast_get_extension_name(p)))
878 fprintf(output, "\n");
883 if (ast_get_extension_priority(p) == PRIORITY_HINT) { /* easy */
884 fprintf(output, "exten => %s,hint,%s\n",
885 ast_get_extension_name(p),
886 ast_get_extension_app(p));
888 const char *sep, *cid;
889 const char *el = ast_get_extension_label(p);
890 char label[128] = "";
892 if (ast_get_extension_matchcid(p)) {
894 cid = ast_get_extension_cidmatch(p);
898 if (el && (snprintf(label, sizeof(label), "(%s)", el) != (strlen(el) + 2)))
899 incomplete = 1; /* error encountered or label > 125 chars */
901 fprintf(output, "exten => %s%s%s,%d%s,%s(%s)\n",
902 ast_get_extension_name(p), (ast_strlen_zero(sep) ? "" : sep), (ast_strlen_zero(cid) ? "" : cid),
903 ast_get_extension_priority(p), label,
904 ast_get_extension_app(p), (ast_strlen_zero(ast_get_extension_app_data(p)) ? "" : (const char *)ast_get_extension_app_data(p)));
909 /* written any extensions? ok, write space between exten & inc */
911 fprintf(output, "\n");
913 /* walk through includes */
914 for (i = NULL; (i = ast_walk_context_includes(c, i)) ; ) {
915 if (strcmp(ast_get_include_registrar(i), registrar) != 0)
916 continue; /* not mine */
918 fprintf(output, "include => %s\n", ast_get_include_name(i));
920 if (ast_walk_context_includes(c, NULL))
921 fprintf(output, "\n");
923 /* walk through switches */
924 for (sw = NULL; (sw = ast_walk_context_switches(c, sw)) ; ) {
925 if (strcmp(ast_get_switch_registrar(sw), registrar) != 0)
926 continue; /* not mine */
928 fprintf(output, "switch => %s/%s\n",
929 ast_get_switch_name(sw), ast_get_switch_data(sw));
932 if (ast_walk_context_switches(c, NULL))
933 fprintf(output, "\n");
935 /* fireout ignorepats ... */
936 for (ip = NULL; (ip = ast_walk_context_ignorepats(c, ip)); ) {
937 if (strcmp(ast_get_ignorepat_registrar(ip), registrar) != 0)
938 continue; /* not mine */
940 fprintf(output, "ignorepat => %s\n",
941 ast_get_ignorepat_name(ip));
944 ast_unlock_context(c);
947 ast_unlock_contexts();
948 ast_mutex_unlock(&save_dialplan_lock);
952 ast_cli(a->fd, "Saved dialplan is incomplete\n");
956 ast_cli(a->fd, "Dialplan successfully saved into '%s'\n",
962 * \brief ADD EXTENSION command stuff
964 static char *handle_cli_dialplan_add_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
969 char *cidmatch, *app, *app_data;
974 e->command = "dialplan add extension";
976 "Usage: dialplan add extension <exten>,<priority>,<app>,<app-data>\n"
977 " into <context> [replace]\n\n"
978 " This command will add new extension into <context>. If there is an\n"
979 " existence of extension with the same priority and last 'replace'\n"
980 " arguments is given here we simply replace this extension.\n"
982 "Example: dialplan add extension 6123,1,Dial,IAX/216.207.245.56/6123 into local\n"
983 " Now, you can dial 6123 and talk to Markster :)\n";
986 return complete_dialplan_add_extension(a);
989 /* check for arguments at first */
990 if (a->argc != 6 && a->argc != 7)
991 return CLI_SHOWUSAGE;
992 if (strcmp(a->argv[4], "into"))
993 return CLI_SHOWUSAGE;
995 if (strcmp(a->argv[6], "replace"))
996 return CLI_SHOWUSAGE;
998 /* XXX overwrite argv[3] */
999 whole_exten = a->argv[3];
1000 exten = strsep(&whole_exten,",");
1001 if (strchr(exten, '/')) {
1003 strsep(&cidmatch,"/");
1007 prior = strsep(&whole_exten,",");
1009 if (!strcmp(prior, "hint")) {
1010 iprior = PRIORITY_HINT;
1012 if (sscanf(prior, "%d", &iprior) != 1) {
1013 ast_cli(a->fd, "'%s' is not a valid priority\n", prior);
1019 if (app && (start = strchr(app, '(')) && (end = strrchr(app, ')'))) {
1020 *start = *end = '\0';
1021 app_data = start + 1;
1024 app_data = strchr(app, ',');
1033 if (!exten || !prior || !app || (!app_data && iprior != PRIORITY_HINT))
1034 return CLI_SHOWUSAGE;
1038 if (ast_add_extension(a->argv[5], a->argc == 7 ? 1 : 0, exten, iprior, NULL, cidmatch, app,
1039 (void *)strdup(app_data), ast_free_ptr, registrar)) {
1042 ast_cli(a->fd, "Out of free memory\n");
1046 ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
1050 ast_cli(a->fd, "No existence of '%s' context\n", a->argv[5]);
1054 ast_cli(a->fd, "Extension %s@%s with priority %s already exists\n",
1055 exten, a->argv[5], prior);
1059 ast_cli(a->fd, "Failed to add '%s,%s,%s,%s' extension into '%s' context\n",
1060 exten, prior, app, app_data, a->argv[5]);
1067 ast_cli(a->fd, "Extension %s@%s (%s) replace by '%s,%s,%s,%s'\n",
1068 exten, a->argv[5], prior, exten, prior, app, app_data);
1070 ast_cli(a->fd, "Extension '%s,%s,%s,%s' added into '%s' context\n",
1071 exten, prior, app, app_data, a->argv[5]);
1076 /*! dialplan add extension 6123,1,Dial,IAX/212.71.138.13/6123 into local */
1077 static char *complete_dialplan_add_extension(struct ast_cli_args *a)
1081 if (a->pos == 4) { /* complete 'into' word ... */
1082 return (a->n == 0) ? strdup("into") : NULL;
1083 } else if (a->pos == 5) { /* complete context */
1084 struct ast_context *c = NULL;
1085 int len = strlen(a->word);
1088 /* try to lock contexts list ... */
1089 if (ast_rdlock_contexts()) {
1090 ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1094 /* walk through all contexts */
1095 while ( !res && (c = ast_walk_contexts(c)) )
1096 if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
1097 res = strdup(ast_get_context_name(c));
1098 ast_unlock_contexts();
1100 } else if (a->pos == 6) {
1101 return a->n == 0 ? strdup("replace") : NULL;
1107 * IGNOREPAT CLI stuff
1109 static char *handle_cli_dialplan_add_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1113 e->command = "dialplan add ignorepat";
1115 "Usage: dialplan add ignorepat <pattern> into <context>\n"
1116 " This command adds a new ignore pattern into context <context>\n"
1118 "Example: dialplan add ignorepat _3XX into local\n";
1121 return complete_dialplan_add_ignorepat(a);
1125 return CLI_SHOWUSAGE;
1127 if (strcmp(a->argv[4], "into"))
1128 return CLI_SHOWUSAGE;
1130 if (ast_context_add_ignorepat(a->argv[5], a->argv[3], registrar)) {
1133 ast_cli(a->fd, "Out of free memory\n");
1137 ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
1141 ast_cli(a->fd, "Ignore pattern '%s' already included in '%s' context\n",
1142 a->argv[3], a->argv[5]);
1146 ast_cli(a->fd, "Failed to lock context(s) list, please, try again later\n");
1150 ast_cli(a->fd, "Failed to add ingore pattern '%s' into '%s' context\n",
1151 a->argv[3], a->argv[5]);
1157 ast_cli(a->fd, "Ignore pattern '%s' added into '%s' context\n",
1158 a->argv[3], a->argv[5]);
1163 static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
1166 return a->n == 0 ? strdup("into") : NULL;
1167 else if (a->pos == 5) {
1168 struct ast_context *c;
1170 char *dupline, *ignorepat = NULL;
1173 int len = strlen(a->word);
1175 /* XXX skip first three words 'dialplan' 'add' 'ignorepat' */
1176 s = skip_words(a->line, 3);
1179 dupline = strdup(s);
1181 ast_log(LOG_ERROR, "Malloc failure\n");
1184 ignorepat = strsep(&dupline, " ");
1186 if (ast_rdlock_contexts()) {
1187 ast_log(LOG_ERROR, "Failed to lock contexts list\n");
1191 for (c = NULL; !ret && (c = ast_walk_contexts(c));) {
1194 if (!partial_match(ast_get_context_name(c), a->word, len))
1195 continue; /* not mine */
1196 if (ignorepat) /* there must be one, right ? */
1197 found = lookup_c_ip(c, ignorepat);
1198 if (!found && ++which > a->n)
1199 ret = strdup(ast_get_context_name(c));
1204 ast_unlock_contexts();
1211 static char *handle_cli_dialplan_remove_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1215 e->command = "dialplan remove ignorepat";
1217 "Usage: dialplan remove ignorepat <pattern> from <context>\n"
1218 " This command removes an ignore pattern from context <context>\n"
1220 "Example: dialplan remove ignorepat _3XX from local\n";
1223 return complete_dialplan_remove_ignorepat(a);
1227 return CLI_SHOWUSAGE;
1229 if (strcmp(a->argv[4], "from"))
1230 return CLI_SHOWUSAGE;
1232 if (ast_context_remove_ignorepat(a->argv[5], a->argv[3], registrar)) {
1235 ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
1239 ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
1243 ast_cli(a->fd, "There is no existence of '%s' ignore pattern in '%s' context\n",
1244 a->argv[3], a->argv[5]);
1248 ast_cli(a->fd, "Failed to remove ignore pattern '%s' from '%s' context\n",
1249 a->argv[3], a->argv[5]);
1255 ast_cli(a->fd, "Ignore pattern '%s' removed from '%s' context\n",
1256 a->argv[3], a->argv[5]);
1260 static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
1262 struct ast_context *c;
1267 int len = strlen(a->word);
1268 if (ast_rdlock_contexts()) {
1269 ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1273 for (c = NULL; !ret && (c = ast_walk_contexts(c));) {
1274 struct ast_ignorepat *ip;
1276 if (ast_rdlock_context(c)) /* error, skip it */
1279 for (ip = NULL; !ret && (ip = ast_walk_context_ignorepats(c, ip));) {
1280 if (partial_match(ast_get_ignorepat_name(ip), a->word, len) && ++which > a->n) {
1282 struct ast_context *cw = NULL;
1284 while ( (cw = ast_walk_contexts(cw)) && cw != c && !found) {
1285 /* XXX do i stop on c, or skip it ? */
1286 found = lookup_c_ip(cw, ast_get_ignorepat_name(ip));
1289 ret = strdup(ast_get_ignorepat_name(ip));
1292 ast_unlock_context(c);
1294 ast_unlock_contexts();
1296 } else if (a->pos == 4) {
1297 return a->n == 0 ? strdup("from") : NULL;
1298 } else if (a->pos == 5) { /* XXX check this */
1299 char *dupline, *duplinet, *ignorepat;
1300 int len = strlen(a->word);
1302 dupline = strdup(a->line);
1304 ast_log(LOG_WARNING, "Out of free memory\n");
1309 strsep(&duplinet, " ");
1310 strsep(&duplinet, " ");
1311 ignorepat = strsep(&duplinet, " ");
1318 if (ast_rdlock_contexts()) {
1319 ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1324 for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
1325 if (ast_rdlock_context(c)) /* fail, skip it */
1327 if (!partial_match(ast_get_context_name(c), a->word, len))
1329 if (lookup_c_ip(c, ignorepat) && ++which > a->n)
1330 ret = strdup(ast_get_context_name(c));
1331 ast_unlock_context(c);
1333 ast_unlock_contexts();
1341 static int pbx_load_module(void);
1343 static char *handle_cli_dialplan_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1347 e->command = "dialplan reload";
1349 "Usage: dialplan reload\n"
1350 " Reload extensions.conf without reloading any other\n"
1351 " modules. This command does not delete global variables\n"
1352 " unless clearglobalvars is set to yes in extensions.conf\n";
1359 return CLI_SHOWUSAGE;
1361 if (clearglobalvars_config)
1362 pbx_builtin_clear_globals();
1365 ast_cli(a->fd, "Dialplan reloaded.\n");
1370 * CLI entries for commands provided by this module
1372 static struct ast_cli_entry cli_pbx_config[] = {
1373 AST_CLI_DEFINE(handle_cli_dialplan_add_extension, "Add new extension into context"),
1374 AST_CLI_DEFINE(handle_cli_dialplan_remove_extension, "Remove a specified extension"),
1375 AST_CLI_DEFINE(handle_cli_dialplan_add_ignorepat, "Add new ignore pattern"),
1376 AST_CLI_DEFINE(handle_cli_dialplan_remove_ignorepat, "Remove ignore pattern from context"),
1377 AST_CLI_DEFINE(handle_cli_dialplan_add_include, "Include context in other context"),
1378 AST_CLI_DEFINE(handle_cli_dialplan_remove_include, "Remove a specified include from context"),
1379 AST_CLI_DEFINE(handle_cli_dialplan_reload, "Reload extensions and *only* extensions")
1382 static struct ast_cli_entry cli_dialplan_save =
1383 AST_CLI_DEFINE(handle_cli_dialplan_save, "Save dialplan");
1386 * Standard module functions ...
1388 static int unload_module(void)
1390 if (static_config && !write_protect_config)
1391 ast_cli_unregister(&cli_dialplan_save);
1392 if (overrideswitch_config) {
1393 ast_free(overrideswitch_config);
1395 ast_cli_unregister_multiple(cli_pbx_config, sizeof(cli_pbx_config) / sizeof(struct ast_cli_entry));
1396 ast_context_destroy(NULL, registrar);
1400 static int pbx_load_config(const char *config_file)
1402 struct ast_config *cfg;
1405 char realvalue[256];
1407 struct ast_context *con;
1408 struct ast_variable *v;
1411 const char *newpm, *ovsw;
1412 struct ast_flags config_flags = { 0 };
1413 cfg = ast_config_load(config_file, config_flags);
1417 /* Use existing config to populate the PBX table */
1418 static_config = ast_true(ast_variable_retrieve(cfg, "general", "static"));
1419 write_protect_config = ast_true(ast_variable_retrieve(cfg, "general", "writeprotect"));
1420 if ((aft = ast_variable_retrieve(cfg, "general", "autofallthrough")))
1421 autofallthrough_config = ast_true(aft);
1422 if ((newpm = ast_variable_retrieve(cfg, "general", "extenpatternmatchnew")))
1423 extenpatternmatchnew_config = ast_true(newpm);
1424 clearglobalvars_config = ast_true(ast_variable_retrieve(cfg, "general", "clearglobalvars"));
1425 if ((ovsw = ast_variable_retrieve(cfg, "general", "overrideswitch"))) {
1426 if (overrideswitch_config) {
1427 ast_free(overrideswitch_config);
1429 if (!ast_strlen_zero(ovsw)) {
1430 overrideswitch_config = ast_strdup(ovsw);
1432 overrideswitch_config = NULL;
1436 if ((cxt = ast_variable_retrieve(cfg, "general", "userscontext")))
1437 ast_copy_string(userscontext, cxt, sizeof(userscontext));
1439 ast_copy_string(userscontext, "default", sizeof(userscontext));
1441 for (v = ast_variable_browse(cfg, "globals"); v; v = v->next) {
1442 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1443 pbx_builtin_setvar_helper(NULL, v->name, realvalue);
1445 for (cxt = NULL; (cxt = ast_category_browse(cfg, cxt)); ) {
1446 /* All categories but "general" or "globals" are considered contexts */
1447 if (!strcasecmp(cxt, "general") || !strcasecmp(cxt, "globals"))
1449 con=ast_context_find_or_create(&local_contexts, local_table, cxt, registrar);
1453 for (v = ast_variable_browse(cfg, cxt); v; v = v->next) {
1454 if (!strcasecmp(v->name, "exten")) {
1455 char *tc = ast_strdup(v->value);
1458 char realext[256]="";
1459 char *plus, *firstp;
1460 char *pri, *appl, *data, *cidmatch;
1462 char *ext = strsep(&stringp, ",");
1465 pbx_substitute_variables_helper(NULL, ext, realext, sizeof(realext) - 1);
1466 cidmatch = strchr(realext, '/');
1469 ast_shrink_phone_number(cidmatch);
1471 pri = strsep(&stringp, ",");
1474 pri = ast_skip_blanks(pri);
1475 pri = ast_trim_blanks(pri);
1476 label = strchr(pri, '(');
1479 end = strchr(label, ')');
1483 ast_log(LOG_WARNING, "Label missing trailing ')' at line %d\n", v->lineno);
1485 plus = strchr(pri, '+');
1488 if (!strcmp(pri,"hint"))
1490 else if (!strcmp(pri, "next") || !strcmp(pri, "n")) {
1494 ast_log(LOG_WARNING, "Can't use 'next' priority on the first entry!\n");
1495 } else if (!strcmp(pri, "same") || !strcmp(pri, "s")) {
1499 ast_log(LOG_WARNING, "Can't use 'same' priority on the first entry!\n");
1500 } else if (sscanf(pri, "%d", &ipri) != 1 &&
1501 (ipri = ast_findlabel_extension2(NULL, con, realext, pri, cidmatch)) < 1) {
1502 ast_log(LOG_WARNING, "Invalid priority/label '%s' at line %d\n", pri, v->lineno);
1505 appl = S_OR(stringp, "");
1506 /* Find the first occurrence of '(' */
1507 firstp = strchr(appl, '(');
1512 appl = strsep(&stringp, "(");
1514 end = strrchr(data, ')');
1515 if ((end = strrchr(data, ')'))) {
1518 ast_log(LOG_WARNING, "No closing parenthesis found? '%s(%s'\n", appl, data);
1524 appl = ast_skip_blanks(appl);
1529 if (!ast_opt_dont_warn && !strcmp(realext, "_."))
1530 ast_log(LOG_WARNING, "The use of '_.' for an extension is strongly discouraged and can have unexpected behavior. Please use '_X.' instead at line %d\n", v->lineno);
1531 if (ast_add_extension2(con, 0, realext, ipri, label, cidmatch, appl, strdup(data), ast_free_ptr, registrar)) {
1532 ast_log(LOG_WARNING, "Unable to register extension at line %d\n", v->lineno);
1537 } else if (!strcasecmp(v->name, "include")) {
1538 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1539 if (ast_context_add_include2(con, realvalue, registrar))
1540 ast_log(LOG_WARNING, "Unable to include context '%s' in context '%s'\n", v->value, cxt);
1541 } else if (!strcasecmp(v->name, "ignorepat")) {
1542 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1543 if (ast_context_add_ignorepat2(con, realvalue, registrar))
1544 ast_log(LOG_WARNING, "Unable to include ignorepat '%s' in context '%s'\n", v->value, cxt);
1545 } else if (!strcasecmp(v->name, "switch") || !strcasecmp(v->name, "lswitch") || !strcasecmp(v->name, "eswitch")) {
1546 char *stringp = realvalue;
1549 if (!strcasecmp(v->name, "switch"))
1550 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1552 ast_copy_string(realvalue, v->value, sizeof(realvalue));
1553 appl = strsep(&stringp, "/");
1554 data = S_OR(stringp, "");
1555 if (ast_context_add_switch2(con, appl, data, !strcasecmp(v->name, "eswitch"), registrar))
1556 ast_log(LOG_WARNING, "Unable to include switch '%s' in context '%s'\n", v->value, cxt);
1558 ast_log(LOG_WARNING, "==!!== Unknown directive: %s at line %d -- IGNORING!!!\n", v->name, v->lineno);
1562 ast_config_destroy(cfg);
1566 static void append_interface(char *iface, int maxlen, char *add)
1568 int len = strlen(iface);
1569 if (strlen(add) + len < maxlen - 2) {
1570 if (strlen(iface)) {
1572 strcpy(iface + len + 1, add);
1578 static void pbx_load_users(void)
1580 struct ast_config *cfg;
1582 const char *dahdichan;
1583 const char *hasexten, *altexts;
1586 char dahdicopy[256];
1587 char *ext, altcopy[256];
1591 int start, finish, x;
1592 struct ast_context *con = NULL;
1593 struct ast_flags config_flags = { 0 };
1595 cfg = ast_config_load("users.conf", config_flags);
1599 for (cat = ast_category_browse(cfg, NULL); cat ; cat = ast_category_browse(cfg, cat)) {
1600 if (!strcasecmp(cat, "general"))
1603 len = sizeof(iface);
1604 if (ast_true(ast_config_option(cfg, cat, "hassip"))) {
1605 snprintf(tmp, sizeof(tmp), "SIP/%s", cat);
1606 append_interface(iface, sizeof(iface), tmp);
1608 if (ast_true(ast_config_option(cfg, cat, "hasiax"))) {
1609 snprintf(tmp, sizeof(tmp), "IAX2/%s", cat);
1610 append_interface(iface, sizeof(iface), tmp);
1612 if (ast_true(ast_config_option(cfg, cat, "hash323"))) {
1613 snprintf(tmp, sizeof(tmp), "H323/%s", cat);
1614 append_interface(iface, sizeof(iface), tmp);
1616 hasexten = ast_config_option(cfg, cat, "hasexten");
1617 if (hasexten && !ast_true(hasexten))
1619 hasvoicemail = ast_true(ast_config_option(cfg, cat, "hasvoicemail"));
1620 dahdichan = ast_variable_retrieve(cfg, cat, "dahdichan");
1622 dahdichan = ast_variable_retrieve(cfg, "general", "dahdichan");
1624 /* no dahdichan, but look for zapchan too */
1625 dahdichan = ast_variable_retrieve(cfg, cat, "zapchan");
1627 dahdichan = ast_variable_retrieve(cfg, "general", "zapchan");
1629 if (!ast_strlen_zero(dahdichan)) {
1630 ast_log(LOG_WARNING, "Use of zapchan in users.conf is deprecated. Please update configuration to use dahdichan instead.\n");
1633 if (!ast_strlen_zero(dahdichan)) {
1634 ast_copy_string(dahdicopy, dahdichan, sizeof(dahdicopy));
1636 chan = strsep(&c, ",");
1638 if (sscanf(chan, "%d-%d", &start, &finish) == 2) {
1640 } else if (sscanf(chan, "%d", &start)) {
1644 start = 0; finish = 0;
1646 if (finish < start) {
1651 for (x = start; x <= finish; x++) {
1652 snprintf(tmp, sizeof(tmp), "DAHDI/%d", x);
1653 append_interface(iface, sizeof(iface), tmp);
1655 chan = strsep(&c, ",");
1658 if (!ast_strlen_zero(iface)) {
1659 /* Only create a context here when it is really needed. Otherwise default empty context
1660 created by pbx_config may conflict with the one explicitly created by pbx_ael */
1662 con = ast_context_find_or_create(&local_contexts, local_table, userscontext, registrar);
1665 ast_log(LOG_ERROR, "Can't find/create user context '%s'\n", userscontext);
1670 ast_add_extension2(con, 0, cat, -1, NULL, NULL, iface, NULL, NULL, registrar);
1671 /* If voicemail, use "stdexten" else use plain old dial */
1673 snprintf(tmp, sizeof(tmp), "stdexten,%s,${HINT}", cat);
1674 ast_add_extension2(con, 0, cat, 1, NULL, NULL, "Macro", strdup(tmp), ast_free_ptr, registrar);
1676 ast_add_extension2(con, 0, cat, 1, NULL, NULL, "Dial", strdup("${HINT}"), ast_free_ptr, registrar);
1678 altexts = ast_variable_retrieve(cfg, cat, "alternateexts");
1679 if (!ast_strlen_zero(altexts)) {
1680 snprintf(tmp, sizeof(tmp), "%s,1", cat);
1681 ast_copy_string(altcopy, altexts, sizeof(altcopy));
1683 ext = strsep(&c, ",");
1685 ast_add_extension2(con, 0, ext, 1, NULL, NULL, "Goto", strdup(tmp), ast_free, registrar);
1686 ext = strsep(&c, ",");
1691 ast_config_destroy(cfg);
1694 static int pbx_load_module(void)
1696 struct ast_context *con;
1699 local_table = ast_hashtab_create(17, ast_hashtab_compare_contexts, ast_hashtab_resize_java, ast_hashtab_newsize_java, ast_hashtab_hash_contexts, 0);
1701 if (!pbx_load_config(config))
1702 return AST_MODULE_LOAD_DECLINE;
1706 ast_merge_contexts_and_delete(&local_contexts, local_table, registrar);
1707 local_table = NULL; /* the local table has been moved into the global one. */
1708 local_contexts = NULL;
1710 for (con = NULL; (con = ast_walk_contexts(con));)
1711 ast_context_verify_includes(con);
1713 pbx_set_overrideswitch(overrideswitch_config);
1714 pbx_set_autofallthrough(autofallthrough_config);
1715 pbx_set_extenpatternmatchnew(extenpatternmatchnew_config);
1717 return AST_MODULE_LOAD_SUCCESS;
1720 static int load_module(void)
1722 if (pbx_load_module())
1723 return AST_MODULE_LOAD_DECLINE;
1725 if (static_config && !write_protect_config)
1726 ast_cli_register(&cli_dialplan_save);
1727 ast_cli_register_multiple(cli_pbx_config, sizeof(cli_pbx_config) / sizeof(struct ast_cli_entry));
1729 return AST_MODULE_LOAD_SUCCESS;
1732 static int reload(void)
1734 if (clearglobalvars_config)
1735 pbx_builtin_clear_globals();
1736 return pbx_load_module();
1739 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Text Extension Configuration",
1740 .load = load_module,
1741 .unload = unload_module,