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);
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,"goto %s", item->u1.list->u1.str);
320 if ( item->u1.list->next )
321 fprintf(fin,"|%s", item->u1.list->next->u1.str);
322 if ( item->u1.list->next && item->u1.list->next->next )
323 fprintf(fin,"|%s", item->u1.list->next->next->u1.str);
328 fprintf(fin,"%s:\n", item->u1.str);
332 fprintf(fin,"for (%s; %s; %s)\n", item->u1.for_init, item->u2.for_test, item->u3.for_inc);
333 print_pval_list(fin,item->u4.for_statements,depth+1);
337 fprintf(fin,"while (%s)\n", item->u1.str);
338 print_pval_list(fin,item->u2.statements,depth+1);
342 fprintf(fin,"break;\n");
346 fprintf(fin,"return;\n");
350 fprintf(fin,"continue;\n");
356 if ( item->type == PV_IFTIME ) {
358 fprintf(fin,"ifTime ( %s|%s|%s|%s )\n",
359 item->u1.list->u1.str,
360 item->u1.list->next->u1.str,
361 item->u1.list->next->next->u1.str,
362 item->u1.list->next->next->next->u1.str
364 } else if ( item->type == PV_RANDOM ) {
365 fprintf(fin,"random ( %s )\n", item->u1.str );
367 fprintf(fin,"if ( %s )\n", item->u1.str);
368 if ( item->u2.statements && item->u2.statements->next ) {
369 for (i=0; i<depth; i++) {
370 fprintf(fin,"\t"); /* depth == indentation */
373 print_pval_list(fin,item->u2.statements,depth+1);
374 for (i=0; i<depth; i++) {
375 fprintf(fin,"\t"); /* depth == indentation */
377 if ( item->u3.else_statements )
381 } else if (item->u2.statements ) {
382 print_pval_list(fin,item->u2.statements,depth+1);
384 if (item->u3.else_statements )
385 fprintf(fin, " {} ");
387 fprintf(fin, " {}; ");
389 if ( item->u3.else_statements ) {
390 for (i=0; i<depth; i++) {
391 fprintf(fin,"\t"); /* depth == indentation */
393 fprintf(fin,"else\n");
394 print_pval_list(fin,item->u3.else_statements, depth);
399 fprintf(fin,"switch( %s ) {\n", item->u1.str);
400 print_pval_list(fin,item->u2.statements,depth+1);
401 for (i=0; i<depth; i++) {
402 fprintf(fin,"\t"); /* depth == indentation */
408 if ( item->u4.regexten )
409 fprintf(fin, "regexten ");
410 if ( item->u3.hints )
411 fprintf(fin,"hints(%s) ", item->u3.hints);
413 fprintf(fin,"%s => \n", item->u1.str);
414 print_pval_list(fin,item->u2.statements,depth+1);
418 fprintf(fin,"ignorepat => %s\n", item->u1.str);
422 fprintf(fin,"globals {\n");
423 print_pval_list(fin,item->u1.statements,depth+1);
424 for (i=0; i<depth; i++) {
425 fprintf(fin,"\t"); /* depth == indentation */
432 static void print_pval_list(FILE *fin, pval *item, int depth)
436 for (i=item; i; i=i->next) {
437 print_pval(fin, i, depth);
442 static void ael2_print(char *fname, pval *tree)
444 FILE *fin = fopen(fname,"w");
446 ast_log(LOG_ERROR, "Couldn't open %s for writing.\n", fname);
449 print_pval_list(fin, tree, 0);
455 /* EMPTY TEMPLATE FUNCS FOR AEL TRAVERSAL: ============================================================================= */
457 void traverse_pval_template(pval *item, int depth);
458 void traverse_pval_item_template(pval *item, int depth);
461 void traverse_pval_item_template(pval *item, int depth)/* depth comes in handy for a pretty print (indentation),
462 but you may not need it */
466 switch ( item->type ) {
468 /* fields: item->u1.str == string associated with this (word). */
472 /* fields: item->u1.str == name of macro
473 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
474 item->u2.arglist->u1.str == argument
475 item->u2.arglist->next == next arg
477 item->u3.macro_statements == pval list of statements in macro body.
479 for (lp=item->u2.arglist; lp; lp=lp->next) {
482 traverse_pval_item_template(item->u3.macro_statements,depth+1);
486 /* fields: item->u1.str == name of context
487 item->u2.statements == pval list of statements in context body
488 item->u3.abstract == int 1 if an abstract keyword were present
490 traverse_pval_item_template(item->u2.statements,depth+1);
494 /* fields: item->u1.str == name of macro to call
495 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
496 item->u2.arglist->u1.str == argument
497 item->u2.arglist->next == next arg
499 for (lp=item->u2.arglist; lp; lp=lp->next) {
503 case PV_APPLICATION_CALL:
504 /* fields: item->u1.str == name of application to call
505 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
506 item->u2.arglist->u1.str == argument
507 item->u2.arglist->next == next arg
509 for (lp=item->u2.arglist; lp; lp=lp->next) {
514 /* fields: item->u1.str == value of case
515 item->u2.statements == pval list of statements under the case
517 traverse_pval_item_template(item->u2.statements,depth+1);
521 /* fields: item->u1.str == value of case
522 item->u2.statements == pval list of statements under the case
524 traverse_pval_item_template(item->u2.statements,depth+1);
529 item->u2.statements == pval list of statements under the case
531 traverse_pval_item_template(item->u2.statements,depth+1);
535 /* fields: item->u1.str == name of extension to catch
536 item->u2.statements == pval list of statements in context body
538 traverse_pval_item_template(item->u2.statements,depth+1);
542 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
544 traverse_pval_item_template(item->u1.list,depth+1);
548 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
550 traverse_pval_item_template(item->u1.list,depth+1);
554 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
555 item->u2.arglist == pval list of 4 PV_WORD elements for time values
557 traverse_pval_item_template(item->u1.list,depth+1);
558 traverse_pval_item_template(item->u2.arglist,depth+1);
561 case PV_STATEMENTBLOCK:
562 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
564 traverse_pval_item_template(item->u1.list,depth+1);
568 /* fields: item->u1.str == variable name
569 item->u2.val == variable value to assign
574 /* fields: item->u1.list == pval list of PV_WORD target names, up to 3, in order as given by user.
575 item->u1.list->u1.str == where the data on a PV_WORD will always be.
578 if ( item->u1.list->next )
580 if ( item->u1.list->next && item->u1.list->next->next )
586 /* fields: item->u1.str == label name
591 /* fields: item->u1.for_init == a string containing the initalizer
592 item->u2.for_test == a string containing the loop test
593 item->u3.for_inc == a string containing the loop increment
595 item->u4.for_statements == a pval list of statements in the for ()
597 traverse_pval_item_template(item->u4.for_statements,depth+1);
601 /* fields: item->u1.str == the while conditional, as supplied by user
603 item->u2.statements == a pval list of statements in the while ()
605 traverse_pval_item_template(item->u2.statements,depth+1);
624 /* fields: item->u1.list == there are 4 linked PV_WORDs here.
626 item->u2.statements == a pval list of statements in the if ()
627 item->u3.else_statements == a pval list of statements in the else
630 traverse_pval_item_template(item->u2.statements,depth+1);
631 if ( item->u3.else_statements ) {
632 traverse_pval_item_template(item->u3.else_statements,depth+1);
637 /* fields: item->u1.str == the random number expression, as supplied by user
639 item->u2.statements == a pval list of statements in the if ()
640 item->u3.else_statements == a pval list of statements in the else
643 traverse_pval_item_template(item->u2.statements,depth+1);
644 if ( item->u3.else_statements ) {
645 traverse_pval_item_template(item->u3.else_statements,depth+1);
650 /* fields: item->u1.str == the if conditional, as supplied by user
652 item->u2.statements == a pval list of statements in the if ()
653 item->u3.else_statements == a pval list of statements in the else
656 traverse_pval_item_template(item->u2.statements,depth+1);
657 if ( item->u3.else_statements ) {
658 traverse_pval_item_template(item->u3.else_statements,depth+1);
663 /* fields: item->u1.str == the switch expression
665 item->u2.statements == a pval list of statements in the switch,
666 (will be case statements, most likely!)
668 traverse_pval_item_template(item->u2.statements,depth+1);
672 /* fields: item->u1.str == the extension name, label, whatever it's called
674 item->u2.statements == a pval list of statements in the extension
675 item->u3.hints == a char * hint argument
676 item->u4.regexten == an int boolean. non-zero says that regexten was specified
678 traverse_pval_item_template(item->u2.statements,depth+1);
682 /* fields: item->u1.str == the ignorepat data
687 /* fields: item->u1.statements == pval list of statements, usually vardecs
689 traverse_pval_item_template(item->u1.statements,depth+1);
694 void traverse_pval_template(pval *item, int depth) /* depth comes in handy for a pretty print (indentation),
695 but you may not need it */
699 for (i=item; i; i=i->next) {
700 traverse_pval_item_template(i, depth);
705 /* SEMANTIC CHECKING FOR AEL: ============================================================================= */
707 /* (not all that is syntactically legal is good! */
710 static void check_macro_returns(pval *macro)
713 if (!macro->u3.macro_statements)
715 pval *z = calloc(1, sizeof(struct pval));
716 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The macro %s is empty! I will insert a return.\n",
717 macro->filename, macro->startline, macro->endline, macro->u1.str);
720 z->startline = macro->startline;
721 z->endline = macro->endline;
722 z->startcol = macro->startcol;
723 z->endcol = macro->endcol;
724 z->filename = strdup(macro->filename);
726 macro->u3.macro_statements = z;
729 for (i=macro->u3.macro_statements; i; i=i->next) {
730 /* if the last statement in the list is not return, then insert a return there */
731 if (i->next == NULL) {
732 if (i->type != PV_RETURN) {
733 pval *z = calloc(1, sizeof(struct pval));
734 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The macro %s does not end with a return; I will insert one.\n",
735 macro->filename, macro->startline, macro->endline, macro->u1.str);
738 z->startline = macro->startline;
739 z->endline = macro->endline;
740 z->startcol = macro->startcol;
741 z->endcol = macro->endcol;
742 z->filename = strdup(macro->filename);
754 static int extension_matches(pval *here, const char *exten, const char *pattern)
759 /* simple case, they match exactly, the pattern and exten name */
760 if (!strcmp(pattern,exten) == 0)
763 if (pattern[0] == '_') {
768 if ( strlen(pattern)*5 >= 2000 ) /* safety valve */ {
769 ast_log(LOG_ERROR,"Error: The pattern %s is way too big. Pattern matching cancelled.\n",
773 /* form a regular expression from the pattern, and then match it against exten */
774 *r++ = '^'; /* what if the extension is a pattern ?? */
775 *r++ = '_'; /* what if the extension is a pattern ?? */
777 for (p=pattern+1; *p; p++) {
807 while ( *p && *p != ']' ) {
811 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The extension pattern '%s' is missing a closing bracket \n",
812 here->filename, here->startline, here->endline, pattern);
831 *r++ = '$'; /* what if the extension is a pattern ?? */
832 *r++ = *p++; /* put in the closing null */
833 err1 = regcomp(&preg, reg1, REG_NOSUB|REG_EXTENDED);
836 regerror(err1,&preg,errmess,sizeof(errmess));
838 ast_log(LOG_WARNING, "Regcomp of %s failed, error code %d\n",
842 err1 = regexec(&preg, exten, 0, 0, 0);
846 /* ast_log(LOG_NOTICE,"*****************************[%d]Extension %s did not match %s(%s)\n",
847 err1,exten, pattern, reg1); */
848 return 0; /* no match */
850 /* ast_log(LOG_NOTICE,"*****************************Extension %s matched %s\n",
857 if ( strcmp(exten,pattern) == 0 ) {
865 static void check_expr2_input(pval *expr, char *str)
867 int spaces = strspn(str,"\t \n");
868 if ( !strncmp(str+spaces,"$[",2) ) {
869 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The expression '%s' is redundantly wrapped in '$[ ]'. \n",
870 expr->filename, expr->startline, expr->endline, str);
875 static void check_includes(pval *includes)
878 for (p4=includes->u1.list; p4; p4=p4->next) {
879 /* for each context pointed to, find it, then find a context/label that matches the
881 char *incl_context = p4->u1.str;
882 /* find a matching context name */
883 struct pval *that_other_context = find_context(incl_context);
884 if (!that_other_context && strcmp(incl_context, "parkedcalls") != 0) {
885 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The included context '%s' cannot be found.\n",
886 includes->filename, includes->startline, includes->endline, incl_context);
893 static void check_timerange(pval *p)
900 times = ast_strdupa(p->u1.str);
902 /* Star is all times */
903 if (ast_strlen_zero(times) || !strcmp(times, "*")) {
906 /* Otherwise expect a range */
907 e = strchr(times, '-');
909 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",
910 p->filename, p->startline, p->endline, times);
916 while (*e && !isdigit(*e))
919 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The time range format (%s) is missing the end time!\n",
920 p->filename, p->startline, p->endline, p->u1.str);
923 if (sscanf(times, "%d:%d", &s1, &s2) != 2) {
924 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start time (%s) isn't quite right!\n",
925 p->filename, p->startline, p->endline, times);
928 if (sscanf(e, "%d:%d", &e1, &e2) != 2) {
929 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end time (%s) isn't quite right!\n",
930 p->filename, p->startline, p->endline, times);
935 if ((s1 < 0) || (s1 >= 24*30)) {
936 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start time (%s) is out of range!\n",
937 p->filename, p->startline, p->endline, times);
941 if ((e1 < 0) || (e1 >= 24*30)) {
942 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end time (%s) is out of range!\n",
943 p->filename, p->startline, p->endline, e);
949 static char *days[] =
960 /*! \brief get_dow: Get day of week */
961 static void check_dow(pval *DOW)
965 /* The following line is coincidence, really! */
968 dow = ast_strdupa(DOW->u1.str);
970 /* Check for all days */
971 if (ast_strlen_zero(dow) || !strcmp(dow, "*"))
973 /* Get start and ending days */
974 c = strchr(dow, '-');
982 while ((s < 7) && strcasecmp(dow, days[s])) s++;
984 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",
985 DOW->filename, DOW->startline, DOW->endline, dow);
990 while ((e < 7) && strcasecmp(c, days[e])) e++;
992 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",
993 DOW->filename, DOW->startline, DOW->endline, c);
1000 static void check_day(pval *DAY)
1004 /* The following line is coincidence, really! */
1007 day = ast_strdupa(DAY->u1.str);
1009 /* Check for all days */
1010 if (ast_strlen_zero(day) || !strcmp(day, "*")) {
1013 /* Get start and ending days */
1014 c = strchr(day, '-');
1019 /* Find the start */
1020 if (sscanf(day, "%d", &s) != 1) {
1021 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start day of month (%s) must be a number!\n",
1022 DAY->filename, DAY->startline, DAY->endline, day);
1025 else if ((s < 1) || (s > 31)) {
1026 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",
1027 DAY->filename, DAY->startline, DAY->endline, day);
1032 if (sscanf(c, "%d", &e) != 1) {
1033 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day of month (%s) must be a number!\n",
1034 DAY->filename, DAY->startline, DAY->endline, c);
1037 else if ((e < 1) || (e > 31)) {
1038 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",
1039 DAY->filename, DAY->startline, DAY->endline, day);
1047 static char *months[] =
1063 static void check_month(pval *MON)
1067 /* The following line is coincidence, really! */
1070 mon = ast_strdupa(MON->u1.str);
1072 /* Check for all days */
1073 if (ast_strlen_zero(mon) || !strcmp(mon, "*"))
1075 /* Get start and ending days */
1076 c = strchr(mon, '-');
1081 /* Find the start */
1083 while ((s < 12) && strcasecmp(mon, months[s])) s++;
1085 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n",
1086 MON->filename, MON->startline, MON->endline, mon);
1091 while ((e < 12) && strcasecmp(mon, months[e])) e++;
1093 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n",
1094 MON->filename, MON->startline, MON->endline, c);
1101 static int check_break(pval *item)
1105 while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) /* early cutout, sort of */ {
1106 /* a break is allowed in WHILE, FOR, CASE, DEFAULT, PATTERN; otherwise, it don't make
1108 if( p->type == PV_CASE || p->type == PV_DEFAULT || p->type == PV_PATTERN
1109 || p->type == PV_WHILE || p->type == PV_FOR ) {
1114 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'break' not in switch, for, or while statement!\n",
1115 item->filename, item->startline, item->endline);
1121 static int check_continue(pval *item)
1125 while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) /* early cutout, sort of */ {
1126 /* a break is allowed in WHILE, FOR, CASE, DEFAULT, PATTERN; otherwise, it don't make
1128 if( p->type == PV_WHILE || p->type == PV_FOR ) {
1133 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'continue' not in 'for' or 'while' statement!\n",
1134 item->filename, item->startline, item->endline);
1140 static struct pval *in_macro(pval *item)
1145 if( curr->type == PV_MACRO ) {
1153 static struct pval *in_context(pval *item)
1158 if( curr->type == PV_MACRO || curr->type == PV_CONTEXT ) {
1167 /* general purpose goto finder */
1169 static void check_label(pval *item)
1175 /* A label outside an extension just plain does not make sense! */
1180 if( curr->type == PV_MACRO || curr->type == PV_EXTENSION ) {
1188 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: Label %s is not within an extension or macro!\n",
1189 item->filename, item->startline, item->endline, item->u1.str);
1194 /* basically, ensure that a label is not repeated in a context. Period.
1195 The method: well, for each label, find the first label in the context
1196 with the same name. If it's not the current label, then throw an error. */
1199 /* printf("==== check_label: ====\n"); */
1200 if( !current_extension )
1201 curr = current_context;
1203 curr = current_extension;
1205 x = find_first_label_in_current_context((char *)item->u1.str, curr);
1206 /* 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); */
1207 if( x && x != item )
1209 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: Duplicate label %s! Previously defined at file %s, line %d.\n",
1210 item->filename, item->startline, item->endline, item->u1.str, x->filename, x->startline);
1213 /* printf("<<<<< check_label: ====\n"); */
1216 static pval *get_goto_target(pval *item)
1218 /* just one item-- the label should be in the current extension */
1219 pval *curr_ext = get_extension_or_contxt(item); /* containing exten, or macro */
1222 if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) {
1223 struct pval *x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), curr_ext);
1227 curr_cont = get_contxt(item);
1230 if (item->u1.list->next && !item->u1.list->next->next) {
1231 if (!strstr((item->u1.list)->u1.str,"${")
1232 && !strstr(item->u1.list->next->u1.str,"${") ) /* Don't try to match variables */ {
1233 struct pval *x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, curr_cont);
1239 if (item->u1.list->next && item->u1.list->next->next) {
1241 pval *first = item->u1.list;
1242 pval *second = item->u1.list->next;
1243 pval *third = item->u1.list->next->next;
1245 if (!strstr((item->u1.list)->u1.str,"${")
1246 && !strstr(item->u1.list->next->u1.str,"${")
1247 && !strstr(item->u1.list->next->next->u1.str,"${")) /* Don't try to match variables */ {
1248 struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str);
1252 struct pval *that_context = find_context(item->u1.list->u1.str);
1254 /* the target of the goto could be in an included context!! Fancy that!! */
1255 /* look for includes in the current context */
1257 for (p3=that_context->u2.statements; p3; p3=p3->next) {
1258 if (p3->type == PV_INCLUDES) {
1260 for (p4=p3->u1.list; p4; p4=p4->next) {
1261 /* for each context pointed to, find it, then find a context/label that matches the
1263 char *incl_context = p4->u1.str;
1264 /* find a matching context name */
1265 struct pval *that_other_context = find_context(incl_context);
1266 if (that_other_context) {
1268 x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context);
1284 static void check_goto(pval *item)
1286 /* check for the target of the goto-- does it exist? */
1287 if ( !(item->u1.list)->next && !(item->u1.list)->u1.str ) {
1288 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: empty label reference found!\n",
1289 item->filename, item->startline, item->endline);
1293 /* just one item-- the label should be in the current extension */
1295 if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) {
1296 struct pval *z = get_extension_or_contxt(item);
1299 x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), z); /* if in macro, use current context instead */
1300 /* printf("Called find_label_in_current_extension with arg %s; current_extension is %x: %d\n",
1301 (char*)((item->u1.list)->u1.str), current_extension?current_extension:current_context, current_extension?current_extension->type:current_context->type); */
1303 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s exists in the current extension!\n",
1304 item->filename, item->startline, item->endline, item->u1.list->u1.str);
1312 if (item->u1.list->next && !item->u1.list->next->next) {
1314 /* printf("Calling find_label_in_current_context with args %s, %s\n",
1315 (char*)((item->u1.list)->u1.str), (char *)item->u1.list->next->u1.str); */
1316 if (!strstr((item->u1.list)->u1.str,"${")
1317 && !strstr(item->u1.list->next->u1.str,"${") ) /* Don't try to match variables */ {
1318 struct pval *z = get_contxt(item);
1322 x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, z);
1325 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",
1326 item->filename, item->startline, item->endline, item->u1.list->u1.str, item->u1.list->next->u1.str );
1335 if (item->u1.list->next && item->u1.list->next->next) {
1337 pval *first = item->u1.list;
1338 pval *second = item->u1.list->next;
1339 pval *third = item->u1.list->next->next;
1341 /* printf("Calling find_label_in_current_db with args %s, %s, %s\n",
1342 (char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str); */
1343 if (!strstr((item->u1.list)->u1.str,"${")
1344 && !strstr(item->u1.list->next->u1.str,"${")
1345 && !strstr(item->u1.list->next->next->u1.str,"${")) /* Don't try to match variables */ {
1346 struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str);
1349 struct pval *found = 0;
1350 struct pval *that_context = find_context(item->u1.list->u1.str);
1352 /* the target of the goto could be in an included context!! Fancy that!! */
1353 /* look for includes in the current context */
1355 for (p3=that_context->u2.statements; p3; p3=p3->next) {
1356 if (p3->type == PV_INCLUDES) {
1358 for (p4=p3->u1.list; p4; p4=p4->next) {
1359 /* for each context pointed to, find it, then find a context/label that matches the
1361 char *incl_context = p4->u1.str;
1362 /* find a matching context name */
1363 struct pval *that_other_context = find_context(incl_context);
1364 if (that_other_context) {
1366 x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context);
1376 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s|%s exists in the context %s or its inclusions!\n",
1377 item->filename, item->startline, item->endline, item->u1.list->next->u1.str, item->u1.list->next->next->u1.str, item->u1.list->u1.str );
1380 struct pval *mac = in_macro(item); /* is this goto inside a macro? */
1381 if( mac ) { /* yes! */
1382 struct pval *targ = in_context(found);
1385 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",
1386 item->filename, item->startline, item->endline);
1392 /* here is where code would go to check for target existence in extensions.conf files */
1393 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: goto: no context %s could be found that matches the goto target!\n",
1394 item->filename, item->startline, item->endline, item->u1.list->u1.str);
1395 warns++; /* this is just a warning, because this context could be in extensions.conf or somewhere */
1398 struct pval *mac = in_macro(item); /* is this goto inside a macro? */
1399 if( mac ) { /* yes! */
1400 struct pval *targ = in_context(x);
1403 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",
1404 item->filename, item->startline, item->endline);
1414 static void find_pval_goto_item(pval *item, int lev)
1418 ast_log(LOG_ERROR,"find_pval_goto in infinite loop!\n\n");
1422 switch ( item->type ) {
1424 /* fields: item->u1.str == name of macro
1425 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
1426 item->u2.arglist->u1.str == argument
1427 item->u2.arglist->next == next arg
1429 item->u3.macro_statements == pval list of statements in macro body.
1432 /* printf("Descending into matching macro %s\n", match_context); */
1433 find_pval_gotos(item->u3.macro_statements,lev+1); /* if we're just searching for a context, don't bother descending into them */
1438 /* fields: item->u1.str == name of context
1439 item->u2.statements == pval list of statements in context body
1440 item->u3.abstract == int 1 if an abstract keyword were present
1445 /* fields: item->u1.str == value of case
1446 item->u2.statements == pval list of statements under the case
1448 find_pval_gotos(item->u2.statements,lev+1);
1452 /* fields: item->u1.str == value of case
1453 item->u2.statements == pval list of statements under the case
1455 find_pval_gotos(item->u2.statements,lev+1);
1460 item->u2.statements == pval list of statements under the case
1462 find_pval_gotos(item->u2.statements,lev+1);
1466 /* fields: item->u1.str == name of extension to catch
1467 item->u2.statements == pval list of statements in context body
1469 find_pval_gotos(item->u2.statements,lev+1);
1472 case PV_STATEMENTBLOCK:
1473 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
1475 find_pval_gotos(item->u1.list,lev+1);
1479 /* fields: item->u1.list == pval list of PV_WORD target names, up to 3, in order as given by user.
1480 item->u1.list->u1.str == where the data on a PV_WORD will always be.
1482 check_goto(item); /* THE WHOLE FUNCTION OF THIS ENTIRE ROUTINE!!!! */
1486 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
1488 for (p4=item->u1.list; p4; p4=p4->next) {
1489 /* for each context pointed to, find it, then find a context/label that matches the
1491 char *incl_context = p4->u1.str;
1492 /* find a matching context name */
1493 struct pval *that_context = find_context(incl_context);
1495 find_pval_gotos(that_context,lev+1); /* keep working up the includes */
1501 /* fields: item->u1.for_init == a string containing the initalizer
1502 item->u2.for_test == a string containing the loop test
1503 item->u3.for_inc == a string containing the loop increment
1505 item->u4.for_statements == a pval list of statements in the for ()
1507 find_pval_gotos(item->u4.for_statements,lev+1);
1511 /* fields: item->u1.str == the while conditional, as supplied by user
1513 item->u2.statements == a pval list of statements in the while ()
1515 find_pval_gotos(item->u2.statements,lev+1);
1519 /* fields: item->u1.str == the random number expression, as supplied by user
1521 item->u2.statements == a pval list of statements in the if ()
1522 item->u3.else_statements == a pval list of statements in the else
1524 fall thru to PV_IF */
1527 /* fields: item->u1.list == the time values, 4 of them, as PV_WORD structs in a list
1529 item->u2.statements == a pval list of statements in the if ()
1530 item->u3.else_statements == a pval list of statements in the else
1532 fall thru to PV_IF*/
1534 /* fields: item->u1.str == the if conditional, as supplied by user
1536 item->u2.statements == a pval list of statements in the if ()
1537 item->u3.else_statements == a pval list of statements in the else
1540 find_pval_gotos(item->u2.statements,lev+1);
1542 if (item->u3.else_statements) {
1543 find_pval_gotos(item->u3.else_statements,lev+1);
1548 /* fields: item->u1.str == the switch expression
1550 item->u2.statements == a pval list of statements in the switch,
1551 (will be case statements, most likely!)
1553 find_pval_gotos(item->u3.else_statements,lev+1);
1557 /* fields: item->u1.str == the extension name, label, whatever it's called
1559 item->u2.statements == a pval list of statements in the extension
1560 item->u3.hints == a char * hint argument
1561 item->u4.regexten == an int boolean. non-zero says that regexten was specified
1564 find_pval_gotos(item->u2.statements,lev+1);
1572 static void find_pval_gotos(pval *item,int lev)
1576 for (i=item; i; i=i->next) {
1578 find_pval_goto_item(i, lev);
1584 /* general purpose label finder */
1585 static struct pval *match_pval_item(pval *item)
1589 switch ( item->type ) {
1591 /* fields: item->u1.str == name of macro
1592 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
1593 item->u2.arglist->u1.str == argument
1594 item->u2.arglist->next == next arg
1596 item->u3.macro_statements == pval list of statements in macro body.
1598 /* printf(" matching in MACRO %s, match_context=%s; retoncontmtch=%d; \n", item->u1.str, match_context, return_on_context_match); */
1599 if (!strcmp(match_context,"*") || !strcmp(item->u1.str, match_context)) {
1601 /* printf("MACRO: match context is: %s\n", match_context); */
1603 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 */ {
1604 /* printf("Returning on matching macro %s\n", match_context); */
1609 if (!return_on_context_match) {
1610 /* printf("Descending into matching macro %s/%s\n", match_context, item->u1.str); */
1611 if ((x=match_pval(item->u3.macro_statements))) {
1612 /* printf("Responded with pval match %x\n", x); */
1617 /* printf("Skipping context/macro %s\n", item->u1.str); */
1623 /* fields: item->u1.str == name of context
1624 item->u2.statements == pval list of statements in context body
1625 item->u3.abstract == int 1 if an abstract keyword were present
1627 /* printf(" matching in CONTEXT\n"); */
1628 if (!strcmp(match_context,"*") || !strcmp(item->u1.str, match_context)) {
1629 if (return_on_context_match && !strcmp(item->u1.str, match_context)) {
1630 /* printf("Returning on matching context %s\n", match_context); */
1631 /* printf("non-CONTEXT: Responded with pval match %x\n", x); */
1635 if (!return_on_context_match ) {
1636 /* printf("Descending into matching context %s\n", match_context); */
1637 if ((x=match_pval(item->u2.statements))) /* if we're just searching for a context, don't bother descending into them */ {
1638 /* printf("CONTEXT: Responded with pval match %x\n", x); */
1643 /* printf("Skipping context/macro %s\n", item->u1.str); */
1648 /* fields: item->u1.str == value of case
1649 item->u2.statements == pval list of statements under the case
1651 /* printf(" matching in CASE\n"); */
1652 if ((x=match_pval(item->u2.statements))) {
1653 /* printf("CASE: Responded with pval match %x\n", x); */
1659 /* fields: item->u1.str == value of case
1660 item->u2.statements == pval list of statements under the case
1662 /* printf(" matching in PATTERN\n"); */
1663 if ((x=match_pval(item->u2.statements))) {
1664 /* printf("PATTERN: Responded with pval match %x\n", x); */
1671 item->u2.statements == pval list of statements under the case
1673 /* printf(" matching in DEFAULT\n"); */
1674 if ((x=match_pval(item->u2.statements))) {
1675 /* printf("DEFAULT: Responded with pval match %x\n", x); */
1681 /* fields: item->u1.str == name of extension to catch
1682 item->u2.statements == pval list of statements in context body
1684 /* printf(" matching in CATCH\n"); */
1685 if (!strcmp(match_exten,"*") || extension_matches(item, match_exten, item->u1.str) ) {
1686 /* printf("Descending into matching catch %s => %s\n", match_exten, item->u1.str); */
1687 if (strcmp(match_label,"1") == 0) {
1688 if (item->u2.statements) {
1689 struct pval *p5 = item->u2.statements;
1690 while (p5 && p5->type == PV_LABEL) /* find the first non-label statement in this context. If it exists, there's a "1" */
1701 if ((x=match_pval(item->u2.statements))) {
1702 /* printf("CATCH: Responded with pval match %x\n", (unsigned int)x); */
1706 /* printf("Skipping catch %s\n", item->u1.str); */
1710 case PV_STATEMENTBLOCK:
1711 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
1713 /* printf(" matching in STATEMENTBLOCK\n"); */
1714 if ((x=match_pval(item->u1.list))) {
1715 /* printf("STATEMENTBLOCK: Responded with pval match %x\n", x); */
1721 /* fields: item->u1.str == label name
1723 /* printf("PV_LABEL %s (cont=%s, exten=%s\n",
1724 item->u1.str, current_context->u1.str, (current_extension?current_extension->u1.str:"<macro>"));*/
1727 if (!strcmp(match_label, item->u1.str)) {
1729 last_matched_label = item;
1733 if (!strcmp(match_label, item->u1.str)) {
1734 /* printf("LABEL: Responded with pval match %x\n", x); */
1741 /* fields: item->u1.for_init == a string containing the initalizer
1742 item->u2.for_test == a string containing the loop test
1743 item->u3.for_inc == a string containing the loop increment
1745 item->u4.for_statements == a pval list of statements in the for ()
1747 /* printf(" matching in FOR\n"); */
1748 if ((x=match_pval(item->u4.for_statements))) {
1749 /* printf("FOR: Responded with pval match %x\n", x);*/
1755 /* fields: item->u1.str == the while conditional, as supplied by user
1757 item->u2.statements == a pval list of statements in the while ()
1759 /* printf(" matching in WHILE\n"); */
1760 if ((x=match_pval(item->u2.statements))) {
1761 /* printf("WHILE: Responded with pval match %x\n", x); */
1767 /* fields: item->u1.str == the random number expression, as supplied by user
1769 item->u2.statements == a pval list of statements in the if ()
1770 item->u3.else_statements == a pval list of statements in the else
1772 fall thru to PV_IF */
1775 /* fields: item->u1.list == the time values, 4 of them, as PV_WORD structs in a list
1777 item->u2.statements == a pval list of statements in the if ()
1778 item->u3.else_statements == a pval list of statements in the else
1780 fall thru to PV_IF*/
1782 /* fields: item->u1.str == the if conditional, as supplied by user
1784 item->u2.statements == a pval list of statements in the if ()
1785 item->u3.else_statements == a pval list of statements in the else
1788 /* printf(" matching in IF/IFTIME/RANDOM\n"); */
1789 if ((x=match_pval(item->u2.statements))) {
1792 if (item->u3.else_statements) {
1793 if ((x=match_pval(item->u3.else_statements))) {
1794 /* printf("IF/IFTIME/RANDOM: Responded with pval match %x\n", x); */
1801 /* fields: item->u1.str == the switch expression
1803 item->u2.statements == a pval list of statements in the switch,
1804 (will be case statements, most likely!)
1806 /* printf(" matching in SWITCH\n"); */
1807 if ((x=match_pval(item->u2.statements))) {
1808 /* printf("SWITCH: Responded with pval match %x\n", x); */
1814 /* fields: item->u1.str == the extension name, label, whatever it's called
1816 item->u2.statements == a pval list of statements in the extension
1817 item->u3.hints == a char * hint argument
1818 item->u4.regexten == an int boolean. non-zero says that regexten was specified
1820 /* printf(" matching in EXTENSION\n"); */
1821 if (!strcmp(match_exten,"*") || extension_matches(item, match_exten, item->u1.str) ) {
1822 /* printf("Descending into matching exten %s => %s\n", match_exten, item->u1.str); */
1823 if (strcmp(match_label,"1") == 0) {
1824 if (item->u2.statements) {
1825 struct pval *p5 = item->u2.statements;
1826 while (p5 && p5->type == PV_LABEL) /* find the first non-label statement in this context. If it exists, there's a "1" */
1837 if ((x=match_pval(item->u2.statements))) {
1838 /* printf("EXTENSION: Responded with pval match %x\n", x); */
1842 /* printf("Skipping exten %s\n", item->u1.str); */
1846 /* printf(" matching in default = %d\n", item->type); */
1852 struct pval *match_pval(pval *item)
1856 for (i=item; i; i=i->next) {
1858 /* printf(" -- match pval: item %d\n", i->type); */
1860 if ((x = match_pval_item(i))) {
1861 /* printf("match_pval: returning x=%x\n", (int)x); */
1862 return x; /* cut the search short */
1869 int count_labels_in_current_context(char *label)
1873 return_on_context_match = 0;
1874 match_pval(current_context->u2.statements);
1880 struct pval *find_first_label_in_current_context(char *label, pval *curr_cont)
1882 /* printf(" --- Got args %s, %s\n", exten, label); */
1885 struct pval *startpt = ((curr_cont->type==PV_MACRO)?curr_cont->u3.macro_statements: curr_cont->u2.statements);
1888 return_on_context_match = 0;
1889 match_context = "*";
1891 match_label = label;
1893 ret = match_pval(curr_cont);
1897 /* the target of the goto could be in an included context!! Fancy that!! */
1898 /* look for includes in the current context */
1899 for (p3=startpt; p3; p3=p3->next) {
1900 if (p3->type == PV_INCLUDES) {
1902 for (p4=p3->u1.list; p4; p4=p4->next) {
1903 /* for each context pointed to, find it, then find a context/label that matches the
1905 char *incl_context = p4->u1.str;
1906 /* find a matching context name */
1907 struct pval *that_context = find_context(incl_context);
1910 x3 = find_first_label_in_current_context(label, that_context);
1921 struct pval *find_label_in_current_context(char *exten, char *label, pval *curr_cont)
1923 /* printf(" --- Got args %s, %s\n", exten, label); */
1926 struct pval *startpt;
1929 return_on_context_match = 0;
1930 match_context = "*";
1931 match_exten = exten;
1932 match_label = label;
1933 if (curr_cont->type == PV_MACRO)
1934 startpt = curr_cont->u3.macro_statements;
1936 startpt = curr_cont->u2.statements;
1938 ret = match_pval(startpt);
1942 /* the target of the goto could be in an included context!! Fancy that!! */
1943 /* look for includes in the current context */
1944 for (p3=startpt; p3; p3=p3->next) {
1945 if (p3->type == PV_INCLUDES) {
1947 for (p4=p3->u1.list; p4; p4=p4->next) {
1948 /* for each context pointed to, find it, then find a context/label that matches the
1950 char *incl_context = p4->u1.str;
1951 /* find a matching context name */
1952 struct pval *that_context = find_context(incl_context);
1955 x3 = find_label_in_current_context(exten, label, that_context);
1966 static struct pval *find_label_in_current_extension(const char *label, pval *curr_ext)
1968 /* printf(" --- Got args %s\n", label); */
1970 return_on_context_match = 0;
1971 match_context = "*";
1973 match_label = label;
1974 return match_pval(curr_ext);
1977 static struct pval *find_label_in_current_db(const char *context, const char *exten, const char *label)
1979 /* printf(" --- Got args %s, %s, %s\n", context, exten, label); */
1981 return_on_context_match = 0;
1983 match_context = context;
1984 match_exten = exten;
1985 match_label = label;
1987 return match_pval(current_db);
1991 struct pval *find_macro(char *name)
1993 return_on_context_match = 1;
1995 match_context = name;
1996 match_exten = "*"; /* don't really need to set these, shouldn't be reached */
1998 return match_pval(current_db);
2001 struct pval *find_context(char *name)
2003 return_on_context_match = 1;
2005 match_context = name;
2006 match_exten = "*"; /* don't really need to set these, shouldn't be reached */
2008 return match_pval(current_db);
2011 int is_float(char *arg )
2014 for (s=arg; *s; s++) {
2015 if (*s != '.' && (*s < '0' || *s > '9'))
2020 int is_int(char *arg )
2023 for (s=arg; *s; s++) {
2024 if (*s < '0' || *s > '9')
2029 int is_empty(char *arg)
2036 if (*arg != ' ' && *arg != '\t')
2044 int option_matches_j( struct argdesc *should, pval *is, struct argapp *app)
2046 struct argchoice *ac;
2049 switch (should->dtype) {
2050 case ARGD_OPTIONSET:
2051 if ( strstr(is->u1.str,"${") )
2052 return 0; /* no checking anything if there's a var reference in there! */
2054 opcop = ast_strdupa(is->u1.str);
2056 for (q=opcop;*q;q++) { /* erase the innards of X(innard) type arguments, so we don't get confused later */
2059 while (*p && *p != ')' )
2065 for (ac=app->opts; ac; ac=ac->next) {
2066 if (strlen(ac->name)>1 && strchr(ac->name,'(') == 0 && strcmp(ac->name,is->u1.str) == 0) /* multichar option, no parens, and a match? */
2069 for (ac=app->opts; ac; ac=ac->next) {
2070 if (strlen(ac->name)==1 || strchr(ac->name,'(')) {
2071 char *p = strchr(opcop,ac->name[0]); /* wipe out all matched options in the user-supplied string */
2073 if (p && *p == 'j') {
2074 ast_log(LOG_ERROR, "Error: file %s, line %d-%d: The j option in the %s application call is not appropriate for AEL!\n",
2075 is->filename, is->startline, is->endline, app->name);
2081 if (ac->name[1] == '(') {
2082 if (*(p+1) != '(') {
2083 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",
2084 is->filename, is->startline, is->endline, ac->name[0], app->name);
2091 for (q=opcop; *q; q++) {
2092 if ( *q != '+' && *q != '(' && *q != ')') {
2093 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",
2094 is->filename, is->startline, is->endline, *q, app->name);
2106 int option_matches( struct argdesc *should, pval *is, struct argapp *app)
2108 struct argchoice *ac;
2111 switch (should->dtype) {
2113 if (is_empty(is->u1.str) && should->type == ARGD_REQUIRED)
2115 if (is->u1.str && strlen(is->u1.str) > 0) /* most will match */
2120 if (is_int(is->u1.str))
2127 if (is_float(is->u1.str))
2134 if( !is->u1.str || strlen(is->u1.str) == 0 )
2135 return 1; /* a null arg in the call will match an enum, I guess! */
2136 for (ac=should->choices; ac; ac=ac->next) {
2137 if (strcmp(ac->name,is->u1.str) == 0)
2143 case ARGD_OPTIONSET:
2144 opcop = ast_strdupa(is->u1.str);
2146 for (ac=app->opts; ac; ac=ac->next) {
2147 if (strlen(ac->name)>1 && strchr(ac->name,'(') == 0 && strcmp(ac->name,is->u1.str) == 0) /* multichar option, no parens, and a match? */
2150 for (ac=app->opts; ac; ac=ac->next) {
2151 if (strlen(ac->name)==1 || strchr(ac->name,'(')) {
2152 char *p = strchr(opcop,ac->name[0]); /* wipe out all matched options in the user-supplied string */
2156 if (ac->name[1] == '(') {
2157 if (*(p+1) == '(') {
2159 while (*q && *q != ')') {
2171 return 1; /* matches anything */
2174 return 1; /* unless some for-sure match or non-match returns, then it must be close enough ... */
2178 int check_app_args(pval* appcall, pval *arglist, struct argapp *app)
2181 struct argdesc *ad = app->args;
2185 for (pa = arglist; pa; pa=pa->next) {
2187 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Extra argument %s not in application call to %s !\n",
2188 arglist->filename, arglist->startline, arglist->endline, pa->u1.str, app->name);
2192 /* find the first entry in the ad list that will match */
2194 if ( ad->dtype == ARGD_VARARG ) /* once we hit the VARARG, all bets are off. Discontinue the comparisons */
2197 z= option_matches( ad, pa, app);
2202 if (ad->type == ARGD_REQUIRED) {
2203 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
2204 arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
2208 } else if (z && ad->dtype == ARGD_OPTIONSET) {
2209 option_matches_j( ad, pa, app);
2215 /* any app nodes left, that are not optional? */
2216 for ( ; ad; ad=ad->next) {
2217 if (ad->type == ARGD_REQUIRED && ad->dtype != ARGD_VARARG) {
2220 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
2221 arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
2232 void check_switch_expr(pval *item, struct argapp *apps)
2235 /* get and clean the variable name */
2237 struct argapp *a,*a2;
2238 struct appsetvar *v,*v2;
2239 struct argchoice *c;
2243 while (p && *p && (*p == ' ' || *p == '\t' || *p == '$' || *p == '{' ) )
2246 buff1 = ast_strdupa(p);
2248 while (strlen(buff1) > 0 && ( buff1[strlen(buff1)-1] == '}' || buff1[strlen(buff1)-1] == ' ' || buff1[strlen(buff1)-1] == '\t'))
2249 buff1[strlen(buff1)-1] = 0;
2250 /* buff1 now contains the variable name */
2252 for (a=apps; a; a=a->next) {
2253 for (v=a->setvars;v;v=v->next) {
2254 if (strcmp(v->name,buff1) == 0) {
2262 /* we have a match, to a variable that has a set of determined values */
2267 /* first of all, does this switch have a default case ? */
2268 for (t=item->u2.statements; t; t=t->next) {
2269 if (t->type == PV_DEFAULT) {
2273 if (t->type == PV_PATTERN) {
2277 if (def || pat) /* nothing to check. All cases accounted for! */
2279 for (c=v->vals; c; c=c->next) {
2281 for (t=item->u2.statements; t; t=t->next) {
2282 if (t->type == PV_CASE || t->type == PV_PATTERN) {
2283 if (!strcmp(t->u1.str,c->name)) {
2290 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: switch with expression(%s) does not handle the case of %s !\n",
2291 item->filename, item->startline, item->endline, item->u1.str, c->name);
2295 /* next, is there an app call in the current exten, that would set this var? */
2297 t = current_extension->u2.statements;
2298 if ( t && t->type == PV_STATEMENTBLOCK )
2299 t = t->u1.statements;
2300 for (; t && t != item; t=t->next) {
2301 if (t->type == PV_APPLICATION_CALL) {
2302 /* find the application that matches the u1.str */
2303 for (a2=apps; a2; a2=a2->next) {
2304 if (strcasecmp(a2->name, t->u1.str)==0) {
2305 for (v2=a2->setvars; v2; v2=v2->next) {
2306 if (strcmp(v2->name, buff1) == 0) {
2307 /* found an app that sets the var */
2321 /* see if it sets the var */
2323 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",
2324 item->filename, item->startline, item->endline, item->u1.str);
2331 static void check_context_names(void)
2334 for (i=current_db; i; i=i->next) {
2335 if (i->type == PV_CONTEXT || i->type == PV_MACRO) {
2336 for (j=i->next; j; j=j->next) {
2337 if ( j->type == PV_CONTEXT || j->type == PV_MACRO ) {
2338 if ( !strcmp(i->u1.str, j->u1.str) )
2340 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: The context name (%s) is also declared in file %s, line %d-%d!\n",
2341 i->filename, i->startline, i->endline, i->u1.str, j->filename, j->startline, j->endline);
2350 static void check_abstract_reference(pval *abstract_context)
2353 /* find some context includes that reference this context */
2356 /* otherwise, print out a warning */
2357 for (i=current_db; i; i=i->next) {
2358 if (i->type == PV_CONTEXT) {
2359 for (j=i->u2. statements; j; j=j->next) {
2360 if ( j->type == PV_INCLUDES ) {
2362 for (p4=j->u1.list; p4; p4=p4->next) {
2363 /* for each context pointed to, find it, then find a context/label that matches the
2365 if ( !strcmp(p4->u1.str, abstract_context->u1.str) )
2366 return; /* found a match! */
2372 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",
2373 abstract_context->filename, abstract_context->startline, abstract_context->endline, abstract_context->u1.str);
2378 void check_pval_item(pval *item, struct argapp *apps, int in_globals)
2382 struct argapp *app, *found;
2384 struct pval *macro_def;
2385 struct pval *app_def;
2390 switch (item->type) {
2392 /* fields: item->u1.str == string associated with this (word).
2393 item->u2.arglist == pval list of 4 PV_WORD elements for time values (only in PV_INCLUDES) */
2397 /* fields: item->u1.str == name of macro
2398 item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
2399 item->u2.arglist->u1.str == argument
2400 item->u2.arglist->next == next arg
2402 item->u3.macro_statements == pval list of statements in macro body.
2404 in_abstract_context = 0;
2405 current_context = item;
2406 current_extension = 0;
2408 check_macro_returns(item);
2410 for (lp=item->u2.arglist; lp; lp=lp->next) {
2413 check_pval(item->u3.macro_statements, apps,in_globals);
2417 /* fields: item->u1.str == name of context
2418 item->u2.statements == pval list of statements in context body
2419 item->u3.abstract == int 1 if an abstract keyword were present
2421 current_context = item;
2422 current_extension = 0;
2423 if ( item->u3.abstract ) {
2424 in_abstract_context = 1;
2425 check_abstract_reference(item);
2427 in_abstract_context = 0;
2428 check_pval(item->u2.statements, apps,in_globals);
2432 /* fields: item->u1.str == name of macro to call
2433 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
2434 item->u2.arglist->u1.str == argument
2435 item->u2.arglist->next == next arg
2437 macro_def = find_macro(item->u1.str);
2439 /* here is a good place to check to see if the definition is in extensions.conf! */
2440 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: macro call to non-existent %s ! Hopefully it is present in extensions.conf! \n",
2441 item->filename, item->startline, item->endline, item->u1.str);
2443 } else if (macro_def->type != PV_MACRO) {
2444 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: macro call to %s references a context, not a macro!\n",
2445 item->filename, item->startline, item->endline, item->u1.str);
2448 /* macro_def is a MACRO, so do the args match in number? */
2452 for (lp=item->u2.arglist; lp; lp=lp->next) {
2455 for (lp=macro_def->u2.arglist; lp; lp=lp->next) {
2458 if (hereargs != thereargs ) {
2459 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",
2460 item->filename, item->startline, item->endline, item->u1.str, hereargs, thereargs);
2466 case PV_APPLICATION_CALL:
2467 /* fields: item->u1.str == name of application to call
2468 item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
2469 item->u2.arglist->u1.str == argument
2470 item->u2.arglist->next == next arg
2472 /* Need to check to see if the application is available! */
2473 app_def = find_context(item->u1.str);
2474 if (app_def && app_def->type == PV_MACRO) {
2475 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: application call to %s references an existing macro, but had no & preceding it!\n",
2476 item->filename, item->startline, item->endline, item->u1.str);
2479 if (strcasecmp(item->u1.str,"GotoIf") == 0
2480 || strcasecmp(item->u1.str,"GotoIfTime") == 0
2481 || strcasecmp(item->u1.str,"while") == 0
2482 || strcasecmp(item->u1.str,"endwhile") == 0
2483 || strcasecmp(item->u1.str,"random") == 0
2484 || strcasecmp(item->u1.str,"gosub") == 0
2485 || strcasecmp(item->u1.str,"return") == 0
2486 || strcasecmp(item->u1.str,"gosubif") == 0
2487 || strcasecmp(item->u1.str,"continuewhile") == 0
2488 || strcasecmp(item->u1.str,"endwhile") == 0
2489 || strcasecmp(item->u1.str,"execif") == 0
2490 || strcasecmp(item->u1.str,"execiftime") == 0
2491 || strcasecmp(item->u1.str,"exitwhile") == 0
2492 || strcasecmp(item->u1.str,"goto") == 0
2493 || strcasecmp(item->u1.str,"macro") == 0
2494 || strcasecmp(item->u1.str,"macroexclusive") == 0
2495 || strcasecmp(item->u1.str,"macroif") == 0
2496 || strcasecmp(item->u1.str,"stackpop") == 0
2497 || strcasecmp(item->u1.str,"execIf") == 0 ) {
2498 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",
2499 item->filename, item->startline, item->endline, item->u1.str);
2502 if (strcasecmp(item->u1.str,"macroexit") == 0) {
2503 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: I am converting the MacroExit call here to a return statement.\n",
2504 item->filename, item->startline, item->endline);
2505 item->type = PV_RETURN;
2512 for (app=apps; app; app=app->next) {
2513 if (strcasecmp(app->name, item->u1.str) == 0) {
2519 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: application call to %s not listed in applist database!\n",
2520 item->filename, item->startline, item->endline, item->u1.str);
2523 check_app_args(item, item->u2.arglist, app);
2528 /* fields: item->u1.str == value of case
2529 item->u2.statements == pval list of statements under the case
2531 /* Make sure sequence of statements under case is terminated with goto, return, or break */
2532 /* find the last statement */
2533 check_pval(item->u2.statements, apps,in_globals);
2537 /* fields: item->u1.str == value of case
2538 item->u2.statements == pval list of statements under the case
2540 /* Make sure sequence of statements under case is terminated with goto, return, or break */
2541 /* find the last statement */
2543 check_pval(item->u2.statements, apps,in_globals);
2548 item->u2.statements == pval list of statements under the case
2551 check_pval(item->u2.statements, apps,in_globals);
2555 /* fields: item->u1.str == name of extension to catch
2556 item->u2.statements == pval list of statements in context body
2558 check_pval(item->u2.statements, apps,in_globals);
2562 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
2564 check_pval(item->u1.list, apps,in_globals);
2568 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
2570 check_pval(item->u1.list, apps,in_globals);
2574 /* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
2576 check_pval(item->u1.list, apps,in_globals);
2577 check_includes(item);
2578 for (lp=item->u1.list; lp; lp=lp->next){
2579 char *incl_context = lp->u1.str;
2580 struct pval *that_context = find_context(incl_context);
2582 if ( lp->u2.arglist ) {
2583 check_timerange(lp->u2.arglist);
2584 check_dow(lp->u2.arglist->next);
2585 check_day(lp->u2.arglist->next->next);
2586 check_month(lp->u2.arglist->next->next->next);
2590 find_pval_gotos(that_context->u2.statements,0);
2596 case PV_STATEMENTBLOCK:
2597 /* fields: item->u1.list == pval list of statements in block, one per entry in the list
2599 check_pval(item->u1.list, apps,in_globals);
2603 /* fields: item->u1.str == variable name
2604 item->u2.val == variable value to assign
2606 /* the RHS of a vardec is encapsulated in a $[] expr. Is it legal? */
2607 if( !in_globals ) { /* don't check stuff inside the globals context; no wrapping in $[ ] there... */
2608 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);
2609 ast_expr_register_extra_error_info(errmsg);
2610 ast_expr(item->u2.val, expr_output, sizeof(expr_output));
2611 ast_expr_clear_extra_error_info();
2612 if ( strpbrk(item->u2.val,"~!-+<>=*/&^") && !strstr(item->u2.val,"${") ) {
2613 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2614 item->filename, item->startline, item->endline, item->u2.val);
2617 check_expr2_input(item,item->u2.val);
2622 /* fields: item->u1.list == pval list of PV_WORD target names, up to 3, in order as given by user.
2623 item->u1.list->u1.str == where the data on a PV_WORD will always be.
2625 /* don't check goto's in abstract contexts */
2626 if ( in_abstract_context )
2633 /* fields: item->u1.str == label name
2635 if ( strspn(item->u1.str, "0123456789") == strlen(item->u1.str) ) {
2636 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: label '%s' is numeric, this is bad practice!\n",
2637 item->filename, item->startline, item->endline, item->u1.str);
2645 /* fields: item->u1.for_init == a string containing the initalizer
2646 item->u2.for_test == a string containing the loop test
2647 item->u3.for_inc == a string containing the loop increment
2649 item->u4.for_statements == a pval list of statements in the for ()
2651 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);
2652 ast_expr_register_extra_error_info(errmsg);
2654 strp = strchr(item->u1.for_init, '=');
2656 ast_expr(strp+1, expr_output, sizeof(expr_output));
2658 ast_expr(item->u2.for_test, expr_output, sizeof(expr_output));
2659 strp = strchr(item->u3.for_inc, '=');
2661 ast_expr(strp+1, expr_output, sizeof(expr_output));
2663 if ( strpbrk(item->u2.for_test,"~!-+<>=*/&^") && !strstr(item->u2.for_test,"${") ) {
2664 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2665 item->filename, item->startline, item->endline, item->u2.for_test);
2668 if ( strpbrk(item->u3.for_inc,"~!-+<>=*/&^") && !strstr(item->u3.for_inc,"${") ) {
2669 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2670 item->filename, item->startline, item->endline, item->u3.for_inc);
2673 check_expr2_input(item,item->u2.for_test);
2674 check_expr2_input(item,item->u3.for_inc);
2676 ast_expr_clear_extra_error_info();
2677 check_pval(item->u4.for_statements, apps,in_globals);
2681 /* fields: item->u1.str == the while conditional, as supplied by user
2683 item->u2.statements == a pval list of statements in the while ()
2685 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, while expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2686 ast_expr_register_extra_error_info(errmsg);
2687 ast_expr(item->u1.str, expr_output, sizeof(expr_output));
2688 ast_expr_clear_extra_error_info();
2689 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
2690 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
2691 item->filename, item->startline, item->endline, item->u1.str);
2694 check_expr2_input(item,item->u1.str);
2695 check_pval(item->u2.statements, apps,in_globals);
2712 check_continue(item);
2716 /* fields: item->u1.str == the random number expression, as supplied by user
2718 item->u2.statements == a pval list of statements in the if ()
2719 item->u3.else_statements == a pval list of statements in the else
2722 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, random expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2723 ast_expr_register_extra_error_info(errmsg);
2724 ast_expr(item->u1.str, expr_output, sizeof(expr_output));
2725 ast_expr_clear_extra_error_info();
2726 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
2727 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: random expression '%s' has operators, but no variables. Interesting...\n",
2728 item->filename, item->startline, item->endline, item->u1.str);
2731 check_expr2_input(item,item->u1.str);
2732 check_pval(item->u2.statements, apps,in_globals);
2733 if (item->u3.else_statements) {
2734 check_pval(item->u3.else_statements, apps,in_globals);
2739 /* fields: item->u1.list == the if time values, 4 of them, each in PV_WORD, linked list
2741 item->u2.statements == a pval list of statements in the if ()
2742 item->u3.else_statements == a pval list of statements in the else
2745 if ( item->u2.arglist ) {
2746 check_timerange(item->u1.list);
2747 check_dow(item->u1.list->next);
2748 check_day(item->u1.list->next->next);
2749 check_month(item->u1.list->next->next->next);
2752 check_pval(item->u2.statements, apps,in_globals);
2753 if (item->u3.else_statements) {
2754 check_pval(item->u3.else_statements, apps,in_globals);
2759 /* fields: item->u1.str == the if conditional, as supplied by user
2761 item->u2.statements == a pval list of statements in the if ()
2762 item->u3.else_statements == a pval list of statements in the else
2765 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, if expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2766 ast_expr_register_extra_error_info(errmsg);
2767 ast_expr(item->u1.str, expr_output, sizeof(expr_output));
2768 ast_expr_clear_extra_error_info();
2769 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
2770 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression '%s' has operators, but no variables. Interesting...\n",
2771 item->filename, item->startline, item->endline, item->u1.str);
2774 check_expr2_input(item,item->u1.str);
2775 check_pval(item->u2.statements, apps,in_globals);
2776 if (item->u3.else_statements) {
2777 check_pval(item->u3.else_statements, apps,in_globals);
2782 /* fields: item->u1.str == the switch expression
2784 item->u2.statements == a pval list of statements in the switch,
2785 (will be case statements, most likely!)
2787 /* we can check the switch expression, see if it matches any of the app variables...
2788 if it does, then, are all the possible cases accounted for? */
2789 check_switch_expr(item, apps);
2790 check_pval(item->u2.statements, apps,in_globals);
2794 /* fields: item->u1.str == the extension name, label, whatever it's called
2796 item->u2.statements == a pval list of statements in the extension
2797 item->u3.hints == a char * hint argument
2798 item->u4.regexten == an int boolean. non-zero says that regexten was specified
2800 current_extension = item ;
2802 check_pval(item->u2.statements, apps,in_globals);
2806 /* fields: item->u1.str == the ignorepat data
2811 /* fields: item->u1.statements == pval list of statements, usually vardecs
2813 in_abstract_context = 0;
2814 check_pval(item->u1.statements, apps, 1);
2821 void check_pval(pval *item, struct argapp *apps, int in_globals)
2826 1. Do goto's point to actual labels?
2827 2. Do macro calls reference a macro?
2828 3. Does the number of macro args match the definition?
2829 4. Is a macro call missing its & at the front?
2830 5. Application calls-- we could check syntax for existing applications,
2831 but I need some some sort of universal description bnf for a general
2832 sort of method for checking arguments, in number, maybe even type, at least.
2833 Don't want to hand code checks for hundreds of applications.