2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2006, Digium, Inc.
6 * Steve Murphy <murf@parsetree.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 Compile symbolic Asterisk Extension Logic into Asterisk extensions, version 2.
27 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
29 #include <sys/types.h>
39 #include "asterisk/pbx.h"
40 #include "asterisk/config.h"
41 #include "asterisk/module.h"
42 #include "asterisk/logger.h"
43 #include "asterisk/cli.h"
44 #include "asterisk/app.h"
45 #include "asterisk/callerid.h"
46 #include "asterisk/ael_structs.h"
48 #include "asterisk/argdesc.h"
51 static char expr_output[2096];
53 /* these functions are in ../ast_expr2.fl */
55 #define DEBUG_READ (1 << 0)
56 #define DEBUG_TOKENS (1 << 1)
57 #define DEBUG_MACROS (1 << 2)
58 #define DEBUG_CONTEXTS (1 << 3)
60 static char *config = "extensions.ael";
61 static char *registrar = "pbx_ael";
62 static int pbx_load_module(void);
64 static int errs, warns;
68 /* for the time being, short circuit all the AAL related structures
69 without permanently removing the code; after/during the AAL
70 development, this code can be properly re-instated
73 /*! \brief null definitions for structs passed down the infrastructure */
82 int option_matches_j( struct argdesc *should, pval *is, struct argapp *app);
83 int option_matches( struct argdesc *should, pval *is, struct argapp *app);
84 int ael_is_funcname(char *name);
87 int check_app_args(pval *appcall, pval *arglist, struct argapp *app);
88 void check_pval(pval *item, struct argapp *apps, int in_globals);
89 void check_pval_item(pval *item, struct argapp *apps, int in_globals);
90 void check_switch_expr(pval *item, struct argapp *apps);
91 void ast_expr_register_extra_error_info(char *errmsg);
92 void ast_expr_clear_extra_error_info(void);
93 int ast_expr(char *expr, char *buf, int length,struct ast_channel *chan);
94 struct pval *find_macro(char *name);
95 struct pval *find_context(char *name);
96 struct pval *find_context(char *name);
97 struct pval *find_macro(char *name);
98 struct ael_priority *new_prio(void);
99 struct ael_extension *new_exten(void);
100 void linkprio(struct ael_extension *exten, struct ael_priority *prio);
101 void destroy_extensions(struct ael_extension *exten);
102 static void linkexten(struct ael_extension *exten, struct ael_extension *add);
103 static void gen_prios(struct ael_extension *exten, char *label, pval *statement, struct ael_extension *mother_exten, struct ast_context *context );
104 void set_priorities(struct ael_extension *exten);
105 void add_extensions(struct ael_extension *exten);
106 void ast_compile_ael2(struct ast_context **local_contexts, struct pval *root);
107 void destroy_pval(pval *item);
108 void destroy_pval_item(pval *item);
109 int is_float(char *arg );
110 int is_int(char *arg );
111 int is_empty(char *arg);
112 static pval *current_db;
113 static pval *current_context;
114 static pval *current_extension;
116 static const char *match_context;
117 static const char *match_exten;
118 static const char *match_label;
119 static int in_abstract_context;
120 static int count_labels; /* true, put matcher in label counting mode */
121 static int label_count; /* labels are only meant to be counted in a context or exten */
122 static int return_on_context_match;
123 static pval *last_matched_label;
124 struct pval *match_pval(pval *item);
125 static void check_timerange(pval *p);
126 static void check_dow(pval *DOW);
127 static void check_day(pval *DAY);
128 static void check_month(pval *MON);
129 static void check_expr2_input(pval *expr, char *str);
130 static int extension_matches(pval *here, const char *exten, const char *pattern);
131 static void check_goto(pval *item);
132 static void find_pval_goto_item(pval *item, int lev);
133 static void find_pval_gotos(pval *item, int lev);
134 static int check_break(pval *item);
135 static int check_continue(pval *item);
136 static void check_label(pval *item);
137 static void check_macro_returns(pval *macro);
139 static struct pval *find_label_in_current_context(char *exten, char *label, pval *curr_cont);
140 static struct pval *find_first_label_in_current_context(char *label, pval *curr_cont);
141 static void print_pval_list(FILE *fin, pval *item, int depth);
143 static struct pval *find_label_in_current_extension(const char *label, pval *curr_ext);
144 static struct pval *find_label_in_current_db(const char *context, const char *exten, const char *label);
145 static pval *get_goto_target(pval *item);
146 static int label_inside_case(pval *label);
147 static void attach_exten(struct ael_extension **list, struct ael_extension *newmem);
148 static void fix_gotos_in_extensions(struct ael_extension *exten);
149 static pval *get_extension_or_contxt(pval *p);
150 static pval *get_contxt(pval *p);
151 static void remove_spaces_before_equals(char *str);
152 /* static void substitute_commas(char *str); */
154 /*! \brief I am adding this code to substitute commas with vertbars in the args to apps */
155 static void substitute_commas(char *str)
161 if (*p == ',' && ((p != str && *(p-1) != '\\')
164 if (*p == '\\' && *(p+1) == ',') { /* learning experience: the '\,' is turned into just ',' by pbx_config; So we need to do the same */
166 while (*q) { /* move the ',' and everything after it up 1 char */
176 /* PRETTY PRINTER FOR AEL: ============================================================================= */
178 static void print_pval(FILE *fin, pval *item, int depth)
183 for (i=0; i<depth; i++) {
184 fprintf(fin, "\t"); /* depth == indentation */
187 switch ( item->type ) {
189 fprintf(fin,"%s;\n", item->u1.str); /* usually, words are encapsulated in something else */
193 fprintf(fin,"macro %s(", item->u1.str);
194 for (lp=item->u2.arglist; lp; lp=lp->next) {
195 if (lp != item->u2.arglist )
197 fprintf(fin,"%s", lp->u1.str);
199 fprintf(fin,") {\n");
200 print_pval_list(fin,item->u3.macro_statements,depth+1);
201 for (i=0; i<depth; i++) {
202 fprintf(fin,"\t"); /* depth == indentation */
204 fprintf(fin,"};\n\n");
208 if ( item->u3.abstract )
209 fprintf(fin,"abstract context %s {\n", item->u1.str);
211 fprintf(fin,"context %s {\n", item->u1.str);
212 print_pval_list(fin,item->u2.statements,depth+1);
213 for (i=0; i<depth; i++) {
214 fprintf(fin,"\t"); /* depth == indentation */
216 fprintf(fin,"};\n\n");
220 fprintf(fin,"&%s(", item->u1.str);
221 for (lp=item->u2.arglist; lp; lp=lp->next) {
222 if ( lp != item->u2.arglist )
224 fprintf(fin,"%s", lp->u1.str);
229 case PV_APPLICATION_CALL:
230 fprintf(fin,"%s(", item->u1.str);
231 for (lp=item->u2.arglist; lp; lp=lp->next) {
232 if ( lp != item->u2.arglist )
234 fprintf(fin,"%s", lp->u1.str);
240 fprintf(fin,"case %s:\n", item->u1.str);
241 print_pval_list(fin,item->u2.statements, depth+1);
245 fprintf(fin,"pattern %s:\n", item->u1.str);
246 print_pval_list(fin,item->u2.statements, depth+1);
250 fprintf(fin,"default:\n");
251 print_pval_list(fin,item->u2.statements, depth+1);
255 fprintf(fin,"catch %s {\n", item->u1.str);
256 print_pval_list(fin,item->u2.statements, depth+1);
257 for (i=0; i<depth; i++) {
258 fprintf(fin,"\t"); /* depth == indentation */
264 fprintf(fin,"switches {\n");
265 print_pval_list(fin,item->u1.list,depth+1);
266 for (i=0; i<depth; i++) {
267 fprintf(fin,"\t"); /* depth == indentation */
273 fprintf(fin,"eswitches {\n");
274 print_pval_list(fin,item->u1.list,depth+1);
275 for (i=0; i<depth; i++) {
276 fprintf(fin,"\t"); /* depth == indentation */
282 fprintf(fin,"includes {\n");
283 for (lp=item->u1.list; lp; lp=lp->next) {
284 for (i=0; i<depth+1; i++) {
285 fprintf(fin,"\t"); /* depth == indentation */
287 fprintf(fin,"%s", lp->u1.str); /* usually, words are encapsulated in something else */
288 if ( lp->u2.arglist )
289 fprintf(fin,"|%s|%s|%s|%s",
290 lp->u2.arglist->u1.str,
291 lp->u2.arglist->next->u1.str,
292 lp->u2.arglist->next->next->u1.str,
293 lp->u2.arglist->next->next->next->u1.str
295 fprintf(fin,";\n"); /* usually, words are encapsulated in something else */
298 print_pval_list(fin,item->u1.list,depth+1);
299 for (i=0; i<depth; i++) {
300 fprintf(fin,"\t"); /* depth == indentation */
305 case PV_STATEMENTBLOCK:
307 print_pval_list(fin,item->u1.list, depth+1);
308 for (i=0; i<depth; i++) {
309 fprintf(fin,"\t"); /* depth == indentation */
315 fprintf(fin,"%s=%s;\n", item->u1.str, item->u2.val);
319 fprintf(fin,"local %s=%s;\n", item->u1.str, item->u2.val);
323 fprintf(fin,"goto %s", item->u1.list->u1.str);
324 if ( item->u1.list->next )
325 fprintf(fin,",%s", item->u1.list->next->u1.str);
326 if ( item->u1.list->next && item->u1.list->next->next )
327 fprintf(fin,",%s", item->u1.list->next->next->u1.str);
332 fprintf(fin,"%s:\n", item->u1.str);
336 fprintf(fin,"for (%s; %s; %s)\n", item->u1.for_init, item->u2.for_test, item->u3.for_inc);
337 print_pval_list(fin,item->u4.for_statements,depth+1);
341 fprintf(fin,"while (%s)\n", item->u1.str);
342 print_pval_list(fin,item->u2.statements,depth+1);
346 fprintf(fin,"break;\n");
350 fprintf(fin,"return;\n");
354 fprintf(fin,"continue;\n");
360 if ( item->type == PV_IFTIME ) {
362 fprintf(fin,"ifTime ( %s|%s|%s|%s )\n",
363 item->u1.list->u1.str,
364 item->u1.list->next->u1.str,
365 item->u1.list->next->next->u1.str,
366 item->u1.list->next->next->next->u1.str
368 } else if ( item->type == PV_RANDOM ) {
369 fprintf(fin,"random ( %s )\n", item->u1.str );
371 fprintf(fin,"if ( %s )\n", item->u1.str);
372 if ( item->u2.statements && item->u2.statements->next ) {
373 for (i=0; i<depth; i++) {
374 fprintf(fin,"\t"); /* depth == indentation */
377 print_pval_list(fin,item->u2.statements,depth+1);
378 for (i=0; i<depth; i++) {
379 fprintf(fin,"\t"); /* depth == indentation */
381 if ( item->u3.else_statements )
385 } else if (item->u2.statements ) {
386 print_pval_list(fin,item->u2.statements,depth+1);
388 if (item->u3.else_statements )
389 fprintf(fin, " {} ");
391 fprintf(fin, " {}; ");
393 if ( item->u3.else_statements ) {
394 for (i=0; i<depth; i++) {
395 fprintf(fin,"\t"); /* depth == indentation */
397 fprintf(fin,"else\n");
398 print_pval_list(fin,item->u3.else_statements, depth);
403 fprintf(fin,"switch( %s ) {\n", item->u1.str);
404 print_pval_list(fin,item->u2.statements,depth+1);
405 for (i=0; i<depth; i++) {
406 fprintf(fin,"\t"); /* depth == indentation */
412 if ( item->u4.regexten )
413 fprintf(fin, "regexten ");
414 if ( item->u3.hints )
415 fprintf(fin,"hints(%s) ", item->u3.hints);
417 fprintf(fin,"%s => \n", item->u1.str);
418 print_pval_list(fin,item->u2.statements,depth+1);
422 fprintf(fin,"ignorepat => %s\n", item->u1.str);
426 fprintf(fin,"globals {\n");
427 print_pval_list(fin,item->u1.statements,depth+1);
428 for (i=0; i<depth; i++) {
429 fprintf(fin,"\t"); /* depth == indentation */
436 static void print_pval_list(FILE *fin, pval *item, int depth)
440 for (i=item; i; i=i->next) {
441 print_pval(fin, i, depth);
446 static void ael2_print(char *fname, pval *tree)
448 FILE *fin = fopen(fname,"w");
450 ast_log(LOG_ERROR, "Couldn't open %s for writing.\n", fname);
453 print_pval_list(fin, tree, 0);
459 /* EMPTY TEMPLATE FUNCS FOR AEL TRAVERSAL: ============================================================================= */
461 void traverse_pval_template(pval *item, int depth);
462 void traverse_pval_item_template(pval *item, int depth);
465 void traverse_pval_item_template(pval *item, int depth)/* depth comes in handy for a pretty print (indentation),
466 but you may not need it */
470 switch ( item->type ) {
472 /* fields: item->u1.str == string associated with this (word). */
476 /* fields: item->u1.str == name of macro
477 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
478 item->u2.arglist->u1.str == argument
479 item->u2.arglist->next == next arg
481 item->u3.macro_statements == pval list of statements in macro body.
483 for (lp=item->u2.arglist; lp; lp=lp->next) {
486 traverse_pval_item_template(item->u3.macro_statements,depth+1);
490 /* fields: item->u1.str == name of context
491 item->u2.statements == pval list of statements in context body
492 item->u3.abstract == int 1 if an abstract keyword were present
494 traverse_pval_item_template(item->u2.statements,depth+1);
498 /* fields: item->u1.str == name of macro to call
499 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
500 item->u2.arglist->u1.str == argument
501 item->u2.arglist->next == next arg
503 for (lp=item->u2.arglist; lp; lp=lp->next) {
507 case PV_APPLICATION_CALL:
508 /* fields: item->u1.str == name of application to call
509 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
510 item->u2.arglist->u1.str == argument
511 item->u2.arglist->next == next arg
513 for (lp=item->u2.arglist; lp; lp=lp->next) {
518 /* fields: item->u1.str == value of case
519 item->u2.statements == pval list of statements under the case
521 traverse_pval_item_template(item->u2.statements,depth+1);
525 /* fields: item->u1.str == value of case
526 item->u2.statements == pval list of statements under the case
528 traverse_pval_item_template(item->u2.statements,depth+1);
533 item->u2.statements == pval list of statements under the case
535 traverse_pval_item_template(item->u2.statements,depth+1);
539 /* fields: item->u1.str == name of extension to catch
540 item->u2.statements == pval list of statements in context body
542 traverse_pval_item_template(item->u2.statements,depth+1);
546 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
548 traverse_pval_item_template(item->u1.list,depth+1);
552 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
554 traverse_pval_item_template(item->u1.list,depth+1);
558 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
559 item->u2.arglist == pval list of 4 PV_WORD elements for time values
561 traverse_pval_item_template(item->u1.list,depth+1);
562 traverse_pval_item_template(item->u2.arglist,depth+1);
565 case PV_STATEMENTBLOCK:
566 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
568 traverse_pval_item_template(item->u1.list,depth+1);
573 /* fields: item->u1.str == variable name
574 item->u2.val == variable value to assign
579 /* fields: item->u1.list == pval list of PV_WORD target names, up to 3, in order as given by user.
580 item->u1.list->u1.str == where the data on a PV_WORD will always be.
583 if ( item->u1.list->next )
585 if ( item->u1.list->next && item->u1.list->next->next )
591 /* fields: item->u1.str == label name
596 /* fields: item->u1.for_init == a string containing the initalizer
597 item->u2.for_test == a string containing the loop test
598 item->u3.for_inc == a string containing the loop increment
600 item->u4.for_statements == a pval list of statements in the for ()
602 traverse_pval_item_template(item->u4.for_statements,depth+1);
606 /* fields: item->u1.str == the while conditional, as supplied by user
608 item->u2.statements == a pval list of statements in the while ()
610 traverse_pval_item_template(item->u2.statements,depth+1);
629 /* fields: item->u1.list == there are 4 linked PV_WORDs here.
631 item->u2.statements == a pval list of statements in the if ()
632 item->u3.else_statements == a pval list of statements in the else
635 traverse_pval_item_template(item->u2.statements,depth+1);
636 if ( item->u3.else_statements ) {
637 traverse_pval_item_template(item->u3.else_statements,depth+1);
642 /* fields: item->u1.str == the random number expression, as supplied by user
644 item->u2.statements == a pval list of statements in the if ()
645 item->u3.else_statements == a pval list of statements in the else
648 traverse_pval_item_template(item->u2.statements,depth+1);
649 if ( item->u3.else_statements ) {
650 traverse_pval_item_template(item->u3.else_statements,depth+1);
655 /* fields: item->u1.str == the if conditional, as supplied by user
657 item->u2.statements == a pval list of statements in the if ()
658 item->u3.else_statements == a pval list of statements in the else
661 traverse_pval_item_template(item->u2.statements,depth+1);
662 if ( item->u3.else_statements ) {
663 traverse_pval_item_template(item->u3.else_statements,depth+1);
668 /* fields: item->u1.str == the switch expression
670 item->u2.statements == a pval list of statements in the switch,
671 (will be case statements, most likely!)
673 traverse_pval_item_template(item->u2.statements,depth+1);
677 /* fields: item->u1.str == the extension name, label, whatever it's called
679 item->u2.statements == a pval list of statements in the extension
680 item->u3.hints == a char * hint argument
681 item->u4.regexten == an int boolean. non-zero says that regexten was specified
683 traverse_pval_item_template(item->u2.statements,depth+1);
687 /* fields: item->u1.str == the ignorepat data
692 /* fields: item->u1.statements == pval list of statements, usually vardecs
694 traverse_pval_item_template(item->u1.statements,depth+1);
699 void traverse_pval_template(pval *item, int depth) /* depth comes in handy for a pretty print (indentation),
700 but you may not need it */
704 for (i=item; i; i=i->next) {
705 traverse_pval_item_template(i, depth);
710 /* SEMANTIC CHECKING FOR AEL: ============================================================================= */
712 /* (not all that is syntactically legal is good! */
715 static void check_macro_returns(pval *macro)
718 if (!macro->u3.macro_statements)
720 pval *z = calloc(1, sizeof(struct pval));
721 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The macro %s is empty! I will insert a return.\n",
722 macro->filename, macro->startline, macro->endline, macro->u1.str);
725 z->startline = macro->startline;
726 z->endline = macro->endline;
727 z->startcol = macro->startcol;
728 z->endcol = macro->endcol;
729 z->filename = strdup(macro->filename);
731 macro->u3.macro_statements = z;
734 for (i=macro->u3.macro_statements; i; i=i->next) {
735 /* if the last statement in the list is not return, then insert a return there */
736 if (i->next == NULL) {
737 if (i->type != PV_RETURN) {
738 pval *z = calloc(1, sizeof(struct pval));
739 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The macro %s does not end with a return; I will insert one.\n",
740 macro->filename, macro->startline, macro->endline, macro->u1.str);
743 z->startline = macro->startline;
744 z->endline = macro->endline;
745 z->startcol = macro->startcol;
746 z->endcol = macro->endcol;
747 z->filename = strdup(macro->filename);
759 static int extension_matches(pval *here, const char *exten, const char *pattern)
764 /* simple case, they match exactly, the pattern and exten name */
765 if (!strcmp(pattern,exten) == 0)
768 if (pattern[0] == '_') {
773 if ( strlen(pattern)*5 >= 2000 ) /* safety valve */ {
774 ast_log(LOG_ERROR,"Error: The pattern %s is way too big. Pattern matching cancelled.\n",
778 /* form a regular expression from the pattern, and then match it against exten */
779 *r++ = '^'; /* what if the extension is a pattern ?? */
780 *r++ = '_'; /* what if the extension is a pattern ?? */
782 for (p=pattern+1; *p; p++) {
812 while ( *p && *p != ']' ) {
816 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The extension pattern '%s' is missing a closing bracket \n",
817 here->filename, here->startline, here->endline, pattern);
836 *r++ = '$'; /* what if the extension is a pattern ?? */
837 *r++ = *p++; /* put in the closing null */
838 err1 = regcomp(&preg, reg1, REG_NOSUB|REG_EXTENDED);
841 regerror(err1,&preg,errmess,sizeof(errmess));
843 ast_log(LOG_WARNING, "Regcomp of %s failed, error code %d\n",
847 err1 = regexec(&preg, exten, 0, 0, 0);
851 /* ast_log(LOG_NOTICE,"*****************************[%d]Extension %s did not match %s(%s)\n",
852 err1,exten, pattern, reg1); */
853 return 0; /* no match */
855 /* ast_log(LOG_NOTICE,"*****************************Extension %s matched %s\n",
862 if ( strcmp(exten,pattern) == 0 ) {
870 static void check_expr2_input(pval *expr, char *str)
872 int spaces = strspn(str,"\t \n");
873 if ( !strncmp(str+spaces,"$[",2) ) {
874 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The expression '%s' is redundantly wrapped in '$[ ]'. \n",
875 expr->filename, expr->startline, expr->endline, str);
880 static void check_includes(pval *includes)
883 for (p4=includes->u1.list; p4; p4=p4->next) {
884 /* for each context pointed to, find it, then find a context/label that matches the
886 char *incl_context = p4->u1.str;
887 /* find a matching context name */
888 struct pval *that_other_context = find_context(incl_context);
889 if (!that_other_context && strcmp(incl_context, "parkedcalls") != 0) {
890 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The included context '%s' cannot be found.\n",
891 includes->filename, includes->startline, includes->endline, incl_context);
898 static void check_timerange(pval *p)
905 times = ast_strdupa(p->u1.str);
907 /* Star is all times */
908 if (ast_strlen_zero(times) || !strcmp(times, "*")) {
911 /* Otherwise expect a range */
912 e = strchr(times, '-');
914 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The time range format (%s) requires a '-' surrounded by two 24-hour times of day!\n",
915 p->filename, p->startline, p->endline, times);
921 while (*e && !isdigit(*e))
924 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The time range format (%s) is missing the end time!\n",
925 p->filename, p->startline, p->endline, p->u1.str);
928 if (sscanf(times, "%d:%d", &s1, &s2) != 2) {
929 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start time (%s) isn't quite right!\n",
930 p->filename, p->startline, p->endline, times);
933 if (sscanf(e, "%d:%d", &e1, &e2) != 2) {
934 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end time (%s) isn't quite right!\n",
935 p->filename, p->startline, p->endline, times);
940 if ((s1 < 0) || (s1 >= 24*30)) {
941 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start time (%s) is out of range!\n",
942 p->filename, p->startline, p->endline, times);
946 if ((e1 < 0) || (e1 >= 24*30)) {
947 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end time (%s) is out of range!\n",
948 p->filename, p->startline, p->endline, e);
954 static char *days[] =
965 /*! \brief get_dow: Get day of week */
966 static void check_dow(pval *DOW)
970 /* The following line is coincidence, really! */
973 dow = ast_strdupa(DOW->u1.str);
975 /* Check for all days */
976 if (ast_strlen_zero(dow) || !strcmp(dow, "*"))
978 /* Get start and ending days */
979 c = strchr(dow, '-');
987 while ((s < 7) && strcasecmp(dow, days[s])) s++;
989 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The day (%s) must be one of 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', or 'sat'!\n",
990 DOW->filename, DOW->startline, DOW->endline, dow);
995 while ((e < 7) && strcasecmp(c, days[e])) e++;
997 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day (%s) must be one of 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', or 'sat'!\n",
998 DOW->filename, DOW->startline, DOW->endline, c);
1005 static void check_day(pval *DAY)
1009 /* The following line is coincidence, really! */
1012 day = ast_strdupa(DAY->u1.str);
1014 /* Check for all days */
1015 if (ast_strlen_zero(day) || !strcmp(day, "*")) {
1018 /* Get start and ending days */
1019 c = strchr(day, '-');
1024 /* Find the start */
1025 if (sscanf(day, "%d", &s) != 1) {
1026 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start day of month (%s) must be a number!\n",
1027 DAY->filename, DAY->startline, DAY->endline, day);
1030 else if ((s < 1) || (s > 31)) {
1031 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start day of month (%s) must be a number in the range [1-31]!\n",
1032 DAY->filename, DAY->startline, DAY->endline, day);
1037 if (sscanf(c, "%d", &e) != 1) {
1038 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day of month (%s) must be a number!\n",
1039 DAY->filename, DAY->startline, DAY->endline, c);
1042 else if ((e < 1) || (e > 31)) {
1043 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day of month (%s) must be a number in the range [1-31]!\n",
1044 DAY->filename, DAY->startline, DAY->endline, day);
1052 static char *months[] =
1068 static void check_month(pval *MON)
1072 /* The following line is coincidence, really! */
1075 mon = ast_strdupa(MON->u1.str);
1077 /* Check for all days */
1078 if (ast_strlen_zero(mon) || !strcmp(mon, "*"))
1080 /* Get start and ending days */
1081 c = strchr(mon, '-');
1086 /* Find the start */
1088 while ((s < 12) && strcasecmp(mon, months[s])) s++;
1090 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n",
1091 MON->filename, MON->startline, MON->endline, mon);
1096 while ((e < 12) && strcasecmp(mon, months[e])) e++;
1098 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n",
1099 MON->filename, MON->startline, MON->endline, c);
1106 static int check_break(pval *item)
1110 while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) /* early cutout, sort of */ {
1111 /* a break is allowed in WHILE, FOR, CASE, DEFAULT, PATTERN; otherwise, it don't make
1113 if( p->type == PV_CASE || p->type == PV_DEFAULT || p->type == PV_PATTERN
1114 || p->type == PV_WHILE || p->type == PV_FOR ) {
1119 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'break' not in switch, for, or while statement!\n",
1120 item->filename, item->startline, item->endline);
1126 static int check_continue(pval *item)
1130 while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) /* early cutout, sort of */ {
1131 /* a break is allowed in WHILE, FOR, CASE, DEFAULT, PATTERN; otherwise, it don't make
1133 if( p->type == PV_WHILE || p->type == PV_FOR ) {
1138 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'continue' not in 'for' or 'while' statement!\n",
1139 item->filename, item->startline, item->endline);
1145 static struct pval *in_macro(pval *item)
1150 if( curr->type == PV_MACRO ) {
1158 static struct pval *in_context(pval *item)
1163 if( curr->type == PV_MACRO || curr->type == PV_CONTEXT ) {
1172 /* general purpose goto finder */
1174 static void check_label(pval *item)
1180 /* A label outside an extension just plain does not make sense! */
1185 if( curr->type == PV_MACRO || curr->type == PV_EXTENSION ) {
1193 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: Label %s is not within an extension or macro!\n",
1194 item->filename, item->startline, item->endline, item->u1.str);
1199 /* basically, ensure that a label is not repeated in a context. Period.
1200 The method: well, for each label, find the first label in the context
1201 with the same name. If it's not the current label, then throw an error. */
1204 /* printf("==== check_label: ====\n"); */
1205 if( !current_extension )
1206 curr = current_context;
1208 curr = current_extension;
1210 x = find_first_label_in_current_context((char *)item->u1.str, curr);
1211 /* printf("Hey, check_label found with item = %x, and x is %x, and currcont is %x, label name is %s\n", item,x, current_context, (char *)item->u1.str); */
1212 if( x && x != item )
1214 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: Duplicate label %s! Previously defined at file %s, line %d.\n",
1215 item->filename, item->startline, item->endline, item->u1.str, x->filename, x->startline);
1218 /* printf("<<<<< check_label: ====\n"); */
1221 static pval *get_goto_target(pval *item)
1223 /* just one item-- the label should be in the current extension */
1224 pval *curr_ext = get_extension_or_contxt(item); /* containing exten, or macro */
1227 if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) {
1228 struct pval *x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), curr_ext);
1232 curr_cont = get_contxt(item);
1235 if (item->u1.list->next && !item->u1.list->next->next) {
1236 if (!strstr((item->u1.list)->u1.str,"${")
1237 && !strstr(item->u1.list->next->u1.str,"${") ) /* Don't try to match variables */ {
1238 struct pval *x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, curr_cont);
1244 if (item->u1.list->next && item->u1.list->next->next) {
1246 pval *first = item->u1.list;
1247 pval *second = item->u1.list->next;
1248 pval *third = item->u1.list->next->next;
1250 if (!strstr((item->u1.list)->u1.str,"${")
1251 && !strstr(item->u1.list->next->u1.str,"${")
1252 && !strstr(item->u1.list->next->next->u1.str,"${")) /* Don't try to match variables */ {
1253 struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str);
1257 struct pval *that_context = find_context(item->u1.list->u1.str);
1259 /* the target of the goto could be in an included context!! Fancy that!! */
1260 /* look for includes in the current context */
1262 for (p3=that_context->u2.statements; p3; p3=p3->next) {
1263 if (p3->type == PV_INCLUDES) {
1265 for (p4=p3->u1.list; p4; p4=p4->next) {
1266 /* for each context pointed to, find it, then find a context/label that matches the
1268 char *incl_context = p4->u1.str;
1269 /* find a matching context name */
1270 struct pval *that_other_context = find_context(incl_context);
1271 if (that_other_context) {
1273 x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context);
1289 static void check_goto(pval *item)
1291 /* check for the target of the goto-- does it exist? */
1292 if ( !(item->u1.list)->next && !(item->u1.list)->u1.str ) {
1293 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: empty label reference found!\n",
1294 item->filename, item->startline, item->endline);
1298 /* just one item-- the label should be in the current extension */
1300 if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) {
1301 struct pval *z = get_extension_or_contxt(item);
1304 x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), z); /* if in macro, use current context instead */
1305 /* printf("Called find_label_in_current_extension with arg %s; current_extension is %x: %d\n",
1306 (char*)((item->u1.list)->u1.str), current_extension?current_extension:current_context, current_extension?current_extension->type:current_context->type); */
1308 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s exists in the current extension!\n",
1309 item->filename, item->startline, item->endline, item->u1.list->u1.str);
1317 if (item->u1.list->next && !item->u1.list->next->next) {
1319 /* printf("Calling find_label_in_current_context with args %s, %s\n",
1320 (char*)((item->u1.list)->u1.str), (char *)item->u1.list->next->u1.str); */
1321 if (!strstr((item->u1.list)->u1.str,"${")
1322 && !strstr(item->u1.list->next->u1.str,"${") ) /* Don't try to match variables */ {
1323 struct pval *z = get_contxt(item);
1327 x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, z);
1330 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s|%s exists in the current context, or any of its inclusions!\n",
1331 item->filename, item->startline, item->endline, item->u1.list->u1.str, item->u1.list->next->u1.str );
1340 if (item->u1.list->next && item->u1.list->next->next) {
1342 pval *first = item->u1.list;
1343 pval *second = item->u1.list->next;
1344 pval *third = item->u1.list->next->next;
1346 /* printf("Calling find_label_in_current_db with args %s, %s, %s\n",
1347 (char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str); */
1348 if (!strstr((item->u1.list)->u1.str,"${")
1349 && !strstr(item->u1.list->next->u1.str,"${")
1350 && !strstr(item->u1.list->next->next->u1.str,"${")) /* Don't try to match variables */ {
1351 struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str);
1354 struct pval *found = 0;
1355 struct pval *that_context = find_context(item->u1.list->u1.str);
1357 /* the target of the goto could be in an included context!! Fancy that!! */
1358 /* look for includes in the current context */
1360 for (p3=that_context->u2.statements; p3; p3=p3->next) {
1361 if (p3->type == PV_INCLUDES) {
1363 for (p4=p3->u1.list; p4; p4=p4->next) {
1364 /* for each context pointed to, find it, then find a context/label that matches the
1366 char *incl_context = p4->u1.str;
1367 /* find a matching context name */
1368 struct pval *that_other_context = find_context(incl_context);
1369 if (that_other_context) {
1371 x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context);
1381 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s|%s exists in the context %s or its inclusions!\n",
1382 item->filename, item->startline, item->endline, item->u1.list->next->u1.str, item->u1.list->next->next->u1.str, item->u1.list->u1.str );
1385 struct pval *mac = in_macro(item); /* is this goto inside a macro? */
1386 if( mac ) { /* yes! */
1387 struct pval *targ = in_context(found);
1390 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: It's bad form to have a goto in a macro to a target outside the macro!\n",
1391 item->filename, item->startline, item->endline);
1397 /* here is where code would go to check for target existence in extensions.conf files */
1398 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: goto: no context %s could be found that matches the goto target!\n",
1399 item->filename, item->startline, item->endline, item->u1.list->u1.str);
1400 warns++; /* this is just a warning, because this context could be in extensions.conf or somewhere */
1403 struct pval *mac = in_macro(item); /* is this goto inside a macro? */
1404 if( mac ) { /* yes! */
1405 struct pval *targ = in_context(x);
1408 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: It's bad form to have a goto in a macro to a target outside the macro!\n",
1409 item->filename, item->startline, item->endline);
1419 static void find_pval_goto_item(pval *item, int lev)
1423 ast_log(LOG_ERROR,"find_pval_goto in infinite loop!\n\n");
1427 switch ( item->type ) {
1429 /* fields: item->u1.str == name of macro
1430 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
1431 item->u2.arglist->u1.str == argument
1432 item->u2.arglist->next == next arg
1434 item->u3.macro_statements == pval list of statements in macro body.
1437 /* printf("Descending into matching macro %s\n", match_context); */
1438 find_pval_gotos(item->u3.macro_statements,lev+1); /* if we're just searching for a context, don't bother descending into them */
1443 /* fields: item->u1.str == name of context
1444 item->u2.statements == pval list of statements in context body
1445 item->u3.abstract == int 1 if an abstract keyword were present
1450 /* fields: item->u1.str == value of case
1451 item->u2.statements == pval list of statements under the case
1453 find_pval_gotos(item->u2.statements,lev+1);
1457 /* fields: item->u1.str == value of case
1458 item->u2.statements == pval list of statements under the case
1460 find_pval_gotos(item->u2.statements,lev+1);
1465 item->u2.statements == pval list of statements under the case
1467 find_pval_gotos(item->u2.statements,lev+1);
1471 /* fields: item->u1.str == name of extension to catch
1472 item->u2.statements == pval list of statements in context body
1474 find_pval_gotos(item->u2.statements,lev+1);
1477 case PV_STATEMENTBLOCK:
1478 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
1480 find_pval_gotos(item->u1.list,lev+1);
1484 /* fields: item->u1.list == pval list of PV_WORD target names, up to 3, in order as given by user.
1485 item->u1.list->u1.str == where the data on a PV_WORD will always be.
1487 check_goto(item); /* THE WHOLE FUNCTION OF THIS ENTIRE ROUTINE!!!! */
1491 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
1493 for (p4=item->u1.list; p4; p4=p4->next) {
1494 /* for each context pointed to, find it, then find a context/label that matches the
1496 char *incl_context = p4->u1.str;
1497 /* find a matching context name */
1498 struct pval *that_context = find_context(incl_context);
1500 find_pval_gotos(that_context,lev+1); /* keep working up the includes */
1506 /* fields: item->u1.for_init == a string containing the initalizer
1507 item->u2.for_test == a string containing the loop test
1508 item->u3.for_inc == a string containing the loop increment
1510 item->u4.for_statements == a pval list of statements in the for ()
1512 find_pval_gotos(item->u4.for_statements,lev+1);
1516 /* fields: item->u1.str == the while conditional, as supplied by user
1518 item->u2.statements == a pval list of statements in the while ()
1520 find_pval_gotos(item->u2.statements,lev+1);
1524 /* fields: item->u1.str == the random number expression, as supplied by user
1526 item->u2.statements == a pval list of statements in the if ()
1527 item->u3.else_statements == a pval list of statements in the else
1529 fall thru to PV_IF */
1532 /* fields: item->u1.list == the time values, 4 of them, as PV_WORD structs in a list
1534 item->u2.statements == a pval list of statements in the if ()
1535 item->u3.else_statements == a pval list of statements in the else
1537 fall thru to PV_IF*/
1539 /* fields: item->u1.str == the if conditional, as supplied by user
1541 item->u2.statements == a pval list of statements in the if ()
1542 item->u3.else_statements == a pval list of statements in the else
1545 find_pval_gotos(item->u2.statements,lev+1);
1547 if (item->u3.else_statements) {
1548 find_pval_gotos(item->u3.else_statements,lev+1);
1553 /* fields: item->u1.str == the switch expression
1555 item->u2.statements == a pval list of statements in the switch,
1556 (will be case statements, most likely!)
1558 find_pval_gotos(item->u3.else_statements,lev+1);
1562 /* fields: item->u1.str == the extension name, label, whatever it's called
1564 item->u2.statements == a pval list of statements in the extension
1565 item->u3.hints == a char * hint argument
1566 item->u4.regexten == an int boolean. non-zero says that regexten was specified
1569 find_pval_gotos(item->u2.statements,lev+1);
1577 static void find_pval_gotos(pval *item,int lev)
1581 for (i=item; i; i=i->next) {
1583 find_pval_goto_item(i, lev);
1589 /* general purpose label finder */
1590 static struct pval *match_pval_item(pval *item)
1594 switch ( item->type ) {
1596 /* fields: item->u1.str == name of macro
1597 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
1598 item->u2.arglist->u1.str == argument
1599 item->u2.arglist->next == next arg
1601 item->u3.macro_statements == pval list of statements in macro body.
1603 /* printf(" matching in MACRO %s, match_context=%s; retoncontmtch=%d; \n", item->u1.str, match_context, return_on_context_match); */
1604 if (!strcmp(match_context,"*") || !strcmp(item->u1.str, match_context)) {
1606 /* printf("MACRO: match context is: %s\n", match_context); */
1608 if (return_on_context_match && !strcmp(item->u1.str, match_context)) /* if we're just searching for a context, don't bother descending into them */ {
1609 /* printf("Returning on matching macro %s\n", match_context); */
1614 if (!return_on_context_match) {
1615 /* printf("Descending into matching macro %s/%s\n", match_context, item->u1.str); */
1616 if ((x=match_pval(item->u3.macro_statements))) {
1617 /* printf("Responded with pval match %x\n", x); */
1622 /* printf("Skipping context/macro %s\n", item->u1.str); */
1628 /* fields: item->u1.str == name of context
1629 item->u2.statements == pval list of statements in context body
1630 item->u3.abstract == int 1 if an abstract keyword were present
1632 /* printf(" matching in CONTEXT\n"); */
1633 if (!strcmp(match_context,"*") || !strcmp(item->u1.str, match_context)) {
1634 if (return_on_context_match && !strcmp(item->u1.str, match_context)) {
1635 /* printf("Returning on matching context %s\n", match_context); */
1636 /* printf("non-CONTEXT: Responded with pval match %x\n", x); */
1640 if (!return_on_context_match ) {
1641 /* printf("Descending into matching context %s\n", match_context); */
1642 if ((x=match_pval(item->u2.statements))) /* if we're just searching for a context, don't bother descending into them */ {
1643 /* printf("CONTEXT: Responded with pval match %x\n", x); */
1648 /* printf("Skipping context/macro %s\n", item->u1.str); */
1653 /* fields: item->u1.str == value of case
1654 item->u2.statements == pval list of statements under the case
1656 /* printf(" matching in CASE\n"); */
1657 if ((x=match_pval(item->u2.statements))) {
1658 /* printf("CASE: Responded with pval match %x\n", x); */
1664 /* fields: item->u1.str == value of case
1665 item->u2.statements == pval list of statements under the case
1667 /* printf(" matching in PATTERN\n"); */
1668 if ((x=match_pval(item->u2.statements))) {
1669 /* printf("PATTERN: Responded with pval match %x\n", x); */
1676 item->u2.statements == pval list of statements under the case
1678 /* printf(" matching in DEFAULT\n"); */
1679 if ((x=match_pval(item->u2.statements))) {
1680 /* printf("DEFAULT: Responded with pval match %x\n", x); */
1686 /* fields: item->u1.str == name of extension to catch
1687 item->u2.statements == pval list of statements in context body
1689 /* printf(" matching in CATCH\n"); */
1690 if (!strcmp(match_exten,"*") || extension_matches(item, match_exten, item->u1.str) ) {
1691 /* printf("Descending into matching catch %s => %s\n", match_exten, item->u1.str); */
1692 if (strcmp(match_label,"1") == 0) {
1693 if (item->u2.statements) {
1694 struct pval *p5 = item->u2.statements;
1695 while (p5 && p5->type == PV_LABEL) /* find the first non-label statement in this context. If it exists, there's a "1" */
1706 if ((x=match_pval(item->u2.statements))) {
1707 /* printf("CATCH: Responded with pval match %x\n", (unsigned int)x); */
1711 /* printf("Skipping catch %s\n", item->u1.str); */
1715 case PV_STATEMENTBLOCK:
1716 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
1718 /* printf(" matching in STATEMENTBLOCK\n"); */
1719 if ((x=match_pval(item->u1.list))) {
1720 /* printf("STATEMENTBLOCK: Responded with pval match %x\n", x); */
1726 /* fields: item->u1.str == label name
1728 /* printf("PV_LABEL %s (cont=%s, exten=%s\n",
1729 item->u1.str, current_context->u1.str, (current_extension?current_extension->u1.str:"<macro>"));*/
1732 if (!strcmp(match_label, item->u1.str)) {
1734 last_matched_label = item;
1738 if (!strcmp(match_label, item->u1.str)) {
1739 /* printf("LABEL: Responded with pval match %x\n", x); */
1746 /* fields: item->u1.for_init == a string containing the initalizer
1747 item->u2.for_test == a string containing the loop test
1748 item->u3.for_inc == a string containing the loop increment
1750 item->u4.for_statements == a pval list of statements in the for ()
1752 /* printf(" matching in FOR\n"); */
1753 if ((x=match_pval(item->u4.for_statements))) {
1754 /* printf("FOR: Responded with pval match %x\n", x);*/
1760 /* fields: item->u1.str == the while conditional, as supplied by user
1762 item->u2.statements == a pval list of statements in the while ()
1764 /* printf(" matching in WHILE\n"); */
1765 if ((x=match_pval(item->u2.statements))) {
1766 /* printf("WHILE: Responded with pval match %x\n", x); */
1772 /* fields: item->u1.str == the random number expression, as supplied by user
1774 item->u2.statements == a pval list of statements in the if ()
1775 item->u3.else_statements == a pval list of statements in the else
1777 fall thru to PV_IF */
1780 /* fields: item->u1.list == the time values, 4 of them, as PV_WORD structs in a list
1782 item->u2.statements == a pval list of statements in the if ()
1783 item->u3.else_statements == a pval list of statements in the else
1785 fall thru to PV_IF*/
1787 /* fields: item->u1.str == the if conditional, as supplied by user
1789 item->u2.statements == a pval list of statements in the if ()
1790 item->u3.else_statements == a pval list of statements in the else
1793 /* printf(" matching in IF/IFTIME/RANDOM\n"); */
1794 if ((x=match_pval(item->u2.statements))) {
1797 if (item->u3.else_statements) {
1798 if ((x=match_pval(item->u3.else_statements))) {
1799 /* printf("IF/IFTIME/RANDOM: Responded with pval match %x\n", x); */
1806 /* fields: item->u1.str == the switch expression
1808 item->u2.statements == a pval list of statements in the switch,
1809 (will be case statements, most likely!)
1811 /* printf(" matching in SWITCH\n"); */
1812 if ((x=match_pval(item->u2.statements))) {
1813 /* printf("SWITCH: Responded with pval match %x\n", x); */
1819 /* fields: item->u1.str == the extension name, label, whatever it's called
1821 item->u2.statements == a pval list of statements in the extension
1822 item->u3.hints == a char * hint argument
1823 item->u4.regexten == an int boolean. non-zero says that regexten was specified
1825 /* printf(" matching in EXTENSION\n"); */
1826 if (!strcmp(match_exten,"*") || extension_matches(item, match_exten, item->u1.str) ) {
1827 /* printf("Descending into matching exten %s => %s\n", match_exten, item->u1.str); */
1828 if (strcmp(match_label,"1") == 0) {
1829 if (item->u2.statements) {
1830 struct pval *p5 = item->u2.statements;
1831 while (p5 && p5->type == PV_LABEL) /* find the first non-label statement in this context. If it exists, there's a "1" */
1842 if ((x=match_pval(item->u2.statements))) {
1843 /* printf("EXTENSION: Responded with pval match %x\n", x); */
1847 /* printf("Skipping exten %s\n", item->u1.str); */
1851 /* printf(" matching in default = %d\n", item->type); */
1857 struct pval *match_pval(pval *item)
1861 for (i=item; i; i=i->next) {
1863 /* printf(" -- match pval: item %d\n", i->type); */
1865 if ((x = match_pval_item(i))) {
1866 /* printf("match_pval: returning x=%x\n", (int)x); */
1867 return x; /* cut the search short */
1874 int count_labels_in_current_context(char *label)
1878 return_on_context_match = 0;
1879 match_pval(current_context->u2.statements);
1885 struct pval *find_first_label_in_current_context(char *label, pval *curr_cont)
1887 /* printf(" --- Got args %s, %s\n", exten, label); */
1890 struct pval *startpt = ((curr_cont->type==PV_MACRO)?curr_cont->u3.macro_statements: curr_cont->u2.statements);
1893 return_on_context_match = 0;
1894 match_context = "*";
1896 match_label = label;
1898 ret = match_pval(curr_cont);
1902 /* the target of the goto could be in an included context!! Fancy that!! */
1903 /* look for includes in the current context */
1904 for (p3=startpt; p3; p3=p3->next) {
1905 if (p3->type == PV_INCLUDES) {
1907 for (p4=p3->u1.list; p4; p4=p4->next) {
1908 /* for each context pointed to, find it, then find a context/label that matches the
1910 char *incl_context = p4->u1.str;
1911 /* find a matching context name */
1912 struct pval *that_context = find_context(incl_context);
1915 x3 = find_first_label_in_current_context(label, that_context);
1926 struct pval *find_label_in_current_context(char *exten, char *label, pval *curr_cont)
1928 /* printf(" --- Got args %s, %s\n", exten, label); */
1931 struct pval *startpt;
1934 return_on_context_match = 0;
1935 match_context = "*";
1936 match_exten = exten;
1937 match_label = label;
1938 if (curr_cont->type == PV_MACRO)
1939 startpt = curr_cont->u3.macro_statements;
1941 startpt = curr_cont->u2.statements;
1943 ret = match_pval(startpt);
1947 /* the target of the goto could be in an included context!! Fancy that!! */
1948 /* look for includes in the current context */
1949 for (p3=startpt; p3; p3=p3->next) {
1950 if (p3->type == PV_INCLUDES) {
1952 for (p4=p3->u1.list; p4; p4=p4->next) {
1953 /* for each context pointed to, find it, then find a context/label that matches the
1955 char *incl_context = p4->u1.str;
1956 /* find a matching context name */
1957 struct pval *that_context = find_context(incl_context);
1960 x3 = find_label_in_current_context(exten, label, that_context);
1971 static struct pval *find_label_in_current_extension(const char *label, pval *curr_ext)
1973 /* printf(" --- Got args %s\n", label); */
1975 return_on_context_match = 0;
1976 match_context = "*";
1978 match_label = label;
1979 return match_pval(curr_ext);
1982 static struct pval *find_label_in_current_db(const char *context, const char *exten, const char *label)
1984 /* printf(" --- Got args %s, %s, %s\n", context, exten, label); */
1986 return_on_context_match = 0;
1988 match_context = context;
1989 match_exten = exten;
1990 match_label = label;
1992 return match_pval(current_db);
1996 struct pval *find_macro(char *name)
1998 return_on_context_match = 1;
2000 match_context = name;
2001 match_exten = "*"; /* don't really need to set these, shouldn't be reached */
2003 return match_pval(current_db);
2006 struct pval *find_context(char *name)
2008 return_on_context_match = 1;
2010 match_context = name;
2011 match_exten = "*"; /* don't really need to set these, shouldn't be reached */
2013 return match_pval(current_db);
2016 int is_float(char *arg )
2019 for (s=arg; *s; s++) {
2020 if (*s != '.' && (*s < '0' || *s > '9'))
2025 int is_int(char *arg )
2028 for (s=arg; *s; s++) {
2029 if (*s < '0' || *s > '9')
2034 int is_empty(char *arg)
2041 if (*arg != ' ' && *arg != '\t')
2049 int option_matches_j( struct argdesc *should, pval *is, struct argapp *app)
2051 struct argchoice *ac;
2054 switch (should->dtype) {
2055 case ARGD_OPTIONSET:
2056 if ( strstr(is->u1.str,"${") )
2057 return 0; /* no checking anything if there's a var reference in there! */
2059 opcop = ast_strdupa(is->u1.str);
2061 for (q=opcop;*q;q++) { /* erase the innards of X(innard) type arguments, so we don't get confused later */
2064 while (*p && *p != ')' )
2070 for (ac=app->opts; ac; ac=ac->next) {
2071 if (strlen(ac->name)>1 && strchr(ac->name,'(') == 0 && strcmp(ac->name,is->u1.str) == 0) /* multichar option, no parens, and a match? */
2074 for (ac=app->opts; ac; ac=ac->next) {
2075 if (strlen(ac->name)==1 || strchr(ac->name,'(')) {
2076 char *p = strchr(opcop,ac->name[0]); /* wipe out all matched options in the user-supplied string */
2078 if (p && *p == 'j') {
2079 ast_log(LOG_ERROR, "Error: file %s, line %d-%d: The j option in the %s application call is not appropriate for AEL!\n",
2080 is->filename, is->startline, is->endline, app->name);
2086 if (ac->name[1] == '(') {
2087 if (*(p+1) != '(') {
2088 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The %c option in the %s application call should have an (argument), but doesn't!\n",
2089 is->filename, is->startline, is->endline, ac->name[0], app->name);
2096 for (q=opcop; *q; q++) {
2097 if ( *q != '+' && *q != '(' && *q != ')') {
2098 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The %c option in the %s application call is not available as an option!\n",
2099 is->filename, is->startline, is->endline, *q, app->name);
2111 int option_matches( struct argdesc *should, pval *is, struct argapp *app)
2113 struct argchoice *ac;
2116 switch (should->dtype) {
2118 if (is_empty(is->u1.str) && should->type == ARGD_REQUIRED)
2120 if (is->u1.str && strlen(is->u1.str) > 0) /* most will match */
2125 if (is_int(is->u1.str))
2132 if (is_float(is->u1.str))
2139 if( !is->u1.str || strlen(is->u1.str) == 0 )
2140 return 1; /* a null arg in the call will match an enum, I guess! */
2141 for (ac=should->choices; ac; ac=ac->next) {
2142 if (strcmp(ac->name,is->u1.str) == 0)
2148 case ARGD_OPTIONSET:
2149 opcop = ast_strdupa(is->u1.str);
2151 for (ac=app->opts; ac; ac=ac->next) {
2152 if (strlen(ac->name)>1 && strchr(ac->name,'(') == 0 && strcmp(ac->name,is->u1.str) == 0) /* multichar option, no parens, and a match? */
2155 for (ac=app->opts; ac; ac=ac->next) {
2156 if (strlen(ac->name)==1 || strchr(ac->name,'(')) {
2157 char *p = strchr(opcop,ac->name[0]); /* wipe out all matched options in the user-supplied string */
2161 if (ac->name[1] == '(') {
2162 if (*(p+1) == '(') {
2164 while (*q && *q != ')') {
2176 return 1; /* matches anything */
2179 return 1; /* unless some for-sure match or non-match returns, then it must be close enough ... */
2183 int check_app_args(pval* appcall, pval *arglist, struct argapp *app)
2186 struct argdesc *ad = app->args;
2190 for (pa = arglist; pa; pa=pa->next) {
2192 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Extra argument %s not in application call to %s !\n",
2193 arglist->filename, arglist->startline, arglist->endline, pa->u1.str, app->name);
2197 /* find the first entry in the ad list that will match */
2199 if ( ad->dtype == ARGD_VARARG ) /* once we hit the VARARG, all bets are off. Discontinue the comparisons */
2202 z= option_matches( ad, pa, app);
2207 if (ad->type == ARGD_REQUIRED) {
2208 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
2209 arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
2213 } else if (z && ad->dtype == ARGD_OPTIONSET) {
2214 option_matches_j( ad, pa, app);
2220 /* any app nodes left, that are not optional? */
2221 for ( ; ad; ad=ad->next) {
2222 if (ad->type == ARGD_REQUIRED && ad->dtype != ARGD_VARARG) {
2225 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
2226 arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
2237 void check_switch_expr(pval *item, struct argapp *apps)
2240 /* get and clean the variable name */
2242 struct argapp *a,*a2;
2243 struct appsetvar *v,*v2;
2244 struct argchoice *c;
2248 while (p && *p && (*p == ' ' || *p == '\t' || *p == '$' || *p == '{' ) )
2251 buff1 = ast_strdupa(p);
2253 while (strlen(buff1) > 0 && ( buff1[strlen(buff1)-1] == '}' || buff1[strlen(buff1)-1] == ' ' || buff1[strlen(buff1)-1] == '\t'))
2254 buff1[strlen(buff1)-1] = 0;
2255 /* buff1 now contains the variable name */
2257 for (a=apps; a; a=a->next) {
2258 for (v=a->setvars;v;v=v->next) {
2259 if (strcmp(v->name,buff1) == 0) {
2267 /* we have a match, to a variable that has a set of determined values */
2272 /* first of all, does this switch have a default case ? */
2273 for (t=item->u2.statements; t; t=t->next) {
2274 if (t->type == PV_DEFAULT) {
2278 if (t->type == PV_PATTERN) {
2282 if (def || pat) /* nothing to check. All cases accounted for! */
2284 for (c=v->vals; c; c=c->next) {
2286 for (t=item->u2.statements; t; t=t->next) {
2287 if (t->type == PV_CASE || t->type == PV_PATTERN) {
2288 if (!strcmp(t->u1.str,c->name)) {
2295 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: switch with expression(%s) does not handle the case of %s !\n",
2296 item->filename, item->startline, item->endline, item->u1.str, c->name);
2300 /* next, is there an app call in the current exten, that would set this var? */
2302 t = current_extension->u2.statements;
2303 if ( t && t->type == PV_STATEMENTBLOCK )
2304 t = t->u1.statements;
2305 for (; t && t != item; t=t->next) {
2306 if (t->type == PV_APPLICATION_CALL) {
2307 /* find the application that matches the u1.str */
2308 for (a2=apps; a2; a2=a2->next) {
2309 if (strcasecmp(a2->name, t->u1.str)==0) {
2310 for (v2=a2->setvars; v2; v2=v2->next) {
2311 if (strcmp(v2->name, buff1) == 0) {
2312 /* found an app that sets the var */
2326 /* see if it sets the var */
2328 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: Couldn't find an application call in this extension that sets the expression (%s) value!\n",
2329 item->filename, item->startline, item->endline, item->u1.str);
2337 /* first of all, does this switch have a default case ? */
2338 for (t=item->u2.statements; t; t=t->next) {
2339 if (t->type == PV_DEFAULT) {
2345 if (def) /* nothing to check. All cases accounted for! */
2347 /* if no default, warn and insert a default case at the end */
2348 p2 = tl->next = calloc(1, sizeof(struct pval));
2350 p2->type = PV_DEFAULT;
2351 p2->startline = tl->startline;
2352 p2->endline = tl->endline;
2353 p2->startcol = tl->startcol;
2354 p2->endcol = tl->endcol;
2355 p2->filename = strdup(tl->filename);
2356 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: A default case was automatically added to the switch.\n",
2357 p2->filename, p2->startline, p2->endline);
2363 static void check_context_names(void)
2366 for (i=current_db; i; i=i->next) {
2367 if (i->type == PV_CONTEXT || i->type == PV_MACRO) {
2368 for (j=i->next; j; j=j->next) {
2369 if ( j->type == PV_CONTEXT || j->type == PV_MACRO ) {
2370 if ( !strcmp(i->u1.str, j->u1.str) )
2372 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: The context name (%s) is also declared in file %s, line %d-%d!\n",
2373 i->filename, i->startline, i->endline, i->u1.str, j->filename, j->startline, j->endline);
2382 static void check_abstract_reference(pval *abstract_context)
2385 /* find some context includes that reference this context */
2388 /* otherwise, print out a warning */
2389 for (i=current_db; i; i=i->next) {
2390 if (i->type == PV_CONTEXT) {
2391 for (j=i->u2. statements; j; j=j->next) {
2392 if ( j->type == PV_INCLUDES ) {
2394 for (p4=j->u1.list; p4; p4=p4->next) {
2395 /* for each context pointed to, find it, then find a context/label that matches the
2397 if ( !strcmp(p4->u1.str, abstract_context->u1.str) )
2398 return; /* found a match! */
2404 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: Couldn't find a reference to this abstract context (%s) in any other context!\n",
2405 abstract_context->filename, abstract_context->startline, abstract_context->endline, abstract_context->u1.str);
2410 void check_pval_item(pval *item, struct argapp *apps, int in_globals)
2414 struct argapp *app, *found;
2416 struct pval *macro_def;
2417 struct pval *app_def;
2422 switch (item->type) {
2424 /* fields: item->u1.str == string associated with this (word).
2425 item->u2.arglist == pval list of 4 PV_WORD elements for time values (only in PV_INCLUDES) */
2429 /* fields: item->u1.str == name of macro
2430 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
2431 item->u2.arglist->u1.str == argument
2432 item->u2.arglist->next == next arg
2434 item->u3.macro_statements == pval list of statements in macro body.
2436 in_abstract_context = 0;
2437 current_context = item;
2438 current_extension = 0;
2440 check_macro_returns(item);
2442 for (lp=item->u2.arglist; lp; lp=lp->next) {
2445 check_pval(item->u3.macro_statements, apps,in_globals);
2449 /* fields: item->u1.str == name of context
2450 item->u2.statements == pval list of statements in context body
2451 item->u3.abstract == int 1 if an abstract keyword were present
2453 current_context = item;
2454 current_extension = 0;
2455 if ( item->u3.abstract ) {
2456 in_abstract_context = 1;
2457 check_abstract_reference(item);
2459 in_abstract_context = 0;
2460 check_pval(item->u2.statements, apps,in_globals);
2464 /* fields: item->u1.str == name of macro to call
2465 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
2466 item->u2.arglist->u1.str == argument
2467 item->u2.arglist->next == next arg
2469 macro_def = find_macro(item->u1.str);
2471 /* here is a good place to check to see if the definition is in extensions.conf! */
2472 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: macro call to non-existent %s ! Hopefully it is present in extensions.conf! \n",
2473 item->filename, item->startline, item->endline, item->u1.str);
2475 } else if (macro_def->type != PV_MACRO) {
2476 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: macro call to %s references a context, not a macro!\n",
2477 item->filename, item->startline, item->endline, item->u1.str);
2480 /* macro_def is a MACRO, so do the args match in number? */
2484 for (lp=item->u2.arglist; lp; lp=lp->next) {
2487 for (lp=macro_def->u2.arglist; lp; lp=lp->next) {
2490 if (hereargs != thereargs ) {
2491 ast_log(LOG_ERROR, "Error: file %s, line %d-%d: The macro call to %s has %d arguments, but the macro definition has %d arguments\n",
2492 item->filename, item->startline, item->endline, item->u1.str, hereargs, thereargs);
2498 case PV_APPLICATION_CALL:
2499 /* fields: item->u1.str == name of application to call
2500 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
2501 item->u2.arglist->u1.str == argument
2502 item->u2.arglist->next == next arg
2504 /* Need to check to see if the application is available! */
2505 app_def = find_context(item->u1.str);
2506 if (app_def && app_def->type == PV_MACRO) {
2507 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: application call to %s references an existing macro, but had no & preceding it!\n",
2508 item->filename, item->startline, item->endline, item->u1.str);
2511 if (strcasecmp(item->u1.str,"GotoIf") == 0
2512 || strcasecmp(item->u1.str,"GotoIfTime") == 0
2513 || strcasecmp(item->u1.str,"while") == 0
2514 || strcasecmp(item->u1.str,"endwhile") == 0
2515 || strcasecmp(item->u1.str,"random") == 0
2516 || strcasecmp(item->u1.str,"gosub") == 0
2517 || strcasecmp(item->u1.str,"return") == 0
2518 || strcasecmp(item->u1.str,"gosubif") == 0
2519 || strcasecmp(item->u1.str,"continuewhile") == 0
2520 || strcasecmp(item->u1.str,"endwhile") == 0
2521 || strcasecmp(item->u1.str,"execif") == 0
2522 || strcasecmp(item->u1.str,"execiftime") == 0
2523 || strcasecmp(item->u1.str,"exitwhile") == 0
2524 || strcasecmp(item->u1.str,"goto") == 0
2525 || strcasecmp(item->u1.str,"macro") == 0
2526 || strcasecmp(item->u1.str,"macroexclusive") == 0
2527 || strcasecmp(item->u1.str,"macroif") == 0
2528 || strcasecmp(item->u1.str,"stackpop") == 0
2529 || strcasecmp(item->u1.str,"execIf") == 0 ) {
2530 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: application call to %s affects flow of control, and needs to be re-written using AEL if, while, goto, etc. keywords instead!\n",
2531 item->filename, item->startline, item->endline, item->u1.str);
2534 if (strcasecmp(item->u1.str,"macroexit") == 0) {
2535 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: I am converting the MacroExit call here to a return statement.\n",
2536 item->filename, item->startline, item->endline);
2537 item->type = PV_RETURN;
2544 for (app=apps; app; app=app->next) {
2545 if (strcasecmp(app->name, item->u1.str) == 0) {
2551 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: application call to %s not listed in applist database!\n",
2552 item->filename, item->startline, item->endline, item->u1.str);
2555 check_app_args(item, item->u2.arglist, app);
2560 /* fields: item->u1.str == value of case
2561 item->u2.statements == pval list of statements under the case
2563 /* Make sure sequence of statements under case is terminated with goto, return, or break */
2564 /* find the last statement */
2565 check_pval(item->u2.statements, apps,in_globals);
2569 /* fields: item->u1.str == value of case
2570 item->u2.statements == pval list of statements under the case
2572 /* Make sure sequence of statements under case is terminated with goto, return, or break */
2573 /* find the last statement */
2575 check_pval(item->u2.statements, apps,in_globals);
2580 item->u2.statements == pval list of statements under the case
2583 check_pval(item->u2.statements, apps,in_globals);
2587 /* fields: item->u1.str == name of extension to catch
2588 item->u2.statements == pval list of statements in context body
2590 check_pval(item->u2.statements, apps,in_globals);
2594 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
2596 check_pval(item->u1.list, apps,in_globals);
2600 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
2602 check_pval(item->u1.list, apps,in_globals);
2606 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
2608 check_pval(item->u1.list, apps,in_globals);
2609 check_includes(item);
2610 for (lp=item->u1.list; lp; lp=lp->next){
2611 char *incl_context = lp->u1.str;
2612 struct pval *that_context = find_context(incl_context);
2614 if ( lp->u2.arglist ) {
2615 check_timerange(lp->u2.arglist);
2616 check_dow(lp->u2.arglist->next);
2617 check_day(lp->u2.arglist->next->next);
2618 check_month(lp->u2.arglist->next->next->next);
2622 find_pval_gotos(that_context->u2.statements,0);
2628 case PV_STATEMENTBLOCK:
2629 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
2631 check_pval(item->u1.list, apps,in_globals);
2635 case PV_LOCALVARDEC:
2636 /* fields: item->u1.str == variable name
2637 item->u2.val == variable value to assign
2639 /* the RHS of a vardec is encapsulated in a $[] expr. Is it legal? */
2640 if( !in_globals ) { /* don't check stuff inside the globals context; no wrapping in $[ ] there... */
2641 snprintf(errmsg,sizeof(errmsg), "file %s, line %d, columns %d-%d, variable declaration expr '%s':", config, item->startline, item->startcol, item->endcol, item->u2.val);
2642 ast_expr_register_extra_error_info(errmsg);
2643 ast_expr(item->u2.val, expr_output, sizeof(expr_output),NULL);
2644 ast_expr_clear_extra_error_info();
2645 if ( strpbrk(item->u2.val,"~!-+<>=*/&^") && !strstr(item->u2.val,"${") ) {
2646 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2647 item->filename, item->startline, item->endline, item->u2.val);
2650 check_expr2_input(item,item->u2.val);
2655 /* fields: item->u1.list == pval list of PV_WORD target names, up to 3, in order as given by user.
2656 item->u1.list->u1.str == where the data on a PV_WORD will always be.
2658 /* don't check goto's in abstract contexts */
2659 if ( in_abstract_context )
2666 /* fields: item->u1.str == label name
2668 if ( strspn(item->u1.str, "0123456789") == strlen(item->u1.str) ) {
2669 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: label '%s' is numeric, this is bad practice!\n",
2670 item->filename, item->startline, item->endline, item->u1.str);
2678 /* fields: item->u1.for_init == a string containing the initalizer
2679 item->u2.for_test == a string containing the loop test
2680 item->u3.for_inc == a string containing the loop increment
2682 item->u4.for_statements == a pval list of statements in the for ()
2684 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, for test expr '%s':", config, item->startline, item->startcol, item->endcol, item->u2.for_test);
2685 ast_expr_register_extra_error_info(errmsg);
2687 strp = strchr(item->u1.for_init, '=');
2689 ast_expr(strp+1, expr_output, sizeof(expr_output),NULL);
2691 ast_expr(item->u2.for_test, expr_output, sizeof(expr_output),NULL);
2692 strp = strchr(item->u3.for_inc, '=');
2694 ast_expr(strp+1, expr_output, sizeof(expr_output),NULL);
2696 if ( strpbrk(item->u2.for_test,"~!-+<>=*/&^") && !strstr(item->u2.for_test,"${") ) {
2697 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2698 item->filename, item->startline, item->endline, item->u2.for_test);
2701 if ( strpbrk(item->u3.for_inc,"~!-+<>=*/&^") && !strstr(item->u3.for_inc,"${") ) {
2702 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2703 item->filename, item->startline, item->endline, item->u3.for_inc);
2706 check_expr2_input(item,item->u2.for_test);
2707 check_expr2_input(item,item->u3.for_inc);
2709 ast_expr_clear_extra_error_info();
2710 check_pval(item->u4.for_statements, apps,in_globals);
2714 /* fields: item->u1.str == the while conditional, as supplied by user
2716 item->u2.statements == a pval list of statements in the while ()
2718 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, while expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2719 ast_expr_register_extra_error_info(errmsg);
2720 ast_expr(item->u1.str, expr_output, sizeof(expr_output),NULL);
2721 ast_expr_clear_extra_error_info();
2722 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
2723 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2724 item->filename, item->startline, item->endline, item->u1.str);
2727 check_expr2_input(item,item->u1.str);
2728 check_pval(item->u2.statements, apps,in_globals);
2745 check_continue(item);
2749 /* fields: item->u1.str == the random number expression, as supplied by user
2751 item->u2.statements == a pval list of statements in the if ()
2752 item->u3.else_statements == a pval list of statements in the else
2755 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, random expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2756 ast_expr_register_extra_error_info(errmsg);
2757 ast_expr(item->u1.str, expr_output, sizeof(expr_output),NULL);
2758 ast_expr_clear_extra_error_info();
2759 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
2760 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: random expression '%s' has operators, but no variables. Interesting...\n",
2761 item->filename, item->startline, item->endline, item->u1.str);
2764 check_expr2_input(item,item->u1.str);
2765 check_pval(item->u2.statements, apps,in_globals);
2766 if (item->u3.else_statements) {
2767 check_pval(item->u3.else_statements, apps,in_globals);
2772 /* fields: item->u1.list == the if time values, 4 of them, each in PV_WORD, linked list
2774 item->u2.statements == a pval list of statements in the if ()
2775 item->u3.else_statements == a pval list of statements in the else
2778 if ( item->u2.arglist ) {
2779 check_timerange(item->u1.list);
2780 check_dow(item->u1.list->next);
2781 check_day(item->u1.list->next->next);
2782 check_month(item->u1.list->next->next->next);
2785 check_pval(item->u2.statements, apps,in_globals);
2786 if (item->u3.else_statements) {
2787 check_pval(item->u3.else_statements, apps,in_globals);
2792 /* fields: item->u1.str == the if conditional, as supplied by user
2794 item->u2.statements == a pval list of statements in the if ()
2795 item->u3.else_statements == a pval list of statements in the else
2798 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, if expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2799 ast_expr_register_extra_error_info(errmsg);
2800 ast_expr(item->u1.str, expr_output, sizeof(expr_output),NULL);
2801 ast_expr_clear_extra_error_info();
2802 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
2803 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression '%s' has operators, but no variables. Interesting...\n",
2804 item->filename, item->startline, item->endline, item->u1.str);
2807 check_expr2_input(item,item->u1.str);
2808 check_pval(item->u2.statements, apps,in_globals);
2809 if (item->u3.else_statements) {
2810 check_pval(item->u3.else_statements, apps,in_globals);
2815 /* fields: item->u1.str == the switch expression
2817 item->u2.statements == a pval list of statements in the switch,
2818 (will be case statements, most likely!)
2820 /* we can check the switch expression, see if it matches any of the app variables...
2821 if it does, then, are all the possible cases accounted for? */
2822 check_switch_expr(item, apps);
2823 check_pval(item->u2.statements, apps,in_globals);
2827 /* fields: item->u1.str == the extension name, label, whatever it's called
2829 item->u2.statements == a pval list of statements in the extension
2830 item->u3.hints == a char * hint argument
2831 item->u4.regexten == an int boolean. non-zero says that regexten was specified
2833 current_extension = item ;