Wed Jan 8 2020 09:49:49

Asterisk developer's documentation


pbx_config.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2006, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
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.
13  *
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.
17  */
18 
19 /*! \file
20  *
21  * \brief Populate and remember extensions from static config file
22  *
23  *
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 413586 $")
33 
34 #include <ctype.h>
35 
36 #include "asterisk/paths.h" /* ast_config_AST_CONFIG_DIR */
37 #include "asterisk/pbx.h"
38 #include "asterisk/config.h"
39 #include "asterisk/module.h"
40 #include "asterisk/logger.h"
41 #include "asterisk/cli.h"
42 #include "asterisk/channel.h" /* AST_MAX_EXTENSION */
43 #include "asterisk/callerid.h"
44 
45 static const char config[] = "extensions.conf";
46 static const char registrar[] = "pbx_config";
47 static char userscontext[AST_MAX_EXTENSION] = "default";
48 
49 static int static_config = 0;
50 static int write_protect_config = 1;
51 static int autofallthrough_config = 1;
52 static int clearglobalvars_config = 0;
54 static char *overrideswitch_config = NULL;
55 
57 
59 
60 static struct ast_context *local_contexts = NULL;
61 static struct ast_hashtab *local_table = NULL;
62 /*
63  * Prototypes for our completion functions
64  */
65 static char *complete_dialplan_remove_include(struct ast_cli_args *);
66 static char *complete_dialplan_add_include(struct ast_cli_args *);
68 static char *complete_dialplan_add_ignorepat(struct ast_cli_args *);
70 static char *complete_dialplan_add_extension(struct ast_cli_args *);
71 
72 /*
73  * Implementation of functions provided by this module
74  */
75 
76 /*!
77  * REMOVE INCLUDE command stuff
78  */
79 static char *handle_cli_dialplan_remove_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
80 {
81  switch (cmd) {
82  case CLI_INIT:
83  e->command = "dialplan remove include";
84  e->usage =
85  "Usage: dialplan remove include <context> from <context>\n"
86  " Remove an included context from another context.\n";
87  return NULL;
88  case CLI_GENERATE:
90  }
91 
92  if (a->argc != 6 || strcmp(a->argv[4], "from"))
93  return CLI_SHOWUSAGE;
94 
95  if (!ast_context_remove_include(a->argv[5], a->argv[3], registrar)) {
96  ast_cli(a->fd, "We are not including '%s' into '%s' now\n",
97  a->argv[3], a->argv[5]);
98  return CLI_SUCCESS;
99  }
100 
101  ast_cli(a->fd, "Failed to remove '%s' include from '%s' context\n",
102  a->argv[3], a->argv[5]);
103  return CLI_FAILURE;
104 }
105 
106 /*! \brief return true if 'name' is included by context c */
107 static int lookup_ci(struct ast_context *c, const char *name)
108 {
109  struct ast_include *i = NULL;
110 
111  if (ast_rdlock_context(c)) /* error, skip */
112  return 0;
113  while ( (i = ast_walk_context_includes(c, i)) )
114  if (!strcmp(name, ast_get_include_name(i)))
115  break;
117  return i ? -1 /* success */ : 0;
118 }
119 
120 /*! \brief return true if 'name' is in the ignorepats for context c */
121 static int lookup_c_ip(struct ast_context *c, const char *name)
122 {
123  struct ast_ignorepat *ip = NULL;
124 
125  if (ast_rdlock_context(c)) /* error, skip */
126  return 0;
127  while ( (ip = ast_walk_context_ignorepats(c, ip)) )
128  if (!strcmp(name, ast_get_ignorepat_name(ip)))
129  break;
131  return ip ? -1 /* success */ : 0;
132 }
133 
134 /*! \brief moves to the n-th word in the string, or empty string if none */
135 static const char *skip_words(const char *p, int n)
136 {
137  int in_blank = 0;
138  for (;n && *p; p++) {
139  if (isblank(*p) /* XXX order is important */ && !in_blank) {
140  n--; /* one word is gone */
141  in_blank = 1;
142  } else if (/* !is_blank(*p), we know already, && */ in_blank) {
143  in_blank = 0;
144  }
145  }
146  return p;
147 }
148 
149 /*! \brief match the first 'len' chars of word. len==0 always succeeds */
150 static int partial_match(const char *s, const char *word, int len)
151 {
152  return (len == 0 || !strncmp(s, word, len));
153 }
154 
155 /*! \brief split extension\@context in two parts, return -1 on error.
156  * The return string is malloc'ed and pointed by *ext
157  */
158 static int split_ec(const char *src, char **ext, char ** const ctx, char ** const cid)
159 {
160  char *i, *c, *e = ast_strdup(src); /* now src is not used anymore */
161 
162  if (e == NULL)
163  return -1; /* malloc error */
164  /* now, parse values from 'exten@context' */
165  *ext = e;
166  c = strchr(e, '@');
167  if (c == NULL) /* no context part */
168  *ctx = ""; /* it is not overwritten, anyways */
169  else { /* found context, check for duplicity ... */
170  *c++ = '\0';
171  *ctx = c;
172  if (strchr(c, '@')) { /* two @, not allowed */
173  free(e);
174  return -1;
175  }
176  }
177  if (cid && (i = strchr(e, '/'))) {
178  *i++ = '\0';
179  *cid = i;
180  } else if (cid) {
181  /* Signal none detected */
182  *cid = NULL;
183  }
184  return 0;
185 }
186 
187 /* _X_ is the string we need to complete */
189 {
190  int which = 0;
191  char *res = NULL;
192  int len = strlen(a->word); /* how many bytes to match */
193  struct ast_context *c = NULL;
194 
195  if (a->pos == 3) { /* "dialplan remove include _X_" */
196  if (ast_wrlock_contexts()) {
197  ast_log(LOG_ERROR, "Failed to lock context list\n");
198  return NULL;
199  }
200  /* walk contexts and their includes, return the n-th match */
201  while (!res && (c = ast_walk_contexts(c))) {
202  struct ast_include *i = NULL;
203 
204  if (ast_rdlock_context(c)) /* error ? skip this one */
205  continue;
206 
207  while ( !res && (i = ast_walk_context_includes(c, i)) ) {
208  const char *i_name = ast_get_include_name(i);
209  struct ast_context *nc = NULL;
210  int already_served = 0;
211 
212  if (!partial_match(i_name, a->word, len))
213  continue; /* not matched */
214 
215  /* check if this include is already served or not */
216 
217  /* go through all contexts again till we reach actual
218  * context or already_served = 1
219  */
220  while ( (nc = ast_walk_contexts(nc)) && nc != c && !already_served)
221  already_served = lookup_ci(nc, i_name);
222 
223  if (!already_served && ++which > a->n)
224  res = strdup(i_name);
225  }
227  }
228 
230  return res;
231  } else if (a->pos == 4) { /* "dialplan remove include CTX _X_" */
232  /*
233  * complete as 'from', but only if previous context is really
234  * included somewhere
235  */
236  char *context, *dupline;
237  const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
238 
239  if (a->n > 0)
240  return NULL;
241  context = dupline = strdup(s);
242  if (!dupline) {
243  ast_log(LOG_ERROR, "Out of free memory\n");
244  return NULL;
245  }
246  strsep(&dupline, " ");
247 
248  if (ast_rdlock_contexts()) {
249  ast_log(LOG_ERROR, "Failed to lock contexts list\n");
250  free(context);
251  return NULL;
252  }
253 
254  /* go through all contexts and check if is included ... */
255  while (!res && (c = ast_walk_contexts(c)))
256  if (lookup_ci(c, context)) /* context is really included, complete "from" command */
257  res = strdup("from");
259  if (!res)
260  ast_log(LOG_WARNING, "%s not included anywhere\n", context);
261  free(context);
262  return res;
263  } else if (a->pos == 5) { /* "dialplan remove include CTX from _X_" */
264  /*
265  * Context from which we removing include ...
266  */
267  char *context, *dupline, *from;
268  const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
269  context = dupline = strdup(s);
270  if (!dupline) {
271  ast_log(LOG_ERROR, "Out of free memory\n");
272  return NULL;
273  }
274 
275  strsep(&dupline, " "); /* skip context */
276 
277  /* fourth word must be 'from' */
278  from = strsep(&dupline, " ");
279  if (!from || strcmp(from, "from")) {
280  free(context);
281  return NULL;
282  }
283 
284  if (ast_rdlock_contexts()) {
285  ast_log(LOG_ERROR, "Failed to lock context list\n");
286  free(context);
287  return NULL;
288  }
289 
290  /* walk through all contexts ... */
291  c = NULL;
292  while ( !res && (c = ast_walk_contexts(c))) {
293  const char *c_name = ast_get_context_name(c);
294  if (!partial_match(c_name, a->word, len)) /* not a good target */
295  continue;
296  /* walk through all includes and check if it is our context */
297  if (lookup_ci(c, context) && ++which > a->n)
298  res = strdup(c_name);
299  }
301  free(context);
302  return res;
303  }
304 
305  return NULL;
306 }
307 
308 /*!
309  * REMOVE EXTENSION command stuff
310  */
311 static char *handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
312 {
313  int removing_priority = 0;
314  char *exten, *context, *cid;
315  char *ret = CLI_FAILURE;
316 
317  switch (cmd) {
318  case CLI_INIT:
319  e->command = "dialplan remove extension";
320  e->usage =
321  "Usage: dialplan remove extension exten[/cid]@context [priority]\n"
322  " Remove an extension from a given context. If a priority\n"
323  " is given, only that specific priority from the given extension\n"
324  " will be removed.\n";
325  return NULL;
326  case CLI_GENERATE:
328  }
329 
330  if (a->argc != 5 && a->argc != 4)
331  return CLI_SHOWUSAGE;
332 
333  /*
334  * Priority input checking ...
335  */
336  if (a->argc == 5) {
337  const char *c = a->argv[4];
338 
339  /* check for digits in whole parameter for right priority ...
340  * why? because atoi (strtol) returns 0 if any characters in
341  * string and whole extension will be removed, it's not good
342  */
343  if (!strcmp("hint", c))
344  removing_priority = PRIORITY_HINT;
345  else {
346  while (*c && isdigit(*c))
347  c++;
348  if (*c) { /* non-digit in string */
349  ast_cli(a->fd, "Invalid priority '%s'\n", a->argv[4]);
350  return CLI_FAILURE;
351  }
352  removing_priority = atoi(a->argv[4]);
353  }
354 
355  if (removing_priority == 0) {
356  ast_cli(a->fd, "If you want to remove whole extension, please " \
357  "omit priority argument\n");
358  return CLI_FAILURE;
359  }
360  }
361 
362  /* XXX original overwrote argv[3] */
363  /*
364  * Format exten@context checking ...
365  */
366  if (split_ec(a->argv[3], &exten, &context, &cid))
367  return CLI_FAILURE; /* XXX malloc failure */
368  if ((!strlen(exten)) || (!(strlen(context)))) {
369  ast_cli(a->fd, "Missing extension or context name in third argument '%s'\n",
370  a->argv[3]);
371  free(exten);
372  return CLI_FAILURE;
373  }
374 
375  if (!ast_context_remove_extension_callerid(context, exten, removing_priority,
376  /* Do NOT substitute S_OR; it is NOT the same thing */
377  cid ? cid : (removing_priority ? "" : NULL), cid ? 1 : 0, registrar)) {
378  if (!removing_priority)
379  ast_cli(a->fd, "Whole extension %s@%s removed\n",
380  exten, context);
381  else
382  ast_cli(a->fd, "Extension %s@%s with priority %d removed\n",
383  exten, context, removing_priority);
384 
385  ret = CLI_SUCCESS;
386  } else {
387  if (cid) {
388  ast_cli(a->fd, "Failed to remove extension %s/%s@%s\n", exten, cid, context);
389  } else {
390  ast_cli(a->fd, "Failed to remove extension %s@%s\n", exten, context);
391  }
392  ret = CLI_FAILURE;
393  }
394  free(exten);
395  return ret;
396 }
397 
399 {
400  char *ret = NULL;
401  int which = 0;
402 
403  if (a->pos == 3) { /* 'dialplan remove extension _X_' (exten@context ... */
404  struct ast_context *c = NULL;
405  char *context = NULL, *exten = NULL, *cid = NULL;
406  int le = 0; /* length of extension */
407  int lc = 0; /* length of context */
408  int lcid = 0; /* length of cid */
409 
410  lc = split_ec(a->word, &exten, &context, &cid);
411  if (lc) { /* error */
412  return NULL;
413  }
414  le = strlen(exten);
415  lc = strlen(context);
416  lcid = cid ? strlen(cid) : -1;
417 
418  if (ast_rdlock_contexts()) {
419  ast_log(LOG_ERROR, "Failed to lock context list\n");
420  goto error2;
421  }
422 
423  /* find our context ... */
424  while ( (c = ast_walk_contexts(c)) ) { /* match our context if any */
425  struct ast_exten *e = NULL;
426  /* XXX locking ? */
427  if (!partial_match(ast_get_context_name(c), context, lc))
428  continue; /* context not matched */
429  while ( (e = ast_walk_context_extensions(c, e)) ) { /* try to complete extensions ... */
430  if ( !strchr(a->word, '/') ||
431  (!strchr(a->word, '@') && partial_match(ast_get_extension_cidmatch(e), cid, lcid)) ||
432  (strchr(a->word, '@') && !strcmp(ast_get_extension_cidmatch(e), cid))) {
433  if ( ((strchr(a->word, '/') || strchr(a->word, '@')) && !strcmp(ast_get_extension_name(e), exten)) ||
434  (!strchr(a->word, '/') && !strchr(a->word, '@') && partial_match(ast_get_extension_name(e), exten, le))) { /* n-th match */
435  if (++which > a->n) {
436  /* If there is an extension then return exten@context. */
437  if (ast_get_extension_matchcid(e) && (!strchr(a->word, '@') || strchr(a->word, '/'))) {
439  ret = NULL;
440  }
441  break;
442  } else if (!ast_get_extension_matchcid(e) && !strchr(a->word, '/')) {
443  if (ast_asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c)) < 0) {
444  ret = NULL;
445  }
446  break;
447  }
448  }
449  }
450  }
451  }
452  if (e) /* got a match */
453  break;
454  }
455 
457  error2:
458  free(exten);
459  } else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
460  char *exten = NULL, *context, *cid, *p;
461  struct ast_context *c;
462  int le, lc, len;
463  const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'extension' */
464  int i = split_ec(s, &exten, &context, &cid); /* parse ext@context */
465 
466  if (i) /* error */
467  goto error3;
468  if ( (p = strchr(exten, ' ')) ) /* remove space after extension */
469  *p = '\0';
470  if ( (p = strchr(context, ' ')) ) /* remove space after context */
471  *p = '\0';
472  le = strlen(exten);
473  lc = strlen(context);
474  len = strlen(a->word);
475  if (le == 0 || lc == 0)
476  goto error3;
477 
478  if (ast_rdlock_contexts()) {
479  ast_log(LOG_ERROR, "Failed to lock context list\n");
480  goto error3;
481  }
482 
483  /* walk contexts */
484  c = NULL;
485  while ( (c = ast_walk_contexts(c)) ) {
486  /* XXX locking on c ? */
487  struct ast_exten *e;
488  if (strcmp(ast_get_context_name(c), context) != 0)
489  continue;
490  /* got it, we must match here */
491  e = NULL;
492  while ( (e = ast_walk_context_extensions(c, e)) ) {
493  struct ast_exten *priority;
494  char buffer[10];
495 
496  if (cid && strcmp(ast_get_extension_cidmatch(e), cid) != 0) {
497  continue;
498  }
499  if (strcmp(ast_get_extension_name(e), exten) != 0)
500  continue;
501  /* XXX lock e ? */
502  priority = NULL;
503  while ( !ret && (priority = ast_walk_extension_priorities(e, priority)) ) {
504  snprintf(buffer, sizeof(buffer), "%d", ast_get_extension_priority(priority));
505  if (partial_match(buffer, a->word, len) && ++which > a->n) /* n-th match */
506  ret = strdup(buffer);
507  }
508  break;
509  }
510  break;
511  }
513  error3:
514  free(exten);
515  }
516  return ret;
517 }
518 
519 /*!
520  * Include context ...
521  */
522 static char *handle_cli_dialplan_add_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
523 {
524  switch (cmd) {
525  case CLI_INIT:
526  e->command = "dialplan add include";
527  e->usage =
528  "Usage: dialplan add include <context> into <context>\n"
529  " Include a context in another context.\n";
530  return NULL;
531  case CLI_GENERATE:
533  }
534 
535  if (a->argc != 6) /* dialplan add include CTX in CTX */
536  return CLI_SHOWUSAGE;
537 
538  /* fifth arg must be 'into' ... */
539  if (strcmp(a->argv[4], "into"))
540  return CLI_SHOWUSAGE;
541 
542  if (ast_context_add_include(a->argv[5], a->argv[3], registrar)) {
543  switch (errno) {
544  case ENOMEM:
545  ast_cli(a->fd, "Out of memory for context addition\n");
546  break;
547 
548  case EBUSY:
549  ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
550  break;
551 
552  case EEXIST:
553  ast_cli(a->fd, "Context '%s' already included in '%s' context\n",
554  a->argv[3], a->argv[5]);
555  break;
556 
557  case ENOENT:
558  case EINVAL:
559  ast_cli(a->fd, "There is no existence of context '%s'\n",
560  errno == ENOENT ? a->argv[5] : a->argv[3]);
561  break;
562 
563  default:
564  ast_cli(a->fd, "Failed to include '%s' in '%s' context\n",
565  a->argv[3], a->argv[5]);
566  break;
567  }
568  return CLI_FAILURE;
569  }
570 
571  /* show some info ... */
572  ast_cli(a->fd, "Context '%s' included in '%s' context\n",
573  a->argv[3], a->argv[5]);
574 
575  return CLI_SUCCESS;
576 }
577 
579 {
580  struct ast_context *c;
581  int which = 0;
582  char *ret = NULL;
583  int len = strlen(a->word);
584 
585  if (a->pos == 3) { /* 'dialplan add include _X_' (context) ... */
586  if (ast_rdlock_contexts()) {
587  ast_log(LOG_ERROR, "Failed to lock context list\n");
588  return NULL;
589  }
590  for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
591  if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
592  ret = strdup(ast_get_context_name(c));
594  return ret;
595  } else if (a->pos == 4) { /* dialplan add include CTX _X_ */
596  /* complete as 'into' if context exists or we are unable to check */
597  char *context, *dupline;
598  const char *s = skip_words(a->line, 3); /* should not fail */
599 
600  if (a->n != 0) /* only once */
601  return NULL;
602 
603  /* parse context from line ... */
604  context = dupline = strdup(s);
605  if (!context) {
606  ast_log(LOG_ERROR, "Out of free memory\n");
607  return strdup("into");
608  }
609  strsep(&dupline, " ");
610 
611  /* check for context existence ... */
612  if (ast_rdlock_contexts()) {
613  ast_log(LOG_ERROR, "Failed to lock context list\n");
614  /* our fault, we can't check, so complete 'into' ... */
615  ret = strdup("into");
616  } else {
617  struct ast_context *ctx;
618  for (ctx = NULL; !ret && (ctx = ast_walk_contexts(ctx)); )
619  if (!strcmp(context, ast_get_context_name(ctx)))
620  ret = strdup("into"); /* found */
622  }
623  free(context);
624  return ret;
625  } else if (a->pos == 5) { /* 'dialplan add include CTX into _X_' (dst context) */
626  char *context, *dupline, *into;
627  const char *s = skip_words(a->line, 3); /* should not fail */
628  context = dupline = strdup(s);
629  if (!dupline) {
630  ast_log(LOG_ERROR, "Out of free memory\n");
631  return NULL;
632  }
633  strsep(&dupline, " "); /* skip context */
634  into = strsep(&dupline, " ");
635  /* error if missing context or fifth word is not 'into' */
636  if (!strlen(context) || strcmp(into, "into")) {
637  ast_log(LOG_ERROR, "bad context %s or missing into %s\n",
638  context, into);
639  goto error3;
640  }
641 
642  if (ast_rdlock_contexts()) {
643  ast_log(LOG_ERROR, "Failed to lock context list\n");
644  goto error3;
645  }
646 
647  for (c = NULL; (c = ast_walk_contexts(c)); )
648  if (!strcmp(context, ast_get_context_name(c)))
649  break;
650  if (c) { /* first context exists, go on... */
651  /* go through all contexts ... */
652  for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
653  if (!strcmp(context, ast_get_context_name(c)))
654  continue; /* skip ourselves */
656  !lookup_ci(c, context) /* not included yet */ &&
657  ++which > a->n)
658  ret = strdup(ast_get_context_name(c));
659  }
660  } else {
661  ast_log(LOG_ERROR, "context %s not found\n", context);
662  }
664  error3:
665  free(context);
666  return ret;
667  }
668 
669  return NULL;
670 }
671 
672 /*!
673  * \brief 'save dialplan' CLI command implementation functions ...
674  */
675 static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
676 {
677  char filename[256], overrideswitch[256] = "";
678  struct ast_context *c;
679  struct ast_config *cfg;
680  struct ast_variable *v;
681  int incomplete = 0; /* incomplete config write? */
682  FILE *output;
683  struct ast_flags config_flags = { 0 };
684  const char *base, *slash;
685 
686  switch (cmd) {
687  case CLI_INIT:
688  e->command = "dialplan save";
689  e->usage =
690  "Usage: dialplan save [/path/to/extension/file]\n"
691  " Save dialplan created by pbx_config module.\n"
692  "\n"
693  "Example: dialplan save (/etc/asterisk/extensions.conf)\n"
694  " dialplan save /home/markster (/home/markster/extensions.conf)\n";
695  return NULL;
696  case CLI_GENERATE:
697  return NULL;
698  }
699 
700  if (! (static_config && !write_protect_config)) {
701  ast_cli(a->fd,
702  "I can't save dialplan now, see '%s' example file.\n",
703  config);
704  return CLI_FAILURE;
705  }
706 
707  if (a->argc != 2 && a->argc != 3)
708  return CLI_SHOWUSAGE;
709 
711  ast_cli(a->fd,
712  "Failed to lock dialplan saving (another proccess saving?)\n");
713  return CLI_FAILURE;
714  }
715  /* XXX the code here is quite loose, a pathname with .conf in it
716  * is assumed to be a complete pathname
717  */
718  if (a->argc == 3) { /* have config path. Look for *.conf */
719  base = a->argv[2];
720  if (!strstr(a->argv[2], ".conf")) { /*no, this is assumed to be a pathname */
721  /* if filename ends with '/', do not add one */
722  slash = (*(a->argv[2] + strlen(a->argv[2]) -1) == '/') ? "/" : "";
723  } else { /* yes, complete file name */
724  slash = "";
725  }
726  } else {
727  /* no config file, default one */
729  slash = "/";
730  }
731  snprintf(filename, sizeof(filename), "%s%s%s", base, slash, config);
732 
733  cfg = ast_config_load("extensions.conf", config_flags);
734  if (!cfg) {
735  ast_cli(a->fd, "Failed to load extensions.conf\n");
737  return CLI_FAILURE;
738  }
739 
740  /* try to lock contexts list */
741  if (ast_rdlock_contexts()) {
742  ast_cli(a->fd, "Failed to lock contexts list\n");
744  ast_config_destroy(cfg);
745  return CLI_FAILURE;
746  }
747 
748  /* create new file ... */
749  if (!(output = fopen(filename, "wt"))) {
750  ast_cli(a->fd, "Failed to create file '%s'\n",
751  filename);
754  ast_config_destroy(cfg);
755  return CLI_FAILURE;
756  }
757 
758  /* fireout general info */
759  if (overrideswitch_config) {
760  snprintf(overrideswitch, sizeof(overrideswitch), "overrideswitch=%s\n", overrideswitch_config);
761  }
762  fprintf(output, "[general]\nstatic=%s\nwriteprotect=%s\nautofallthrough=%s\nclearglobalvars=%s\n%sextenpatternmatchnew=%s\n\n",
763  static_config ? "yes" : "no",
764  write_protect_config ? "yes" : "no",
765  autofallthrough_config ? "yes" : "no",
766  clearglobalvars_config ? "yes" : "no",
767  overrideswitch_config ? overrideswitch : "",
768  extenpatternmatchnew_config ? "yes" : "no");
769 
770  if ((v = ast_variable_browse(cfg, "globals"))) {
771  fprintf(output, "[globals]\n");
772  while(v) {
773  fprintf(output, "%s => %s\n", v->name, v->value);
774  v = v->next;
775  }
776  fprintf(output, "\n");
777  }
778 
779  ast_config_destroy(cfg);
780 
781 #define PUT_CTX_HDR do { \
782  if (!context_header_written) { \
783  fprintf(output, "[%s]\n", ast_get_context_name(c)); \
784  context_header_written = 1; \
785  } \
786  } while (0)
787 
788  /* walk all contexts */
789  for (c = NULL; (c = ast_walk_contexts(c)); ) {
790  int context_header_written = 0;
791  struct ast_exten *ext, *last_written_e = NULL;
792  struct ast_include *i;
793  struct ast_ignorepat *ip;
794  struct ast_sw *sw;
795 
796  /* try to lock context and fireout all info */
797  if (ast_rdlock_context(c)) { /* lock failure */
798  incomplete = 1;
799  continue;
800  }
801  /* registered by this module? */
802  /* XXX do we need this ? */
803  if (!strcmp(ast_get_context_registrar(c), registrar)) {
804  fprintf(output, "[%s]\n", ast_get_context_name(c));
805  context_header_written = 1;
806  }
807 
808  /* walk extensions ... */
809  for (ext = NULL; (ext = ast_walk_context_extensions(c, ext)); ) {
810  struct ast_exten *p = NULL;
811 
812  /* fireout priorities */
813  while ( (p = ast_walk_extension_priorities(ext, p)) ) {
814  if (strcmp(ast_get_extension_registrar(p), registrar) != 0) /* not this source */
815  continue;
816 
817  /* make empty line between different extensions */
818  if (last_written_e != NULL &&
819  strcmp(ast_get_extension_name(last_written_e),
821  fprintf(output, "\n");
822  last_written_e = p;
823 
824  PUT_CTX_HDR;
825 
826  if (ast_get_extension_priority(p) == PRIORITY_HINT) { /* easy */
827  fprintf(output, "exten => %s,hint,%s\n",
830  } else {
831  const char *sep, *cid;
832  const char *el = ast_get_extension_label(p);
833  char label[128] = "";
834 
836  sep = "/";
838  } else
839  sep = cid = "";
840 
841  if (el && (snprintf(label, sizeof(label), "(%s)", el) != (strlen(el) + 2)))
842  incomplete = 1; /* error encountered or label > 125 chars */
843 
844  fprintf(output, "exten => %s%s%s,%d%s,%s(%s)\n",
845  ast_get_extension_name(p), (ast_strlen_zero(sep) ? "" : sep), (ast_strlen_zero(cid) ? "" : cid),
846  ast_get_extension_priority(p), label,
848  }
849  }
850  }
851 
852  /* written any extensions? ok, write space between exten & inc */
853  if (last_written_e)
854  fprintf(output, "\n");
855 
856  /* walk through includes */
857  for (i = NULL; (i = ast_walk_context_includes(c, i)) ; ) {
858  if (strcmp(ast_get_include_registrar(i), registrar) != 0)
859  continue; /* not mine */
860  PUT_CTX_HDR;
861  fprintf(output, "include => %s\n", ast_get_include_name(i));
862  }
863  if (ast_walk_context_includes(c, NULL))
864  fprintf(output, "\n");
865 
866  /* walk through switches */
867  for (sw = NULL; (sw = ast_walk_context_switches(c, sw)) ; ) {
868  if (strcmp(ast_get_switch_registrar(sw), registrar) != 0)
869  continue; /* not mine */
870  PUT_CTX_HDR;
871  fprintf(output, "switch => %s/%s\n",
873  }
874 
875  if (ast_walk_context_switches(c, NULL))
876  fprintf(output, "\n");
877 
878  /* fireout ignorepats ... */
879  for (ip = NULL; (ip = ast_walk_context_ignorepats(c, ip)); ) {
880  if (strcmp(ast_get_ignorepat_registrar(ip), registrar) != 0)
881  continue; /* not mine */
882  PUT_CTX_HDR;
883  fprintf(output, "ignorepat => %s\n",
885  }
886 
888  }
889 
892  fclose(output);
893 
894  if (incomplete) {
895  ast_cli(a->fd, "Saved dialplan is incomplete\n");
896  return CLI_FAILURE;
897  }
898 
899  ast_cli(a->fd, "Dialplan successfully saved into '%s'\n",
900  filename);
901  return CLI_SUCCESS;
902 }
903 
904 /*!
905  * \brief ADD EXTENSION command stuff
906  */
907 static char *handle_cli_dialplan_add_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
908 {
909  char *whole_exten;
910  char *exten, *prior;
911  int iprior = -2;
912  char *cidmatch, *app, *app_data;
913  char *start, *end;
914 
915  switch (cmd) {
916  case CLI_INIT:
917  e->command = "dialplan add extension";
918  e->usage =
919  "Usage: dialplan add extension <exten>,<priority>,<app> into <context> [replace]\n"
920  "\n"
921  " app can be either:\n"
922  " app-name\n"
923  " app-name(app-data)\n"
924  " app-name,<app-data>\n"
925  "\n"
926  " This command will add the new extension into <context>. If\n"
927  " an extension with the same priority already exists and the\n"
928  " 'replace' option is given we will replace the extension.\n"
929  "\n"
930  "Example: dialplan add extension 6123,1,Dial,IAX/216.207.245.56/6123 into local\n"
931  " Now, you can dial 6123 and talk to Markster :)\n";
932  return NULL;
933  case CLI_GENERATE:
935  }
936 
937  /* check for arguments at first */
938  if (a->argc != 6 && a->argc != 7)
939  return CLI_SHOWUSAGE;
940  if (strcmp(a->argv[4], "into"))
941  return CLI_SHOWUSAGE;
942  if (a->argc == 7)
943  if (strcmp(a->argv[6], "replace"))
944  return CLI_SHOWUSAGE;
945 
946  whole_exten = ast_strdupa(a->argv[3]);
947  exten = strsep(&whole_exten,",");
948  if (strchr(exten, '/')) {
949  cidmatch = exten;
950  strsep(&cidmatch,"/");
951  } else {
952  cidmatch = NULL;
953  }
954  prior = strsep(&whole_exten,",");
955  if (prior) {
956  if (!strcmp(prior, "hint")) {
957  iprior = PRIORITY_HINT;
958  } else {
959  if (sscanf(prior, "%30d", &iprior) != 1) {
960  ast_cli(a->fd, "'%s' is not a valid priority\n", prior);
961  prior = NULL;
962  }
963  }
964  }
965  app = whole_exten;
966  if (app) {
967  if ((start = strchr(app, '(')) && (end = strrchr(app, ')'))) {
968  *start = *end = '\0';
969  app_data = start + 1;
970  } else {
971  app_data = strchr(app, ',');
972  if (app_data) {
973  *app_data++ = '\0';
974  }
975  }
976  } else {
977  app_data = NULL;
978  }
979 
980  if (!exten || !prior || !app) {
981  return CLI_SHOWUSAGE;
982  }
983 
984  if (!app_data)
985  app_data="";
986  if (ast_add_extension(a->argv[5], a->argc == 7 ? 1 : 0, exten, iprior, NULL, cidmatch, app,
987  ast_strdup(app_data), ast_free_ptr, registrar)) {
988  switch (errno) {
989  case ENOMEM:
990  ast_cli(a->fd, "Out of free memory\n");
991  break;
992 
993  case EBUSY:
994  ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
995  break;
996 
997  case ENOENT:
998  ast_cli(a->fd, "No existence of '%s' context\n", a->argv[5]);
999  break;
1000 
1001  case EEXIST:
1002  ast_cli(a->fd, "Extension %s@%s with priority %s already exists\n",
1003  exten, a->argv[5], prior);
1004  break;
1005 
1006  default:
1007  ast_cli(a->fd, "Failed to add '%s,%s,%s(%s)' extension into '%s' context\n",
1008  exten, prior, app, app_data, a->argv[5]);
1009  break;
1010  }
1011  return CLI_FAILURE;
1012  }
1013 
1014  if (a->argc == 7) {
1015  ast_cli(a->fd, "Extension %s@%s (%s) replace by '%s,%s,%s(%s)'\n",
1016  exten, a->argv[5], prior, exten, prior, app, app_data);
1017  } else {
1018  ast_cli(a->fd, "Extension '%s,%s,%s(%s)' added into '%s' context\n",
1019  exten, prior, app, app_data, a->argv[5]);
1020  }
1021 
1022  return CLI_SUCCESS;
1023 }
1024 
1025 /*! dialplan add extension 6123,1,Dial,IAX/212.71.138.13/6123 into local */
1027 {
1028  int which = 0;
1029 
1030  if (a->pos == 4) { /* complete 'into' word ... */
1031  return (a->n == 0) ? strdup("into") : NULL;
1032  } else if (a->pos == 5) { /* complete context */
1033  struct ast_context *c = NULL;
1034  int len = strlen(a->word);
1035  char *res = NULL;
1036 
1037  /* try to lock contexts list ... */
1038  if (ast_rdlock_contexts()) {
1039  ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1040  return NULL;
1041  }
1042 
1043  /* walk through all contexts */
1044  while ( !res && (c = ast_walk_contexts(c)) )
1045  if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
1046  res = strdup(ast_get_context_name(c));
1048  return res;
1049  } else if (a->pos == 6) {
1050  return a->n == 0 ? strdup("replace") : NULL;
1051  }
1052  return NULL;
1053 }
1054 
1055 /*!
1056  * IGNOREPAT CLI stuff
1057  */
1058 static char *handle_cli_dialplan_add_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1059 {
1060  switch (cmd) {
1061  case CLI_INIT:
1062  e->command = "dialplan add ignorepat";
1063  e->usage =
1064  "Usage: dialplan add ignorepat <pattern> into <context>\n"
1065  " This command adds a new ignore pattern into context <context>\n"
1066  "\n"
1067  "Example: dialplan add ignorepat _3XX into local\n";
1068  return NULL;
1069  case CLI_GENERATE:
1071  }
1072 
1073  if (a->argc != 6)
1074  return CLI_SHOWUSAGE;
1075 
1076  if (strcmp(a->argv[4], "into"))
1077  return CLI_SHOWUSAGE;
1078 
1079  if (ast_context_add_ignorepat(a->argv[5], a->argv[3], registrar)) {
1080  switch (errno) {
1081  case ENOMEM:
1082  ast_cli(a->fd, "Out of free memory\n");
1083  break;
1084 
1085  case ENOENT:
1086  ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
1087  break;
1088 
1089  case EEXIST:
1090  ast_cli(a->fd, "Ignore pattern '%s' already included in '%s' context\n",
1091  a->argv[3], a->argv[5]);
1092  break;
1093 
1094  case EBUSY:
1095  ast_cli(a->fd, "Failed to lock context(s) list, please, try again later\n");
1096  break;
1097 
1098  default:
1099  ast_cli(a->fd, "Failed to add ingore pattern '%s' into '%s' context\n",
1100  a->argv[3], a->argv[5]);
1101  break;
1102  }
1103  return CLI_FAILURE;
1104  }
1105 
1106  ast_cli(a->fd, "Ignore pattern '%s' added into '%s' context\n",
1107  a->argv[3], a->argv[5]);
1108 
1109  return CLI_SUCCESS;
1110 }
1111 
1113 {
1114  if (a->pos == 4)
1115  return a->n == 0 ? strdup("into") : NULL;
1116  else if (a->pos == 5) {
1117  struct ast_context *c;
1118  int which = 0;
1119  char *dupline, *ignorepat = NULL;
1120  const char *s;
1121  char *ret = NULL;
1122  int len = strlen(a->word);
1123 
1124  /* XXX skip first three words 'dialplan' 'add' 'ignorepat' */
1125  s = skip_words(a->line, 3);
1126  if (s == NULL)
1127  return NULL;
1128  dupline = strdup(s);
1129  if (!dupline) {
1130  ast_log(LOG_ERROR, "Malloc failure\n");
1131  return NULL;
1132  }
1133  ignorepat = strsep(&dupline, " ");
1134 
1135  if (ast_rdlock_contexts()) {
1136  ast_log(LOG_ERROR, "Failed to lock contexts list\n");
1137  return NULL;
1138  }
1139 
1140  for (c = NULL; !ret && (c = ast_walk_contexts(c));) {
1141  int found = 0;
1142 
1144  continue; /* not mine */
1145  if (ignorepat) /* there must be one, right ? */
1146  found = lookup_c_ip(c, ignorepat);
1147  if (!found && ++which > a->n)
1148  ret = strdup(ast_get_context_name(c));
1149  }
1150 
1151  free(ignorepat);
1153  return ret;
1154  }
1155 
1156  return NULL;
1157 }
1158 
1159 static char *handle_cli_dialplan_remove_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1160 {
1161  switch (cmd) {
1162  case CLI_INIT:
1163  e->command = "dialplan remove ignorepat";
1164  e->usage =
1165  "Usage: dialplan remove ignorepat <pattern> from <context>\n"
1166  " This command removes an ignore pattern from context <context>\n"
1167  "\n"
1168  "Example: dialplan remove ignorepat _3XX from local\n";
1169  return NULL;
1170  case CLI_GENERATE:
1172  }
1173 
1174  if (a->argc != 6)
1175  return CLI_SHOWUSAGE;
1176 
1177  if (strcmp(a->argv[4], "from"))
1178  return CLI_SHOWUSAGE;
1179 
1180  if (ast_context_remove_ignorepat(a->argv[5], a->argv[3], registrar)) {
1181  switch (errno) {
1182  case EBUSY:
1183  ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
1184  break;
1185 
1186  case ENOENT:
1187  ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
1188  break;
1189 
1190  case EINVAL:
1191  ast_cli(a->fd, "There is no existence of '%s' ignore pattern in '%s' context\n",
1192  a->argv[3], a->argv[5]);
1193  break;
1194 
1195  default:
1196  ast_cli(a->fd, "Failed to remove ignore pattern '%s' from '%s' context\n",
1197  a->argv[3], a->argv[5]);
1198  break;
1199  }
1200  return CLI_FAILURE;
1201  }
1202 
1203  ast_cli(a->fd, "Ignore pattern '%s' removed from '%s' context\n",
1204  a->argv[3], a->argv[5]);
1205  return CLI_SUCCESS;
1206 }
1207 
1209 {
1210  struct ast_context *c;
1211  int which = 0;
1212  char *ret = NULL;
1213 
1214  if (a->pos == 3) {
1215  int len = strlen(a->word);
1216  if (ast_rdlock_contexts()) {
1217  ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1218  return NULL;
1219  }
1220 
1221  for (c = NULL; !ret && (c = ast_walk_contexts(c));) {
1222  struct ast_ignorepat *ip;
1223 
1224  if (ast_rdlock_context(c)) /* error, skip it */
1225  continue;
1226 
1227  for (ip = NULL; !ret && (ip = ast_walk_context_ignorepats(c, ip));) {
1228  if (partial_match(ast_get_ignorepat_name(ip), a->word, len) && ++which > a->n) {
1229  /* n-th match */
1230  struct ast_context *cw = NULL;
1231  int found = 0;
1232  while ( (cw = ast_walk_contexts(cw)) && cw != c && !found) {
1233  /* XXX do i stop on c, or skip it ? */
1234  found = lookup_c_ip(cw, ast_get_ignorepat_name(ip));
1235  }
1236  if (!found)
1237  ret = strdup(ast_get_ignorepat_name(ip));
1238  }
1239  }
1240  ast_unlock_context(c);
1241  }
1243  return ret;
1244  } else if (a->pos == 4) {
1245  return a->n == 0 ? strdup("from") : NULL;
1246  } else if (a->pos == 5) { /* XXX check this */
1247  char *dupline, *duplinet, *ignorepat;
1248  int len = strlen(a->word);
1249 
1250  dupline = strdup(a->line);
1251  if (!dupline) {
1252  ast_log(LOG_WARNING, "Out of free memory\n");
1253  return NULL;
1254  }
1255 
1256  duplinet = dupline;
1257  strsep(&duplinet, " ");
1258  strsep(&duplinet, " ");
1259  ignorepat = strsep(&duplinet, " ");
1260 
1261  if (!ignorepat) {
1262  free(dupline);
1263  return NULL;
1264  }
1265 
1266  if (ast_rdlock_contexts()) {
1267  ast_log(LOG_WARNING, "Failed to lock contexts list\n");
1268  free(dupline);
1269  return NULL;
1270  }
1271 
1272  for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
1273  if (ast_rdlock_context(c)) /* fail, skip it */
1274  continue;
1276  continue;
1277  if (lookup_c_ip(c, ignorepat) && ++which > a->n)
1278  ret = strdup(ast_get_context_name(c));
1279  ast_unlock_context(c);
1280  }
1282  free(dupline);
1283  return NULL;
1284  }
1285 
1286  return NULL;
1287 }
1288 
1289 static int pbx_load_module(void);
1290 
1291 static char *handle_cli_dialplan_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1292 {
1293  switch (cmd) {
1294  case CLI_INIT:
1295  e->command = "dialplan reload";
1296  e->usage =
1297  "Usage: dialplan reload\n"
1298  " Reload extensions.conf without reloading any other\n"
1299  " modules. This command does not delete global variables\n"
1300  " unless clearglobalvars is set to yes in extensions.conf\n";
1301  return NULL;
1302  case CLI_GENERATE:
1303  return NULL;
1304  }
1305 
1306  if (a->argc != 2)
1307  return CLI_SHOWUSAGE;
1308 
1309  if (clearglobalvars_config)
1311 
1312  pbx_load_module();
1313  ast_cli(a->fd, "Dialplan reloaded.\n");
1314  return CLI_SUCCESS;
1315 }
1316 
1317 /*!
1318  * CLI entries for commands provided by this module
1319  */
1320 static struct ast_cli_entry cli_pbx_config[] = {
1321  AST_CLI_DEFINE(handle_cli_dialplan_add_extension, "Add new extension into context"),
1322  AST_CLI_DEFINE(handle_cli_dialplan_remove_extension, "Remove a specified extension"),
1323  AST_CLI_DEFINE(handle_cli_dialplan_add_ignorepat, "Add new ignore pattern"),
1324  AST_CLI_DEFINE(handle_cli_dialplan_remove_ignorepat, "Remove ignore pattern from context"),
1325  AST_CLI_DEFINE(handle_cli_dialplan_add_include, "Include context in other context"),
1326  AST_CLI_DEFINE(handle_cli_dialplan_remove_include, "Remove a specified include from context"),
1327  AST_CLI_DEFINE(handle_cli_dialplan_reload, "Reload extensions and *only* extensions"),
1328  AST_CLI_DEFINE(handle_cli_dialplan_save, "Save current dialplan into a file")
1329 };
1330 
1332  AST_CLI_DEFINE(handle_cli_dialplan_save, "Save dialplan");
1333 
1334 /*!
1335  * Standard module functions ...
1336  */
1337 static int unload_module(void)
1338 {
1339  if (static_config && !write_protect_config)
1340  ast_cli_unregister(&cli_dialplan_save);
1341  if (overrideswitch_config) {
1342  ast_free(overrideswitch_config);
1343  }
1344  ast_cli_unregister_multiple(cli_pbx_config, ARRAY_LEN(cli_pbx_config));
1345  ast_context_destroy(NULL, registrar);
1346  return 0;
1347 }
1348 
1349 /*!\note Protect against misparsing based upon commas in the middle of fields
1350  * like character classes. We've taken steps to permit pretty much every other
1351  * printable character in a character class, so properly handling a comma at
1352  * this level is a natural extension. This is almost like the standard
1353  * application parser in app.c, except that it handles square brackets. */
1354 static char *pbx_strsep(char **destructible, const char *delim)
1355 {
1356  int square = 0;
1357  char *res;
1358 
1359  if (!destructible || !*destructible) {
1360  return NULL;
1361  }
1362  res = *destructible;
1363  for (; **destructible; (*destructible)++) {
1364  if (**destructible == '[' && !strchr(delim, '[')) {
1365  square++;
1366  } else if (**destructible == ']' && !strchr(delim, ']')) {
1367  if (square) {
1368  square--;
1369  }
1370  } else if (**destructible == '\\' && !strchr(delim, '\\')) {
1371  (*destructible)++;
1372  } else if (strchr(delim, **destructible) && !square) {
1373  **destructible = '\0';
1374  (*destructible)++;
1375  break;
1376  }
1377  }
1378  if (**destructible == '\0') {
1379  *destructible = NULL;
1380  }
1381  return res;
1382 }
1383 
1384 static int pbx_load_config(const char *config_file)
1385 {
1386  struct ast_config *cfg;
1387  char *end;
1388  char *label;
1389 #ifdef LOW_MEMORY
1390  char realvalue[256];
1391 #else
1392  char realvalue[8192];
1393 #endif
1394  int lastpri = -2;
1395  struct ast_context *con;
1396  struct ast_variable *v;
1397  const char *cxt;
1398  const char *aft;
1399  const char *newpm, *ovsw;
1400  struct ast_flags config_flags = { 0 };
1401  char lastextension[256];
1402  cfg = ast_config_load(config_file, config_flags);
1403  if (!cfg || cfg == CONFIG_STATUS_FILEINVALID)
1404  return 0;
1405 
1406  /* Use existing config to populate the PBX table */
1407  static_config = ast_true(ast_variable_retrieve(cfg, "general", "static"));
1408  write_protect_config = ast_true(ast_variable_retrieve(cfg, "general", "writeprotect"));
1409  if ((aft = ast_variable_retrieve(cfg, "general", "autofallthrough")))
1410  autofallthrough_config = ast_true(aft);
1411  if ((newpm = ast_variable_retrieve(cfg, "general", "extenpatternmatchnew")))
1412  extenpatternmatchnew_config = ast_true(newpm);
1413  clearglobalvars_config = ast_true(ast_variable_retrieve(cfg, "general", "clearglobalvars"));
1414  if ((ovsw = ast_variable_retrieve(cfg, "general", "overrideswitch"))) {
1415  if (overrideswitch_config) {
1416  ast_free(overrideswitch_config);
1417  }
1418  if (!ast_strlen_zero(ovsw)) {
1419  overrideswitch_config = ast_strdup(ovsw);
1420  } else {
1421  overrideswitch_config = NULL;
1422  }
1423  }
1424 
1425  ast_copy_string(userscontext, ast_variable_retrieve(cfg, "general", "userscontext") ?: "default", sizeof(userscontext));
1426 
1427  for (v = ast_variable_browse(cfg, "globals"); v; v = v->next) {
1428  pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1429  pbx_builtin_setvar_helper(NULL, v->name, realvalue);
1430  }
1431  for (cxt = ast_category_browse(cfg, NULL);
1432  cxt;
1433  cxt = ast_category_browse(cfg, cxt)) {
1434  /* All categories but "general" or "globals" are considered contexts */
1435  if (!strcasecmp(cxt, "general") || !strcasecmp(cxt, "globals")) {
1436  continue;
1437  }
1438  if (!(con = ast_context_find_or_create(&local_contexts, local_table, cxt, registrar))) {
1439  continue;
1440  }
1441 
1442  /* Reset continuation items at the beginning of each context */
1443  lastextension[0] = '\0';
1444  lastpri = -2;
1445 
1446  for (v = ast_variable_browse(cfg, cxt); v; v = v->next) {
1447  char *tc = NULL;
1448  char realext[256] = "";
1449  char *stringp, *ext;
1450  const char *vfile;
1451 
1452  /* get filename for error reporting from top level or an #include */
1453  vfile = !*v->file ? config_file : v->file;
1454 
1455  if (!strncasecmp(v->name, "same", 4)) {
1456  if (ast_strlen_zero(lastextension)) {
1458  "No previous pattern in the first entry of context '%s' to match '%s' at line %d of %s!\n",
1459  cxt, v->name, v->lineno, vfile);
1460  continue;
1461  }
1462  if ((stringp = tc = ast_strdup(v->value))) {
1463  ast_copy_string(realext, lastextension, sizeof(realext));
1464  goto process_extension;
1465  }
1466  } else if (!strcasecmp(v->name, "exten")) {
1467  int ipri;
1468  char *plus;
1469  char *pri, *appl, *data, *cidmatch;
1470 
1471  if (!(stringp = tc = ast_strdup(v->value))) {
1472  continue;
1473  }
1474 
1475  ext = S_OR(pbx_strsep(&stringp, ","), "");
1476  pbx_substitute_variables_helper(NULL, ext, realext, sizeof(realext) - 1);
1477  ast_copy_string(lastextension, realext, sizeof(lastextension));
1478 process_extension:
1479  ipri = -2;
1480  if ((cidmatch = strchr(realext, '/'))) {
1481  *cidmatch++ = '\0';
1482  ast_shrink_phone_number(cidmatch);
1483  }
1484  pri = ast_strip(S_OR(strsep(&stringp, ","), ""));
1485  if ((label = strchr(pri, '('))) {
1486  *label++ = '\0';
1487  if ((end = strchr(label, ')'))) {
1488  *end = '\0';
1489  } else {
1491  "Label missing trailing ')' at line %d of %s\n",
1492  v->lineno, vfile);
1493  ast_free(tc);
1494  continue;
1495  }
1496  }
1497  if ((plus = strchr(pri, '+'))) {
1498  *plus++ = '\0';
1499  }
1500  if (!strcmp(pri,"hint")) {
1501  ipri = PRIORITY_HINT;
1502  } else if (!strcmp(pri, "next") || !strcmp(pri, "n")) {
1503  if (lastpri > -2) {
1504  ipri = lastpri + 1;
1505  } else {
1507  "Can't use 'next' priority on the first entry at line %d of %s!\n",
1508  v->lineno, vfile);
1509  ast_free(tc);
1510  continue;
1511  }
1512  } else if (!strcmp(pri, "same") || !strcmp(pri, "s")) {
1513  if (lastpri > -2) {
1514  ipri = lastpri;
1515  } else {
1517  "Can't use 'same' priority on the first entry at line %d of %s!\n",
1518  v->lineno, vfile);
1519  ast_free(tc);
1520  continue;
1521  }
1522  } else if (sscanf(pri, "%30d", &ipri) != 1 &&
1523  (ipri = ast_findlabel_extension2(NULL, con, realext, pri, cidmatch)) < 1) {
1525  "Invalid priority/label '%s' at line %d of %s\n",
1526  pri, v->lineno, vfile);
1527  ipri = 0;
1528  ast_free(tc);
1529  continue;
1530  } else if (ipri < 1) {
1531  ast_log(LOG_WARNING, "Invalid priority '%s' at line %d of %s\n",
1532  pri, v->lineno, vfile);
1533  ast_free(tc);
1534  continue;
1535  }
1536  appl = S_OR(stringp, "");
1537  /* Find the first occurrence of '(' */
1538  if (!strchr(appl, '(')) {
1539  /* No arguments */
1540  data = "";
1541  } else {
1542  char *orig_appl = ast_strdup(appl);
1543 
1544  if (!orig_appl) {
1545  ast_free(tc);
1546  continue;
1547  }
1548 
1549  appl = strsep(&stringp, "(");
1550 
1551  /* check if there are variables or expressions without an application, like: exten => 100,hint,DAHDI/g0/${GLOBAL(var)} */
1552  if (strstr(appl, "${") || strstr(appl, "$[")){
1553  /* set appl to original one */
1554  strcpy(appl, orig_appl);
1555  /* set no data */
1556  data = "";
1557  /* no variable before application found -> go ahead */
1558  } else {
1559  data = S_OR(stringp, "");
1560  if ((end = strrchr(data, ')'))) {
1561  *end = '\0';
1562  } else {
1564  "No closing parenthesis found? '%s(%s' at line %d of %s\n",
1565  appl, data, v->lineno, vfile);
1566  }
1567  }
1568  ast_free(orig_appl);
1569  }
1570 
1571  appl = ast_skip_blanks(appl);
1572  if (ipri) {
1573  if (plus) {
1574  ipri += atoi(plus);
1575  }
1576  lastpri = ipri;
1577  if (!ast_opt_dont_warn && (!strcmp(realext, "_.") || !strcmp(realext, "_!"))) {
1579  "The use of '%s' for an extension is strongly discouraged and can have unexpected behavior. Please use '_X%c' instead at line %d of %s\n",
1580  realext, realext[1], v->lineno, vfile);
1581  }
1582  if (ast_add_extension2(con, 0, realext, ipri, label, cidmatch, appl, ast_strdup(data), ast_free_ptr, registrar)) {
1584  "Unable to register extension at line %d of %s\n",
1585  v->lineno, vfile);
1586  }
1587  }
1588  ast_free(tc);
1589  } else if (!strcasecmp(v->name, "include")) {
1590  pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1591  if (ast_context_add_include2(con, realvalue, registrar)) {
1592  switch (errno) {
1593  case ENOMEM:
1594  ast_log(LOG_WARNING, "Out of memory for context addition\n");
1595  break;
1596 
1597  case EBUSY:
1598  ast_log(LOG_WARNING, "Failed to lock context(s) list, please try again later\n");
1599  break;
1600 
1601  case EEXIST:
1603  "Context '%s' already included in '%s' context on include at line %d of %s\n",
1604  v->value, cxt, v->lineno, vfile);
1605  break;
1606 
1607  case ENOENT:
1608  case EINVAL:
1610  "There is no existence of context '%s' included at line %d of %s\n",
1611  errno == ENOENT ? v->value : cxt, v->lineno, vfile);
1612  break;
1613 
1614  default:
1616  "Failed to include '%s' in '%s' context at line %d of %s\n",
1617  v->value, cxt, v->lineno, vfile);
1618  break;
1619  }
1620  }
1621  } else if (!strcasecmp(v->name, "ignorepat")) {
1622  pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1623  if (ast_context_add_ignorepat2(con, realvalue, registrar)) {
1625  "Unable to include ignorepat '%s' in context '%s' at line %d of %s\n",
1626  v->value, cxt, v->lineno, vfile);
1627  }
1628  } else if (!strcasecmp(v->name, "switch") || !strcasecmp(v->name, "lswitch") || !strcasecmp(v->name, "eswitch")) {
1629  char *stringp = realvalue;
1630  char *appl, *data;
1631 
1632  if (!strcasecmp(v->name, "switch")) {
1633  pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
1634  } else {
1635  ast_copy_string(realvalue, v->value, sizeof(realvalue));
1636  }
1637  appl = strsep(&stringp, "/");
1638  data = S_OR(stringp, "");
1639  if (ast_context_add_switch2(con, appl, data, !strcasecmp(v->name, "eswitch"), registrar)) {
1641  "Unable to include switch '%s' in context '%s' at line %d of %s\n",
1642  v->value, cxt, v->lineno, vfile);
1643  }
1644  } else {
1646  "==!!== Unknown directive: %s at line %d of %s -- IGNORING!!!\n",
1647  v->name, v->lineno, vfile);
1648  }
1649  }
1650  }
1651  ast_config_destroy(cfg);
1652  return 1;
1653 }
1654 
1655 static void append_interface(char *iface, int maxlen, char *add)
1656 {
1657  int len = strlen(iface);
1658  if (strlen(add) + len < maxlen - 2) {
1659  if (strlen(iface)) {
1660  iface[len] = '&';
1661  strcpy(iface + len + 1, add);
1662  } else
1663  strcpy(iface, add);
1664  }
1665 }
1666 
1667 static void pbx_load_users(void)
1668 {
1669  struct ast_config *cfg;
1670  char *cat, *chan;
1671  const char *dahdichan;
1672  const char *hasexten, *altexts;
1673  char tmp[256];
1674  char iface[256];
1675  char dahdicopy[256];
1676  char *ext, altcopy[256];
1677  char *c;
1678  int hasvoicemail;
1679  int start, finish, x;
1680  struct ast_context *con = NULL;
1681  struct ast_flags config_flags = { 0 };
1682 
1683  cfg = ast_config_load("users.conf", config_flags);
1684  if (!cfg)
1685  return;
1686 
1687  for (cat = ast_category_browse(cfg, NULL); cat ; cat = ast_category_browse(cfg, cat)) {
1688  if (!strcasecmp(cat, "general"))
1689  continue;
1690  iface[0] = '\0';
1691  if (ast_true(ast_config_option(cfg, cat, "hassip"))) {
1692  snprintf(tmp, sizeof(tmp), "SIP/%s", cat);
1693  append_interface(iface, sizeof(iface), tmp);
1694  }
1695  if (ast_true(ast_config_option(cfg, cat, "hasiax"))) {
1696  snprintf(tmp, sizeof(tmp), "IAX2/%s", cat);
1697  append_interface(iface, sizeof(iface), tmp);
1698  }
1699  if (ast_true(ast_config_option(cfg, cat, "hash323"))) {
1700  snprintf(tmp, sizeof(tmp), "H323/%s", cat);
1701  append_interface(iface, sizeof(iface), tmp);
1702  }
1703  hasexten = ast_config_option(cfg, cat, "hasexten");
1704  if (hasexten && !ast_true(hasexten))
1705  continue;
1706  hasvoicemail = ast_true(ast_config_option(cfg, cat, "hasvoicemail"));
1707  dahdichan = ast_variable_retrieve(cfg, cat, "dahdichan");
1708  if (!dahdichan)
1709  dahdichan = ast_variable_retrieve(cfg, "general", "dahdichan");
1710  if (!ast_strlen_zero(dahdichan)) {
1711  ast_copy_string(dahdicopy, dahdichan, sizeof(dahdicopy));
1712  c = dahdicopy;
1713  chan = strsep(&c, ",");
1714  while (chan) {
1715  if (sscanf(chan, "%30d-%30d", &start, &finish) == 2) {
1716  /* Range */
1717  } else if (sscanf(chan, "%30d", &start)) {
1718  /* Just one */
1719  finish = start;
1720  } else {
1721  start = 0; finish = 0;
1722  }
1723  if (finish < start) {
1724  x = finish;
1725  finish = start;
1726  start = x;
1727  }
1728  for (x = start; x <= finish; x++) {
1729  snprintf(tmp, sizeof(tmp), "DAHDI/%d", x);
1730  append_interface(iface, sizeof(iface), tmp);
1731  }
1732  chan = strsep(&c, ",");
1733  }
1734  }
1735  if (!ast_strlen_zero(iface)) {
1736  /* Only create a context here when it is really needed. Otherwise default empty context
1737  created by pbx_config may conflict with the one explicitly created by pbx_ael */
1738  if (!con)
1739  con = ast_context_find_or_create(&local_contexts, local_table, userscontext, registrar);
1740 
1741  if (!con) {
1742  ast_log(LOG_ERROR, "Can't find/create user context '%s'\n", userscontext);
1743  return;
1744  }
1745 
1746  /* Add hint */
1747  ast_add_extension2(con, 0, cat, -1, NULL, NULL, iface, NULL, NULL, registrar);
1748  /* If voicemail, use "stdexten" else use plain old dial */
1749  if (hasvoicemail) {
1750  snprintf(tmp, sizeof(tmp), "stdexten,%s,${HINT}", cat);
1751  ast_add_extension2(con, 0, cat, 1, NULL, NULL, "Macro", ast_strdup(tmp), ast_free_ptr, registrar);
1752  } else {
1753  ast_add_extension2(con, 0, cat, 1, NULL, NULL, "Dial", ast_strdup("${HINT}"), ast_free_ptr, registrar);
1754  }
1755  altexts = ast_variable_retrieve(cfg, cat, "alternateexts");
1756  if (!ast_strlen_zero(altexts)) {
1757  snprintf(tmp, sizeof(tmp), "%s,1", cat);
1758  ast_copy_string(altcopy, altexts, sizeof(altcopy));
1759  c = altcopy;
1760  ext = strsep(&c, ",");
1761  while (ext) {
1762  ast_add_extension2(con, 0, ext, 1, NULL, NULL, "Goto", ast_strdup(tmp), ast_free_ptr, registrar);
1763  ext = strsep(&c, ",");
1764  }
1765  }
1766  }
1767  }
1768  ast_config_destroy(cfg);
1769 }
1770 
1771 static int pbx_load_module(void)
1772 {
1773  struct ast_context *con;
1774 
1776 
1777  if (!local_table)
1779 
1780  if (!pbx_load_config(config)) {
1782  return AST_MODULE_LOAD_DECLINE;
1783  }
1784 
1785  pbx_load_users();
1786 
1787  ast_merge_contexts_and_delete(&local_contexts, local_table, registrar);
1788  local_table = NULL; /* the local table has been moved into the global one. */
1789  local_contexts = NULL;
1790 
1792 
1793  for (con = NULL; (con = ast_walk_contexts(con));)
1795 
1796  pbx_set_overrideswitch(overrideswitch_config);
1797  pbx_set_autofallthrough(autofallthrough_config);
1798  pbx_set_extenpatternmatchnew(extenpatternmatchnew_config);
1799 
1800  return AST_MODULE_LOAD_SUCCESS;
1801 }
1802 
1803 static int load_module(void)
1804 {
1805  if (static_config && !write_protect_config)
1806  ast_cli_register(&cli_dialplan_save);
1807  ast_cli_register_multiple(cli_pbx_config, ARRAY_LEN(cli_pbx_config));
1808 
1809  if (pbx_load_module())
1810  return AST_MODULE_LOAD_DECLINE;
1811 
1812  return AST_MODULE_LOAD_SUCCESS;
1813 }
1814 
1815 static int reload(void)
1816 {
1817  if (clearglobalvars_config)
1819  return pbx_load_module();
1820 }
1821 
1822 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Text Extension Configuration",
1823  .load = load_module,
1824  .unload = unload_module,
1825  .reload = reload,
1826  );
struct ast_include * ast_walk_context_includes(struct ast_context *con, struct ast_include *inc)
Definition: pbx.c:11203
ast_include: include= support in extensions.conf
Definition: pbx.c:904
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: pbx.c:4676
static int clearglobalvars_config
Definition: pbx_config.c:52
int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b)
hashtable functions for contexts
Definition: pbx.c:1136
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static int pbx_load_config(const char *config_file)
Definition: pbx_config.c:1384
static char * handle_cli_dialplan_remove_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pbx_config.c:79
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
static int autofallthrough_config
Definition: pbx_config.c:51
int ast_context_add_include2(struct ast_context *con, const char *include, const char *registrar)
Add a context include.
Definition: pbx.c:8411
int ast_get_extension_priority(struct ast_exten *exten)
Definition: pbx.c:11103
Asterisk main include file. File version handling, generic pbx functions.
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
static const char config_file[]
Definition: cdr_odbc.c:49
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
Definition: config.c:625
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
Definition: hashtab.c:131
int ast_context_remove_include(const char *context, const char *include, const char *registrar)
Remove a context include.
Definition: pbx.c:6007
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_context_remove_ignorepat(const char *context, const char *ignorepat, const char *registrar)
Definition: pbx.c:8554
static int reload(void)
Definition: pbx_config.c:1815
void pbx_builtin_clear_globals(void)
Definition: pbx.c:10709
char * strsep(char **str, const char *delims)
const char * ast_get_extension_registrar(struct ast_exten *e)
Definition: pbx.c:11116
static char * handle_cli_dialplan_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pbx_config.c:1291
static int static_config
Definition: pbx_config.c:49
int ast_cli_register(struct ast_cli_entry *e)
Registers a command or an array of commands.
Definition: cli.c:2159
#define ast_strdup(a)
Definition: astmm.h:109
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
static char * complete_dialplan_add_include(struct ast_cli_args *)
Definition: pbx_config.c:578
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
static char * complete_dialplan_remove_include(struct ast_cli_args *)
Definition: pbx_config.c:188
static int write_protect_config
Definition: pbx_config.c:50
static int extenpatternmatchnew_config
Definition: pbx_config.c:53
int ast_cli_unregister(struct ast_cli_entry *e)
Unregisters a command or an array of commands.
Definition: cli.c:2153
descriptor for a cli entry.
Definition: cli.h:165
const int argc
Definition: cli.h:154
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
const char * ast_get_extension_app(struct ast_exten *e)
Definition: pbx.c:11141
int ast_add_extension2(struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add an extension to an extension context, this time with an ast_context *.
Definition: pbx.c:9052
int lineno
Definition: config.h:87
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
Definition: cli.h:146
static EditLine * el
Definition: asterisk.c:222
Configuration File Parser.
static char * complete_dialplan_add_extension(struct ast_cli_args *)
Definition: pbx_config.c:1026
static char userscontext[AST_MAX_EXTENSION]
Definition: pbx_config.c:47
void * ast_get_extension_app_data(struct ast_exten *e)
Definition: pbx.c:11146
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:11042
const char * ast_get_extension_label(struct ast_exten *e)
Definition: pbx.c:11088
#define ast_mutex_lock(a)
Definition: lock.h:155
int ast_wrlock_contexts(void)
Write locks the context list.
Definition: pbx.c:11037
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:374
const char * ast_config_option(struct ast_config *cfg, const char *cat, const char *var)
Retrieve a configuration variable within the configuration set.
Definition: config.c:614
const char * label
Definition: pbx.c:889
static int load_module(void)
Definition: pbx_config.c:1803
const char * ast_get_context_registrar(struct ast_context *c)
Definition: pbx.c:11111
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
const char * ext
Definition: http.c:112
static int pbx_load_module(void)
Definition: pbx_config.c:1771
int ast_context_add_switch2(struct ast_context *con, const char *sw, const char *data, int eval, const char *registrar)
Adds a switch (first param is a ast_context)
Definition: pbx.c:8494
static int partial_match(const char *s, const char *word, int len)
match the first &#39;len&#39; chars of word. len==0 always succeeds
Definition: pbx_config.c:150
void ast_free_ptr(void *ptr)
Definition: ael.tab.c:203
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
int ast_context_add_include(const char *context, const char *include, const char *registrar)
Add a context include.
Definition: pbx.c:8142
const char * line
Definition: cli.h:156
int ast_hashtab_resize_java(struct ast_hashtab *tab)
Determines if a table resize should occur using the Java algorithm (if the table load factor is 75% o...
Definition: hashtab.c:88
const char * ast_get_switch_name(struct ast_sw *sw)
Definition: pbx.c:11151
static char * handle_cli_dialplan_add_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
ADD EXTENSION command stuff.
Definition: pbx_config.c:907
static int lookup_ci(struct ast_context *c, const char *name)
return true if &#39;name&#39; is included by context c
Definition: pbx_config.c:107
const char * ast_get_include_name(struct ast_include *include)
Definition: pbx.c:11093
const char * ast_get_include_registrar(struct ast_include *i)
Definition: pbx.c:11121
#define ast_asprintf(a, b, c...)
Definition: astmm.h:121
#define ast_opt_dont_warn
Definition: options.h:121
static void pbx_load_users(void)
Definition: pbx_config.c:1667
int priority
Definition: pbx.c:888
const char * value
Definition: config.h:79
ast_sw: Switch statement in extensions.conf
Definition: pbx.c:915
static const char app[]
Definition: app_adsiprog.c:49
General Asterisk PBX channel definitions.
struct ast_exten * ast_walk_context_extensions(struct ast_context *con, struct ast_exten *priority)
Definition: pbx.c:11179
Asterisk file paths, configured in asterisk.conf.
const int fd
Definition: cli.h:153
#define ast_config_load(filename, flags)
Load a config file.
Definition: config.h:170
int ast_context_add_ignorepat(const char *context, const char *ignorepat, const char *registrar)
Add an ignorepat.
Definition: pbx.c:8598
static char * handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
&#39;save dialplan&#39; CLI command implementation functions ...
Definition: pbx_config.c:675
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const int n
Definition: cli.h:159
#define AST_MAX_EXTENSION
Definition: channel.h:135
int pbx_set_extenpatternmatchnew(int newval)
Definition: pbx.c:5948
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
const char * ast_get_ignorepat_registrar(struct ast_ignorepat *ip)
Definition: pbx.c:11126
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
const char * ast_get_switch_data(struct ast_sw *sw)
Definition: pbx.c:11156
const char * name
Definition: config.h:77
static const char registrar[]
Definition: pbx_config.c:46
struct ast_ignorepat * ast_walk_context_ignorepats(struct ast_context *con, struct ast_ignorepat *ip)
Definition: pbx.c:11212
int pbx_set_autofallthrough(int newval)
Definition: pbx.c:5941
struct ast_hashtab * ast_hashtab_create(int initial_buckets, int(*compare)(const void *a, const void *b), int(*resize)(struct ast_hashtab *), int(*newsize)(struct ast_hashtab *tab), unsigned int(*hash)(const void *obj), int do_locking)
Create the hashtable list.
Definition: hashtab.c:226
const char * ast_get_extension_cidmatch(struct ast_exten *e)
Definition: pbx.c:11136
#define PRIORITY_HINT
Definition: pbx.h:53
int ast_context_add_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar)
Definition: pbx.c:8611
struct ast_context * ast_walk_contexts(struct ast_context *con)
Definition: pbx.c:11174
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:11073
static char * complete_dialplan_remove_ignorepat(struct ast_cli_args *)
Definition: pbx_config.c:1208
Core PBX routines and definitions.
static char * overrideswitch_config
Definition: pbx_config.c:54
const char *const * argv
Definition: cli.h:155
static char * handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pbx_config.c:311
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static char * handle_cli_dialplan_add_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pbx_config.c:1058
static int lookup_c_ip(struct ast_context *c, const char *name)
return true if &#39;name&#39; is in the ignorepats for context c
Definition: pbx_config.c:121
#define LOG_ERROR
Definition: logger.h:155
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is &quot;true&quot;. This function checks to see whether a string passed to it is an indication of an &quot;true&quot; value. It checks to see if the string is &quot;yes&quot;, &quot;true&quot;, &quot;y&quot;, &quot;t&quot;, &quot;on&quot; or &quot;1&quot;.
Definition: utils.c:1533
static struct ast_cli_entry cli_dialplan_save
Definition: pbx_config.c:1331
const char * file
Definition: config.h:85
#define free(a)
Definition: astmm.h:94
#define CLI_SHOWUSAGE
Definition: cli.h:44
const char * ast_config_AST_CONFIG_DIR
Definition: asterisk.c:256
void ast_merge_contexts_and_delete(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *registrar)
Merge the temporary contexts into a global contexts list and delete from the global list the ones tha...
Definition: pbx.c:7937
const char * ast_get_switch_registrar(struct ast_sw *sw)
Definition: pbx.c:11166
struct ast_exten * ast_walk_extension_priorities(struct ast_exten *exten, struct ast_exten *priority)
Definition: pbx.c:11197
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx.c:925
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static int split_ec(const char *src, char **ext, char **const ctx, char **const cid)
split extension@context in two parts, return -1 on error. The return string is malloc&#39;ed and pointed ...
Definition: pbx_config.c:158
static ast_mutex_t reload_lock
Definition: pbx_config.c:58
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int unload_module(void)
Definition: pbx_config.c:1337
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:97
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_context_remove_extension_callerid(const char *context, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar)
Definition: pbx.c:6119
static char * pbx_strsep(char **destructible, const char *delim)
Definition: pbx_config.c:1354
static void append_interface(char *iface, int maxlen, char *add)
Definition: pbx_config.c:1655
const char * ast_get_extension_name(struct ast_exten *exten)
Definition: pbx.c:11083
static struct ast_hashtab * local_table
Definition: pbx_config.c:61
#define PUT_CTX_HDR
#define CLI_FAILURE
Definition: cli.h:45
int errno
static const char name[]
#define ast_free(a)
Definition: astmm.h:97
char * command
Definition: cli.h:180
const char * ast_get_ignorepat_name(struct ast_ignorepat *ip)
Definition: pbx.c:11098
unsigned int ast_hashtab_hash_contexts(const void *obj)
Definition: pbx.c:1188
const char * word
Definition: cli.h:157
static ast_mutex_t save_dialplan_lock
Definition: pbx_config.c:56
static const char config[]
Definition: pbx_config.c:45
static struct ast_cli_entry cli_pbx_config[]
Definition: pbx_config.c:1320
Structure used to handle boolean flags.
Definition: utils.h:200
Support for logging to various files, console and syslog Configuration in file logger.conf.
const char * cidmatch
Definition: pbx.c:887
const char * usage
Definition: cli.h:171
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546
struct ast_sw * ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw)
Definition: pbx.c:11188
#define CLI_SUCCESS
Definition: cli.h:43
static char * complete_dialplan_add_ignorepat(struct ast_cli_args *)
Definition: pbx_config.c:1112
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
Definition: pbx.c:8691
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
const int pos
Definition: cli.h:158
static struct ast_context * local_contexts
Definition: pbx_config.c:60
static char * overrideswitch
Definition: pbx.c:1222
void pbx_set_overrideswitch(const char *newval)
Definition: pbx.c:5955
void ast_context_destroy(struct ast_context *con, const char *registrar)
Destroy a context (matches the specified context (or ANY context if NULL)
Definition: pbx.c:9875
static char * handle_cli_dialplan_add_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pbx_config.c:522
int ast_context_verify_includes(struct ast_context *con)
Verifies includes in an ast_contect structure.
Definition: pbx.c:11221
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static const char * skip_words(const char *p, int n)
moves to the n-th word in the string, or empty string if none
Definition: pbx_config.c:135
struct ast_context * ast_context_find_or_create(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar)
Register a new context or find an existing one.
Definition: pbx.c:7726
#define strdup(a)
Definition: astmm.h:106
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:948
static char * handle_cli_dialplan_remove_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pbx_config.c:1159
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
int ast_get_extension_matchcid(struct ast_exten *e)
Definition: pbx.c:11131
Asterisk module definitions.
int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:5410
ast_context: An extension context
Definition: pbx.c:955
static char * complete_dialplan_remove_extension(struct ast_cli_args *)
Definition: pbx_config.c:398
#define AST_MUTEX_DEFINE_STATIC(mutex)
Definition: lock.h:526
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
int ast_rdlock_context(struct ast_context *con)
Read locks a given context.
Definition: pbx.c:11060
#define ast_mutex_unlock(a)
Definition: lock.h:156