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)
154 char *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 */
174 /* _X_ is the string we need to complete */
175 static char *complete_dialplan_remove_include(struct ast_cli_args *a)
179 int len = strlen(a->word); /* how many bytes to match */
180 struct ast_context *c = NULL;
182 if (a->pos == 3) { /* "dialplan remove include _X_" */
183 if (ast_wrlock_contexts()) {
184 ast_log(LOG_ERROR, "Failed to lock context list\n");
187 /* walk contexts and their includes, return the n-th match */
188 while (!res && (c = ast_walk_contexts(c))) {
189 struct ast_include *i = NULL;
191 if (ast_rdlock_context(c)) /* error ? skip this one */
194 while ( !res && (i = ast_walk_context_includes(c, i)) ) {
195 const char *i_name = ast_get_include_name(i);
196 struct ast_context *nc = NULL;
197 int already_served = 0;
199 if (!partial_match(i_name, a->word, len))
200 continue; /* not matched */
202 /* check if this include is already served or not */
204 /* go through all contexts again till we reach actual
205 * context or already_served = 1
207 while ( (nc = ast_walk_contexts(nc)) && nc != c && !already_served)
208 already_served = lookup_ci(nc, i_name);
210 if (!already_served && ++which > a->n)
211 res = strdup(i_name);
213 ast_unlock_context(c);
216 ast_unlock_contexts();
218 } else if (a->pos == 4) { /* "dialplan remove include CTX _X_" */
220 * complete as 'from', but only if previous context is really
223 char *context, *dupline;
224 const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
228 context = dupline = strdup(s);
230 ast_log(LOG_ERROR, "Out of free memory\n");
233 strsep(&dupline, " ");
235 if (ast_rdlock_contexts()) {
236 ast_log(LOG_ERROR, "Failed to lock contexts list\n");
241 /* go through all contexts and check if is included ... */
242 while (!res && (c = ast_walk_contexts(c)))
243 if (lookup_ci(c, context)) /* context is really included, complete "from" command */
244 res = strdup("from");
245 ast_unlock_contexts();
247 ast_log(LOG_WARNING, "%s not included anywhere\n", context);
250 } else if (a->pos == 5) { /* "dialplan remove include CTX from _X_" */
252 * Context from which we removing include ...
254 char *context, *dupline, *from;
255 const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
256 context = dupline = strdup(s);
258 ast_log(LOG_ERROR, "Out of free memory\n");
262 strsep(&dupline, " "); /* skip context */
264 /* fourth word must be 'from' */
265 from = strsep(&dupline, " ");
266 if (!from || strcmp(from, "from")) {
271 if (ast_rdlock_contexts()) {
272 ast_log(LOG_ERROR, "Failed to lock context list\n");
277 /* walk through all contexts ... */
279 while ( !res && (c = ast_walk_contexts(c))) {
280 const char *c_name = ast_get_context_name(c);
281 if (!partial_match(c_name, a->word, len)) /* not a good target */
283 /* walk through all includes and check if it is our context */
284 if (lookup_ci(c, context) && ++which > a->n)
285 res = strdup(c_name);
287 ast_unlock_contexts();
296 * REMOVE EXTENSION command stuff
298 static char *handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
300 int removing_priority = 0;
301 char *exten, *context;
302 char *ret = CLI_FAILURE;
306 e->command = "dialplan remove extension";
308 "Usage: dialplan remove extension exten@context [priority]\n"
309 " Remove an extension from a given context. If a priority\n"
310 " is given, only that specific priority from the given extension\n"
311 " will be removed.\n";
314 return complete_dialplan_remove_extension(a);
317 if (a->argc != 5 && a->argc != 4)
318 return CLI_SHOWUSAGE;
321 * Priority input checking ...
324 char *c = a->argv[4];
326 /* check for digits in whole parameter for right priority ...
327 * why? because atoi (strtol) returns 0 if any characters in
328 * string and whole extension will be removed, it's not good
330 if (!strcmp("hint", c))
331 removing_priority = PRIORITY_HINT;
333 while (*c && isdigit(*c))
335 if (*c) { /* non-digit in string */
336 ast_cli(a->fd, "Invalid priority '%s'\n", a->argv[4]);
339 removing_priority = atoi(a->argv[4]);
342 if (removing_priority == 0) {
343 ast_cli(a->fd, "If you want to remove whole extension, please " \
344 "omit priority argument\n");
349 /* XXX original overwrote argv[3] */
351 * Format exten@context checking ...
353 if (split_ec(a->argv[3], &exten, &context))
354 return CLI_FAILURE; /* XXX malloc failure */
355 if ((!strlen(exten)) || (!(strlen(context)))) {
356 ast_cli(a->fd, "Missing extension or context name in third argument '%s'\n",
362 if (!ast_context_remove_extension(context, exten, removing_priority, registrar)) {
363 if (!removing_priority)
364 ast_cli(a->fd, "Whole extension %s@%s removed\n",
367 ast_cli(a->fd, "Extension %s@%s with priority %d removed\n",
368 exten, context, removing_priority);
372 ast_cli(a->fd, "Failed to remove extension %s@%s\n", exten, context);
379 #define BROKEN_READLINE 1
381 #ifdef BROKEN_READLINE
383 * There is one funny thing, when you have word like 300@ and you hit
384 * <tab>, you arguments will like as your word is '300 ', so it '@'
385 * characters acts sometimes as word delimiter and sometimes as a part
388 * This fix function, allocates new word variable and store here every
389 * time xxx@yyy always as one word and correct pos is set too
391 * It's ugly, I know, but I'm waiting for Mark suggestion if upper is
394 static int fix_complete_args(const char *line, char **word, int *pos)
396 char *_line, *_strsep_line, *_previous_word = NULL, *_word = NULL;
399 _line = strdup(line);
401 _strsep_line = _line;
402 while (_strsep_line) {
403 _previous_word = _word;
404 _word = strsep(&_strsep_line, " ");
406 if (_word && strlen(_word)) words++;
410 if (_word || _previous_word) {
412 if (!strlen(_word)) words++;
413 *word = strdup(_word);
415 *word = strdup(_previous_word);
424 #endif /* BROKEN_READLINE */
426 static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
431 #ifdef BROKEN_READLINE
434 * Fix arguments, *word is a new allocated structure, REMEMBER to
435 * free *word when you want to return from this function ...
437 if (fix_complete_args(a->line, &word2, &a->pos)) {
438 ast_log(LOG_ERROR, "Out of free memory\n");
444 if (a->pos == 3) { /* 'dialplan remove extension _X_' (exten@context ... */
445 struct ast_context *c = NULL;
446 char *context = NULL, *exten = NULL;
447 int le = 0; /* length of extension */
448 int lc = 0; /* length of context */
450 lc = split_ec(a->word, &exten, &context);
451 #ifdef BROKEN_READLINE
457 lc = strlen(context);
459 if (ast_rdlock_contexts()) {
460 ast_log(LOG_ERROR, "Failed to lock context list\n");
464 /* find our context ... */
465 while ( (c = ast_walk_contexts(c)) ) { /* match our context if any */
466 struct ast_exten *e = NULL;
468 if (!partial_match(ast_get_context_name(c), context, lc))
469 continue; /* context not matched */
470 while ( (e = ast_walk_context_extensions(c, e)) ) { /* try to complete extensions ... */
471 if ( partial_match(ast_get_extension_name(e), exten, le) && ++which > a->n) { /* n-th match */
472 /* If there is an extension then return exten@context. XXX otherwise ? */
474 asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c));
478 if (e) /* got a match */
482 ast_unlock_contexts();
486 } else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
487 char *exten = NULL, *context, *p;
488 struct ast_context *c;
490 const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'extension' */
491 int i = split_ec(s, &exten, &context); /* parse ext@context */
495 if ( (p = strchr(exten, ' ')) ) /* remove space after extension */
497 if ( (p = strchr(context, ' ')) ) /* remove space after context */
500 lc = strlen(context);
501 len = strlen(a->word);
502 if (le == 0 || lc == 0)
505 if (ast_rdlock_contexts()) {
506 ast_log(LOG_ERROR, "Failed to lock context list\n");
512 while ( (c = ast_walk_contexts(c)) ) {
513 /* XXX locking on c ? */
515 if (strcmp(ast_get_context_name(c), context) != 0)
517 /* got it, we must match here */
519 while ( (e = ast_walk_context_extensions(c, e)) ) {
520 struct ast_exten *priority;
523 if (strcmp(ast_get_extension_name(e), exten) != 0)
527 while ( !ret && (priority = ast_walk_extension_priorities(e, priority)) ) {
528 snprintf(buffer, sizeof(buffer), "%u", ast_get_extension_priority(priority));
529 if (partial_match(buffer, a->word, len) && ++which > a->n) /* n-th match */
530 ret = strdup(buffer);
536 ast_unlock_contexts();
540 #ifdef BROKEN_READLINE
548 * Include context ...
550 static char *handle_cli_dialplan_add_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
554 e->command = "dialplan add include";
556 "Usage: dialplan add include <context> into <context>\n"
557 " Include a context in another context.\n";
560 return complete_dialplan_add_include(a);
563 if (a->argc != 6) /* dialplan add include CTX in CTX */
564 return CLI_SHOWUSAGE;
566 /* fifth arg must be 'into' ... */
567 if (strcmp(a->argv[4], "into"))
568 return CLI_SHOWUSAGE;
570 if (ast_context_add_include(a->argv[5], a->argv[3], registrar)) {
573 ast_cli(a->fd, "Out of memory for context addition\n");
577 ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
581 ast_cli(a->fd, "Context '%s' already included in '%s' context\n",
582 a->argv[3], a->argv[5]);
587 ast_cli(a->fd, "There is no existence of context '%s'\n",
588 errno == ENOENT ? a->argv[5] : a->argv[3]);
592 ast_cli(a->fd, "Failed to include '%s' in '%s' context\n",
593 a->argv[3], a->argv[5]);
599 /* show some info ... */
600 ast_cli(a->fd, "Context '%s' included in '%s' context\n",
601 a->argv[3], a->argv[5]);
606 static char *complete_dialplan_add_include(struct ast_cli_args *a)
608 struct ast_context *c;
611 int len = strlen(a->word);
613 if (a->pos == 3) { /* 'dialplan add include _X_' (context) ... */
614 if (ast_rdlock_contexts()) {
615 ast_log(LOG_ERROR, "Failed to lock context list\n");
618 for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
619 if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
620 ret = strdup(ast_get_context_name(c));
621 ast_unlock_contexts();
623 } else if (a->pos == 4) { /* dialplan add include CTX _X_ */
624 /* complete as 'into' if context exists or we are unable to check */
625 char *context, *dupline;
626 struct ast_context *c;
627 const char *s = skip_words(a->line, 3); /* should not fail */
629 if (a->n != 0) /* only once */
632 /* parse context from line ... */
633 context = dupline = strdup(s);
635 ast_log(LOG_ERROR, "Out of free memory\n");
636 return strdup("into");
638 strsep(&dupline, " ");
640 /* check for context existence ... */
641 if (ast_rdlock_contexts()) {
642 ast_log(LOG_ERROR, "Failed to lock context list\n");
643 /* our fault, we can't check, so complete 'into' ... */
644 ret = strdup("into");
646 for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
647 if (!strcmp(context, ast_get_context_name(c)))
648 ret = strdup("into"); /* found */
649 ast_unlock_contexts();
653 } else if (a->pos == 5) { /* 'dialplan add include CTX into _X_' (dst context) */
654 char *context, *dupline, *into;
655 const char *s = skip_words(a->line, 3); /* should not fail */
656 context = dupline = strdup(s);
658 ast_log(LOG_ERROR, "Out of free memory\n");
661 strsep(&dupline, " "); /* skip context */
662 into = strsep(&dupline, " ");
663 /* error if missing context or fifth word is not 'into' */
664 if (!strlen(context) || strcmp(into, "into")) {
665 ast_log(LOG_ERROR, "bad context %s or missing into %s\n",
670 if (ast_rdlock_contexts()) {
671 ast_log(LOG_ERROR, "Failed to lock context list\n");
675 for (c = NULL; (c = ast_walk_contexts(c)); )
676 if (!strcmp(context, ast_get_context_name(c)))
678 if (c) { /* first context exists, go on... */
679 /* go through all contexts ... */
680 for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
681 if (!strcmp(context, ast_get_context_name(c)))
682 continue; /* skip ourselves */
683 if (partial_match(ast_get_context_name(c), a->word, len) &&
684 !lookup_ci(c, context) /* not included yet */ &&
686 ret = strdup(ast_get_context_name(c));
689 ast_log(LOG_ERROR, "context %s not found\n", context);
691 ast_unlock_contexts();
701 * \brief 'save dialplan' CLI command implementation functions ...
703 static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
705 char filename[256], overrideswitch[256] = "";
706 struct ast_context *c;
707 struct ast_config *cfg;
708 struct ast_variable *v;
709 int incomplete = 0; /* incomplete config write? */
711 struct ast_flags config_flags = { 0 };
712 const char *base, *slash, *file;
716 e->command = "dialplan save";
718 "Usage: dialplan save [/path/to/extension/file]\n"
719 " Save dialplan created by pbx_config module.\n"
721 "Example: dialplan save (/etc/asterisk/extensions.conf)\n"
722 " dialplan save /home/markster (/home/markster/extensions.conf)\n";
728 if (! (static_config && !write_protect_config)) {
730 "I can't save dialplan now, see '%s' example file.\n",
735 if (a->argc != 2 && a->argc != 3)
736 return CLI_SHOWUSAGE;
738 if (ast_mutex_lock(&save_dialplan_lock)) {
740 "Failed to lock dialplan saving (another proccess saving?)\n");
743 /* XXX the code here is quite loose, a pathname with .conf in it
744 * is assumed to be a complete pathname
746 if (a->argc == 3) { /* have config path. Look for *.conf */
748 if (!strstr(a->argv[2], ".conf")) { /*no, this is assumed to be a pathname */
749 /* if filename ends with '/', do not add one */
750 slash = (*(a->argv[2] + strlen(a->argv[2]) -1) == '/') ? "/" : "";
751 file = config; /* default: 'extensions.conf' */
752 } else { /* yes, complete file name */
757 /* no config file, default one */
758 base = ast_config_AST_CONFIG_DIR;
762 snprintf(filename, sizeof(filename), "%s%s%s", base, slash, config);
764 cfg = ast_config_load("extensions.conf", config_flags);
766 /* try to lock contexts list */
767 if (ast_rdlock_contexts()) {
768 ast_cli(a->fd, "Failed to lock contexts list\n");
769 ast_mutex_unlock(&save_dialplan_lock);
770 ast_config_destroy(cfg);
774 /* create new file ... */
775 if (!(output = fopen(filename, "wt"))) {
776 ast_cli(a->fd, "Failed to create file '%s'\n",
778 ast_unlock_contexts();
779 ast_mutex_unlock(&save_dialplan_lock);
780 ast_config_destroy(cfg);
784 /* fireout general info */
785 if (overrideswitch_config) {
786 snprintf(overrideswitch, sizeof(overrideswitch), "overrideswitch=%s\n", overrideswitch_config);
788 fprintf(output, "[general]\nstatic=%s\nwriteprotect=%s\nautofallthrough=%s\nclearglobalvars=%s\n%sextenpatternmatchnew=%s\n\n",
789 static_config ? "yes" : "no",
790 write_protect_config ? "yes" : "no",
791 autofallthrough_config ? "yes" : "no",
792 clearglobalvars_config ? "yes" : "no",
793 overrideswitch_config ? overrideswitch : "",
794 extenpatternmatchnew_config ? "yes" : "no");
796 if ((v = ast_variable_browse(cfg, "globals"))) {
797 fprintf(output, "[globals]\n");
799 fprintf(output, "%s => %s\n", v->name, v->value);
802 fprintf(output, "\n");
805 ast_config_destroy(cfg);
807 #define PUT_CTX_HDR do { \
808 if (!context_header_written) { \
809 fprintf(output, "[%s]\n", ast_get_context_name(c)); \
810 context_header_written = 1; \
814 /* walk all contexts */
815 for (c = NULL; (c = ast_walk_contexts(c)); ) {
816 int context_header_written = 0;
817 struct ast_exten *e, *last_written_e = NULL;
818 struct ast_include *i;
819 struct ast_ignorepat *ip;
822 /* try to lock context and fireout all info */
823 if (ast_rdlock_context(c)) { /* lock failure */
827 /* registered by this module? */
828 /* XXX do we need this ? */
829 if (!strcmp(ast_get_context_registrar(c), registrar)) {
830 fprintf(output, "[%s]\n", ast_get_context_name(c));
831 context_header_written = 1;
834 /* walk extensions ... */
835 for (e = NULL; (e = ast_walk_context_extensions(c, e)); ) {
836 struct ast_exten *p = NULL;
838 /* fireout priorities */
839 while ( (p = ast_walk_extension_priorities(e, p)) ) {
840 if (strcmp(ast_get_extension_registrar(p), registrar) != 0) /* not this source */
843 /* make empty line between different extensions */
844 if (last_written_e != NULL &&
845 strcmp(ast_get_extension_name(last_written_e),
846 ast_get_extension_name(p)))
847 fprintf(output, "\n");
852 if (ast_get_extension_priority(p) == PRIORITY_HINT) { /* easy */
853 fprintf(output, "exten => %s,hint,%s\n",
854 ast_get_extension_name(p),
855 ast_get_extension_app(p));
857 const char *sep, *cid;
858 const char *el = ast_get_extension_label(p);
859 char label[128] = "";
861 if (ast_get_extension_matchcid(p)) {
863 cid = ast_get_extension_cidmatch(p);
867 if (el && (snprintf(label, sizeof(label), "(%s)", el) != (strlen(el) + 2)))
868 incomplete = 1; /* error encountered or label > 125 chars */
870 fprintf(output, "exten => %s%s%s,%d%s,%s(%s)\n",
871 ast_get_extension_name(p), (ast_strlen_zero(sep) ? "" : sep), (ast_strlen_zero(cid) ? "" : cid),
872 ast_get_extension_priority(p), label,
873 ast_get_extension_app(p), (ast_strlen_zero(ast_get_extension_app_data(p)) ? "" : (const char *)ast_get_extension_app_data(p)));
878 /* written any extensions? ok, write space between exten & inc */
880 fprintf(output, "\n");
882 /* walk through includes */
883 for (i = NULL; (i = ast_walk_context_includes(c, i)) ; ) {
884 if (strcmp(ast_get_include_registrar(i), registrar) != 0)
885 continue; /* not mine */
887 fprintf(output, "include => %s\n", ast_get_include_name(i));
889 if (ast_walk_context_includes(c, NULL))
890 fprintf(output, "\n");
892 /* walk through switches */
893 for (sw = NULL; (sw = ast_walk_context_switches(c, sw)) ; ) {
894 if (strcmp(ast_get_switch_registrar(sw), registrar) != 0)
895 continue; /* not mine */
897 fprintf(output, "switch => %s/%s\n",
898 ast_get_switch_name(sw), ast_get_switch_data(sw));
901 if (ast_walk_context_switches(c, NULL))
902 fprintf(output, "\n");
904 /* fireout ignorepats ... */
905 for (ip = NULL; (ip = ast_walk_context_ignorepats(c, ip)); ) {
906 if (strcmp(ast_get_ignorepat_registrar(ip), registrar) != 0)
907 continue; /* not mine */
909 fprintf(output, "ignorepat => %s\n",
910 ast_get_ignorepat_name(ip));
913 ast_unlock_context(c);
916 ast_unlock_contexts();
917 ast_mutex_unlock(&save_dialplan_lock);
921 ast_cli(a->fd, "Saved dialplan is incomplete\n");
925 ast_cli(a->fd, "Dialplan successfully saved into '%s'\n",
931 * \brief ADD EXTENSION command stuff
933 static char *handle_cli_dialplan_add_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
938 char *cidmatch, *app, *app_data;
943 e->command = "dialplan add extension";
945 "Usage: dialplan add extension <exten>,<priority>,<app>,<app-data>\n"
946 " into <context> [replace]\n\n"
947 " This command will add new extension into <context>. If there is an\n"
948 " existence of extension with the same priority and last 'replace'\n"
949 " arguments is given here we simply replace this extension.\n"
951 "Example: dialplan add extension 6123,1,Dial,IAX/216.207.245.56/6123 into local\n"
952 " Now, you can dial 6123 and talk to Markster :)\n";
955 return complete_dialplan_add_extension(a);
958 /* check for arguments at first */
959 if (a->argc != 6 && a->argc != 7)
960 return CLI_SHOWUSAGE;
961 if (strcmp(a->argv[4], "into"))
962 return CLI_SHOWUSAGE;
964 if (strcmp(a->argv[6], "replace"))
965 return CLI_SHOWUSAGE;
967 /* XXX overwrite argv[3] */
968 whole_exten = a->argv[3];
969 exten = strsep(&whole_exten,",");
970 if (strchr(exten, '/')) {
972 strsep(&cidmatch,"/");
976 prior = strsep(&whole_exten,",");
978 if (!strcmp(prior, "hint")) {
979 iprior = PRIORITY_HINT;
981 if (sscanf(prior, "%d", &iprior) != 1) {
982 ast_cli(a->fd, "'%s' is not a valid priority\n", prior);
988 if (app && (start = strchr(app, '(')) && (end = strrchr(app, ')'))) {
989 *start = *end = '\0';
990 app_data = start + 1;
993 app_data = strchr(app, ',');
1002 if (!exten || !prior || !app || (!app_data && iprior != PRIORITY_HINT))
1003 return CLI_SHOWUSAGE;
1007 if (ast_add_extension(a->argv[5], a->argc == 7 ? 1 : 0, exten, iprior, NULL, cidmatch, app,
1008 (void *)strdup(app_data), ast_free_ptr, registrar)) {
1011 ast_cli(a->fd, "Out of free memory\n");
1015 ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
1019 ast_cli(a->fd, "No existence of '%s' context\n", a->argv[5]);
1023 ast_cli(a->fd, "Extension %s@%s with priority %s already exists\n",
1024 exten, a->argv[5], prior);
1028 ast_cli(a->fd, "Failed to add '%s,%s,%s,%s' extension into '%s' context\n",
1029 exten, prior, app, app_data, a->argv[5]);
1036 ast_cli(a->fd, "Extension %s@%s (%s) replace by '%s,%s,%s,%s'\n",
1037 exten, a->argv[5], prior, exten, prior, app, app_data);
1039 ast_cli(a->fd, "Extension '%s,%s,%s,%s' added into '%s' context\n",
1040 exten, prior, app, app_data, a->argv[5]);
1045 /*! dialplan add extension 6123,1,Dial,IAX/212.71.138.13/6123 into local */
1046 static char *complete_dialplan_add_extension(struct ast_cli_args *a)
1050 if (a->pos == 4) { /* complete 'into' word ... */
1051 return (a->n == 0) ? strdup("into") : NULL;
1052 } else if (a->pos == 5) { /* complete context */
1053 struct ast_context *c = NULL;
1054 int len = strlen(a->word);
1057 /* try to lock contexts list ... */
1058 if (ast_rdlock_contexts()) {
1059 ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1063 /* walk through all contexts */
1064 while ( !res && (c = ast_walk_contexts(c)) )
1065 if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
1066 res = strdup(ast_get_context_name(c));
1067 ast_unlock_contexts();
1069 } else if (a->pos == 6) {
1070 return a->n == 0 ? strdup("replace") : NULL;
1076 * IGNOREPAT CLI stuff
1078 static char *handle_cli_dialplan_add_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1082 e->command = "dialplan add ignorepat";
1084 "Usage: dialplan add ignorepat <pattern> into <context>\n"
1085 " This command adds a new ignore pattern into context <context>\n"
1087 "Example: dialplan add ignorepat _3XX into local\n";
1090 return complete_dialplan_add_ignorepat(a);
1094 return CLI_SHOWUSAGE;
1096 if (strcmp(a->argv[4], "into"))
1097 return CLI_SHOWUSAGE;
1099 if (ast_context_add_ignorepat(a->argv[5], a->argv[3], registrar)) {
1102 ast_cli(a->fd, "Out of free memory\n");
1106 ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
1110 ast_cli(a->fd, "Ignore pattern '%s' already included in '%s' context\n",
1111 a->argv[3], a->argv[5]);
1115 ast_cli(a->fd, "Failed to lock context(s) list, please, try again later\n");
1119 ast_cli(a->fd, "Failed to add ingore pattern '%s' into '%s' context\n",
1120 a->argv[3], a->argv[5]);
1126 ast_cli(a->fd, "Ignore pattern '%s' added into '%s' context\n",
1127 a->argv[3], a->argv[5]);
1132 static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
1135 return a->n == 0 ? strdup("into") : NULL;
1136 else if (a->pos == 5) {
1137 struct ast_context *c;
1139 char *dupline, *ignorepat = NULL;
1142 int len = strlen(a->word);
1144 /* XXX skip first three words 'dialplan' 'add' 'ignorepat' */
1145 s = skip_words(a->line, 3);
1148 dupline = strdup(s);
1150 ast_log(LOG_ERROR, "Malloc failure\n");
1153 ignorepat = strsep(&dupline, " ");
1155 if (ast_rdlock_contexts()) {
1156 ast_log(LOG_ERROR, "Failed to lock contexts list\n");
1160 for (c = NULL; !ret && (c = ast_walk_contexts(c));) {
1163 if (!partial_match(ast_get_context_name(c), a->word, len))
1164 continue; /* not mine */
1165 if (ignorepat) /* there must be one, right ? */
1166 found = lookup_c_ip(c, ignorepat);
1167 if (!found && ++which > a->n)
1168 ret = strdup(ast_get_context_name(c));
1173 ast_unlock_contexts();
1180 static char *handle_cli_dialplan_remove_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1184 e->command = "dialplan remove ignorepat";
1186 "Usage: dialplan remove ignorepat <pattern> from <context>\n"
1187 " This command removes an ignore pattern from context <context>\n"
1189 "Example: dialplan remove ignorepat _3XX from local\n";
1192 return complete_dialplan_remove_ignorepat(a);
1196 return CLI_SHOWUSAGE;
1198 if (strcmp(a->argv[4], "from"))
1199 return CLI_SHOWUSAGE;
1201 if (ast_context_remove_ignorepat(a->argv[5], a->argv[3], registrar)) {
1204 ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
1208 ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
1212 ast_cli(a->fd, "There is no existence of '%s' ignore pattern in '%s' context\n",
1213 a->argv[3], a->argv[5]);
1217 ast_cli(a->fd, "Failed to remove ignore pattern '%s' from '%s' context\n",
1218 a->argv[3], a->argv[5]);
1224 ast_cli(a->fd, "Ignore pattern '%s' removed from '%s' context\n",
1225 a->argv[3], a->argv[5]);
1229 static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
1231 struct ast_context *c;
1236 int len = strlen(a->word);
1237 if (ast_rdlock_contexts()) {
1238 ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1242 for (c = NULL; !ret && (c = ast_walk_contexts(c));) {
1243 struct ast_ignorepat *ip;
1245 if (ast_rdlock_context(c)) /* error, skip it */
1248 for (ip = NULL; !ret && (ip = ast_walk_context_ignorepats(c, ip));) {
1249 if (partial_match(ast_get_ignorepat_name(ip), a->word, len) && ++which > a->n) {
1251 struct ast_context *cw = NULL;
1253 while ( (cw = ast_walk_contexts(cw)) && cw != c && !found) {
1254 /* XXX do i stop on c, or skip it ? */
1255 found = lookup_c_ip(cw, ast_get_ignorepat_name(ip));
1258 ret = strdup(ast_get_ignorepat_name(ip));
1261 ast_unlock_context(c);
1263 ast_unlock_contexts();
1265 } else if (a->pos == 4) {
1266 return a->n == 0 ? strdup("from") : NULL;
1267 } else if (a->pos == 5) { /* XXX check this */
1268 char *dupline, *duplinet, *ignorepat;
1269 int len = strlen(a->word);
1271 dupline = strdup(a->line);
1273 ast_log(LOG_WARNING, "Out of free memory\n");
1278 strsep(&duplinet, " ");
1279 strsep(&duplinet, " ");
1280 ignorepat = strsep(&duplinet, " ");
1287 if (ast_rdlock_contexts()) {
1288 ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1293 for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
1294 if (ast_rdlock_context(c)) /* fail, skip it */
1296 if (!partial_match(ast_get_context_name(c), a->word, len))
1298 if (lookup_c_ip(c, ignorepat) && ++which > a->n)
1299 ret = strdup(ast_get_context_name(c));
1300 ast_unlock_context(c);
1302 ast_unlock_contexts();
1310 static int pbx_load_module(void);
1312 static char *handle_cli_dialplan_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1316 e->command = "dialplan reload";
1318 "Usage: dialplan reload\n"
1319 " Reload extensions.conf without reloading any other\n"
1320 " modules. This command does not delete global variables\n"
1321 " unless clearglobalvars is set to yes in extensions.conf\n";
1328 return CLI_SHOWUSAGE;
1330 if (clearglobalvars_config)
1331 pbx_builtin_clear_globals();
1334 ast_cli(a->fd, "Dialplan reloaded.\n");
1339 * CLI entries for commands provided by this module
1341 static struct ast_cli_entry cli_pbx_config[] = {
1342 AST_CLI_DEFINE(handle_cli_dialplan_add_extension, "Add new extension into context"),
1343 AST_CLI_DEFINE(handle_cli_dialplan_remove_extension, "Remove a specified extension"),
1344 AST_CLI_DEFINE(handle_cli_dialplan_add_ignorepat, "Add new ignore pattern"),
1345 AST_CLI_DEFINE(handle_cli_dialplan_remove_ignorepat, "Remove ignore pattern from context"),
1346 AST_CLI_DEFINE(handle_cli_dialplan_add_include, "Include context in other context"),
1347 AST_CLI_DEFINE(handle_cli_dialplan_remove_include, "Remove a specified include from context"),
1348 AST_CLI_DEFINE(handle_cli_dialplan_reload, "Reload extensions and *only* extensions")
1351 static struct ast_cli_entry cli_dialplan_save =
1352 AST_CLI_DEFINE(handle_cli_dialplan_save, "Save dialplan");
1355 * Standard module functions ...
1357 static int unload_module(void)
1359 if (static_config && !write_protect_config)
1360 ast_cli_unregister(&cli_dialplan_save);
1361 if (overrideswitch_config) {
1362 ast_free(overrideswitch_config);
1364 ast_cli_unregister_multiple(cli_pbx_config, sizeof(cli_pbx_config) / sizeof(struct ast_cli_entry));
1365 ast_context_destroy(NULL, registrar);
1369 static int pbx_load_config(const char *config_file)
1371 struct ast_config *cfg;
1374 char realvalue[256];
1376 struct ast_context *con;
1377 struct ast_variable *v;
1380 const char *newpm, *ovsw;
1381 struct ast_flags config_flags = { 0 };
1382 cfg = ast_config_load(config_file, config_flags);
1386 /* Use existing config to populate the PBX table */
1387 static_config = ast_true(ast_variable_retrieve(cfg, "general", "static"));
1388 write_protect_config = ast_true(ast_variable_retrieve(cfg, "general", "writeprotect"));
1389 if ((aft = ast_variable_retrieve(cfg, "general", "autofallthrough")))
1390 autofallthrough_config = ast_true(aft);
1391 if ((newpm = ast_variable_retrieve(cfg, "general", "extenpatternmatchnew")))
1392 extenpatternmatchnew_config = ast_true(newpm);
1393 clearglobalvars_config = ast_true(ast_variable_retrieve(cfg, "general", "clearglobalvars"));
1394 if ((ovsw = ast_variable_retrieve(cfg, "general", "overrideswitch"))) {
1395 if (overrideswitch_config) {
1396 ast_free(overrideswitch_config);
1398 if (!ast_strlen_zero(ovsw)) {
1399 overrideswitch_config = ast_strdup(ovsw);
1401 overrideswitch_config = NULL;
1405 if ((cxt = ast_variable_retrieve(cfg, "general", "userscontext")))
1406 ast_copy_string(userscontext, cxt, sizeof(userscontext));
1408 ast_copy_string(userscontext, "default", sizeof(userscontext));
1410 for (v = ast_variable_browse(cfg, "globals"); v; v = v->next) {
1411 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1412 pbx_builtin_setvar_helper(NULL, v->name, realvalue);
1414 for (cxt = NULL; (cxt = ast_category_browse(cfg, cxt)); ) {
1415 /* All categories but "general" or "globals" are considered contexts */
1416 if (!strcasecmp(cxt, "general") || !strcasecmp(cxt, "globals"))
1418 con=ast_context_find_or_create(&local_contexts, local_table, cxt, registrar);
1422 for (v = ast_variable_browse(cfg, cxt); v; v = v->next) {
1423 if (!strcasecmp(v->name, "exten")) {
1424 char *tc = ast_strdup(v->value);
1427 char realext[256]="";
1428 char *plus, *firstp;
1429 char *pri, *appl, *data, *cidmatch;
1431 char *ext = strsep(&stringp, ",");
1434 pbx_substitute_variables_helper(NULL, ext, realext, sizeof(realext) - 1);
1435 cidmatch = strchr(realext, '/');
1438 ast_shrink_phone_number(cidmatch);
1440 pri = strsep(&stringp, ",");
1443 pri = ast_skip_blanks(pri);
1444 pri = ast_trim_blanks(pri);
1445 label = strchr(pri, '(');
1448 end = strchr(label, ')');
1452 ast_log(LOG_WARNING, "Label missing trailing ')' at line %d\n", v->lineno);
1454 plus = strchr(pri, '+');
1457 if (!strcmp(pri,"hint"))
1459 else if (!strcmp(pri, "next") || !strcmp(pri, "n")) {
1463 ast_log(LOG_WARNING, "Can't use 'next' priority on the first entry!\n");
1464 } else if (!strcmp(pri, "same") || !strcmp(pri, "s")) {
1468 ast_log(LOG_WARNING, "Can't use 'same' priority on the first entry!\n");
1469 } else if (sscanf(pri, "%d", &ipri) != 1 &&
1470 (ipri = ast_findlabel_extension2(NULL, con, realext, pri, cidmatch)) < 1) {
1471 ast_log(LOG_WARNING, "Invalid priority/label '%s' at line %d\n", pri, v->lineno);
1474 appl = S_OR(stringp, "");
1475 /* Find the first occurrence of '(' */
1476 firstp = strchr(appl, '(');
1481 appl = strsep(&stringp, "(");
1483 end = strrchr(data, ')');
1484 if ((end = strrchr(data, ')'))) {
1487 ast_log(LOG_WARNING, "No closing parenthesis found? '%s(%s'\n", appl, data);
1493 appl = ast_skip_blanks(appl);
1498 if (!ast_opt_dont_warn && !strcmp(realext, "_."))
1499 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);
1500 if (ast_add_extension2(con, 0, realext, ipri, label, cidmatch, appl, strdup(data), ast_free_ptr, registrar)) {
1501 ast_log(LOG_WARNING, "Unable to register extension at line %d\n", v->lineno);
1506 } else if (!strcasecmp(v->name, "include")) {
1507 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1508 if (ast_context_add_include2(con, realvalue, registrar))
1509 ast_log(LOG_WARNING, "Unable to include context '%s' in context '%s'\n", v->value, cxt);
1510 } else if (!strcasecmp(v->name, "ignorepat")) {
1511 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1512 if (ast_context_add_ignorepat2(con, realvalue, registrar))
1513 ast_log(LOG_WARNING, "Unable to include ignorepat '%s' in context '%s'\n", v->value, cxt);
1514 } else if (!strcasecmp(v->name, "switch") || !strcasecmp(v->name, "lswitch") || !strcasecmp(v->name, "eswitch")) {
1515 char *stringp = realvalue;
1518 if (!strcasecmp(v->name, "switch"))
1519 pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1521 ast_copy_string(realvalue, v->value, sizeof(realvalue));
1522 appl = strsep(&stringp, "/");
1523 data = S_OR(stringp, "");
1524 if (ast_context_add_switch2(con, appl, data, !strcasecmp(v->name, "eswitch"), registrar))
1525 ast_log(LOG_WARNING, "Unable to include switch '%s' in context '%s'\n", v->value, cxt);
1527 ast_log(LOG_WARNING, "==!!== Unknown directive: %s at line %d -- IGNORING!!!\n", v->name, v->lineno);
1531 ast_config_destroy(cfg);
1535 static void append_interface(char *iface, int maxlen, char *add)
1537 int len = strlen(iface);
1538 if (strlen(add) + len < maxlen - 2) {
1539 if (strlen(iface)) {
1541 strcpy(iface + len + 1, add);
1547 static void pbx_load_users(void)
1549 struct ast_config *cfg;
1551 const char *dahdichan;
1552 const char *hasexten, *altexts;
1555 char dahdicopy[256];
1556 char *ext, altcopy[256];
1560 int start, finish, x;
1561 struct ast_context *con = NULL;
1562 struct ast_flags config_flags = { 0 };
1564 cfg = ast_config_load("users.conf", config_flags);
1568 for (cat = ast_category_browse(cfg, NULL); cat ; cat = ast_category_browse(cfg, cat)) {
1569 if (!strcasecmp(cat, "general"))
1572 len = sizeof(iface);
1573 if (ast_true(ast_config_option(cfg, cat, "hassip"))) {
1574 snprintf(tmp, sizeof(tmp), "SIP/%s", cat);
1575 append_interface(iface, sizeof(iface), tmp);
1577 if (ast_true(ast_config_option(cfg, cat, "hasiax"))) {
1578 snprintf(tmp, sizeof(tmp), "IAX2/%s", cat);
1579 append_interface(iface, sizeof(iface), tmp);
1581 if (ast_true(ast_config_option(cfg, cat, "hash323"))) {
1582 snprintf(tmp, sizeof(tmp), "H323/%s", cat);
1583 append_interface(iface, sizeof(iface), tmp);
1585 hasexten = ast_config_option(cfg, cat, "hasexten");
1586 if (hasexten && !ast_true(hasexten))
1588 hasvoicemail = ast_true(ast_config_option(cfg, cat, "hasvoicemail"));
1589 dahdichan = ast_variable_retrieve(cfg, cat, "dahdichan");
1591 dahdichan = ast_variable_retrieve(cfg, "general", "dahdichan");
1593 /* no dahdichan, but look for zapchan too */
1594 dahdichan = ast_variable_retrieve(cfg, cat, "zapchan");
1596 dahdichan = ast_variable_retrieve(cfg, "general", "zapchan");
1598 if (!ast_strlen_zero(dahdichan)) {
1599 ast_log(LOG_WARNING, "Use of zapchan in users.conf is deprecated. Please update configuration to use dahdichan instead.\n");
1602 if (!ast_strlen_zero(dahdichan)) {
1603 ast_copy_string(dahdicopy, dahdichan, sizeof(dahdicopy));
1605 chan = strsep(&c, ",");
1607 if (sscanf(chan, "%d-%d", &start, &finish) == 2) {
1609 } else if (sscanf(chan, "%d", &start)) {
1613 start = 0; finish = 0;
1615 if (finish < start) {
1620 for (x = start; x <= finish; x++) {
1621 snprintf(tmp, sizeof(tmp), "DAHDI/%d", x);
1622 append_interface(iface, sizeof(iface), tmp);
1624 chan = strsep(&c, ",");
1627 if (!ast_strlen_zero(iface)) {
1628 /* Only create a context here when it is really needed. Otherwise default empty context
1629 created by pbx_config may conflict with the one explicitly created by pbx_ael */
1631 con = ast_context_find_or_create(&local_contexts, local_table, userscontext, registrar);
1634 ast_log(LOG_ERROR, "Can't find/create user context '%s'\n", userscontext);
1639 ast_add_extension2(con, 0, cat, -1, NULL, NULL, iface, NULL, NULL, registrar);
1640 /* If voicemail, use "stdexten" else use plain old dial */
1642 snprintf(tmp, sizeof(tmp), "stdexten,%s,${HINT}", cat);
1643 ast_add_extension2(con, 0, cat, 1, NULL, NULL, "Macro", strdup(tmp), ast_free_ptr, registrar);
1645 ast_add_extension2(con, 0, cat, 1, NULL, NULL, "Dial", strdup("${HINT}"), ast_free_ptr, registrar);
1647 altexts = ast_variable_retrieve(cfg, cat, "alternateexts");
1648 if (!ast_strlen_zero(altexts)) {
1649 snprintf(tmp, sizeof(tmp), "%s,1", cat);
1650 ast_copy_string(altcopy, altexts, sizeof(altcopy));
1652 ext = strsep(&c, ",");
1654 ast_add_extension2(con, 0, ext, 1, NULL, NULL, "Goto", strdup(tmp), ast_free, registrar);
1655 ext = strsep(&c, ",");
1660 ast_config_destroy(cfg);
1663 static int pbx_load_module(void)
1665 struct ast_context *con;
1668 local_table = ast_hashtab_create(17, ast_hashtab_compare_contexts, ast_hashtab_resize_java, ast_hashtab_newsize_java, ast_hashtab_hash_contexts, 0);
1670 if (!pbx_load_config(config))
1671 return AST_MODULE_LOAD_DECLINE;
1675 ast_merge_contexts_and_delete(&local_contexts, local_table, registrar);
1676 local_table = NULL; /* the local table has been moved into the global one. */
1677 local_contexts = NULL;
1679 for (con = NULL; (con = ast_walk_contexts(con));)
1680 ast_context_verify_includes(con);
1682 pbx_set_overrideswitch(overrideswitch_config);
1683 pbx_set_autofallthrough(autofallthrough_config);
1684 pbx_set_extenpatternmatchnew(extenpatternmatchnew_config);
1686 return AST_MODULE_LOAD_SUCCESS;
1689 static int load_module(void)
1691 if (pbx_load_module())
1692 return AST_MODULE_LOAD_DECLINE;
1694 if (static_config && !write_protect_config)
1695 ast_cli_register(&cli_dialplan_save);
1696 ast_cli_register_multiple(cli_pbx_config, sizeof(cli_pbx_config) / sizeof(struct ast_cli_entry));
1698 return AST_MODULE_LOAD_SUCCESS;
1701 static int reload(void)
1703 if (clearglobalvars_config)
1704 pbx_builtin_clear_globals();
1705 return pbx_load_module();
1708 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Text Extension Configuration",
1709 .load = load_module,
1710 .unload = unload_module,