00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "asterisk.h"
00026
00027 #if !defined(STANDALONE_AEL)
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00029 #endif
00030
00031 #include <sys/types.h>
00032 #include <stdlib.h>
00033 #include <unistd.h>
00034 #include <stdio.h>
00035 #include <string.h>
00036 #include <ctype.h>
00037 #include <errno.h>
00038 #include <regex.h>
00039 #include <sys/stat.h>
00040
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/config.h"
00043 #include "asterisk/module.h"
00044 #include "asterisk/logger.h"
00045 #include "asterisk/cli.h"
00046 #include "asterisk/app.h"
00047 #include "asterisk/callerid.h"
00048 #include "asterisk/ael_structs.h"
00049 #ifdef AAL_ARGCHECK
00050 #include "asterisk/argdesc.h"
00051 #endif
00052
00053 static char expr_output[2096];
00054
00055
00056
00057 #define DEBUG_READ (1 << 0)
00058 #define DEBUG_TOKENS (1 << 1)
00059 #define DEBUG_MACROS (1 << 2)
00060 #define DEBUG_CONTEXTS (1 << 3)
00061
00062 static char *config = "extensions.ael";
00063 static char *registrar = "pbx_ael";
00064 static int pbx_load_module(void);
00065
00066 static int errs, warns;
00067 static int notes;
00068
00069 #ifndef AAL_ARGCHECK
00070
00071
00072
00073
00074
00075
00076 struct argapp
00077 {
00078 struct argapp *next;
00079 };
00080
00081 #endif
00082
00083 #ifdef AAL_ARGCHECK
00084 int option_matches_j( struct argdesc *should, pval *is, struct argapp *app);
00085 int option_matches( struct argdesc *should, pval *is, struct argapp *app);
00086 int ael_is_funcname(char *name);
00087 #endif
00088
00089 int check_app_args(pval *appcall, pval *arglist, struct argapp *app);
00090 void check_pval(pval *item, struct argapp *apps, int in_globals);
00091 void check_pval_item(pval *item, struct argapp *apps, int in_globals);
00092 void check_switch_expr(pval *item, struct argapp *apps);
00093 void ast_expr_register_extra_error_info(char *errmsg);
00094 void ast_expr_clear_extra_error_info(void);
00095 int ast_expr(char *expr, char *buf, int length);
00096 struct pval *find_macro(char *name);
00097 struct pval *find_context(char *name);
00098 struct pval *find_context(char *name);
00099 struct pval *find_macro(char *name);
00100 struct ael_priority *new_prio(void);
00101 struct ael_extension *new_exten(void);
00102 void linkprio(struct ael_extension *exten, struct ael_priority *prio, struct ael_extension *mother_exten);
00103 void destroy_extensions(struct ael_extension *exten);
00104 static void linkexten(struct ael_extension *exten, struct ael_extension *add);
00105 static void gen_prios(struct ael_extension *exten, char *label, pval *statement, struct ael_extension *mother_exten, struct ast_context *context );
00106 void set_priorities(struct ael_extension *exten);
00107 void add_extensions(struct ael_extension *exten);
00108 void ast_compile_ael2(struct ast_context **local_contexts, struct pval *root);
00109 void destroy_pval(pval *item);
00110 void destroy_pval_item(pval *item);
00111 int is_float(char *arg );
00112 int is_int(char *arg );
00113 int is_empty(char *arg);
00114 static pval *current_db=0;
00115 static pval *current_context=0;
00116 static pval *current_extension=0;
00117
00118 static const char *match_context;
00119 static const char *match_exten;
00120 static const char *match_label;
00121 static int in_abstract_context;
00122 static int count_labels;
00123 static int label_count;
00124 static int return_on_context_match;
00125 static pval *last_matched_label;
00126 struct pval *match_pval(pval *item);
00127 static void check_timerange(pval *p);
00128 static void check_dow(pval *DOW);
00129 static void check_day(pval *DAY);
00130 static void check_month(pval *MON);
00131 static void check_expr2_input(pval *expr, char *str);
00132 static int extension_matches(pval *here, const char *exten, const char *pattern);
00133 static void check_goto(pval *item);
00134 static void find_pval_goto_item(pval *item, int lev);
00135 static void find_pval_gotos(pval *item, int lev);
00136
00137 static struct pval *find_label_in_current_context(char *exten, char *label, pval *curr_cont);
00138 static struct pval *find_first_label_in_current_context(char *label, pval *curr_cont);
00139 static void print_pval_list(FILE *fin, pval *item, int depth);
00140
00141 static struct pval *find_label_in_current_extension(const char *label, pval *curr_ext);
00142 static struct pval *find_label_in_current_db(const char *context, const char *exten, const char *label);
00143 static pval *get_goto_target(pval *item);
00144 static int label_inside_case(pval *label);
00145 static void attach_exten(struct ael_extension **list, struct ael_extension *newmem);
00146 static void fix_gotos_in_extensions(struct ael_extension *exten);
00147 static pval *get_extension_or_contxt(pval *p);
00148 static pval *get_contxt(pval *p);
00149 static void remove_spaces_before_equals(char *str);
00150 static void substitute_commas(char *str);
00151
00152
00153 static void substitute_commas(char *str)
00154 {
00155 char *p = str;
00156
00157 while (p && *p)
00158 {
00159 if (*p == ',' && ((p != str && *(p-1) != '\\')
00160 || p == str))
00161 *p = '|';
00162 if (*p == '\\' && *(p+1) == ',') {
00163 char *q = p;
00164 while (*q) {
00165 *q = *(q+1);
00166 q++;
00167 }
00168 }
00169 p++;
00170 }
00171 }
00172
00173
00174
00175
00176 static void print_pval(FILE *fin, pval *item, int depth)
00177 {
00178 int i;
00179 pval *lp;
00180
00181 for (i=0; i<depth; i++) {
00182 fprintf(fin, "\t");
00183 }
00184
00185 switch ( item->type ) {
00186 case PV_WORD:
00187 fprintf(fin,"%s;\n", item->u1.str);
00188 break;
00189
00190 case PV_MACRO:
00191 fprintf(fin,"macro %s(", item->u1.str);
00192 for (lp=item->u2.arglist; lp; lp=lp->next) {
00193 if (lp != item->u2.arglist )
00194 fprintf(fin,", ");
00195 fprintf(fin,"%s", lp->u1.str);
00196 }
00197 fprintf(fin,") {\n");
00198 print_pval_list(fin,item->u3.macro_statements,depth+1);
00199 for (i=0; i<depth; i++) {
00200 fprintf(fin,"\t");
00201 }
00202 fprintf(fin,"};\n\n");
00203 break;
00204
00205 case PV_CONTEXT:
00206 if ( item->u3.abstract )
00207 fprintf(fin,"abstract context %s {\n", item->u1.str);
00208 else
00209 fprintf(fin,"context %s {\n", item->u1.str);
00210 print_pval_list(fin,item->u2.statements,depth+1);
00211 for (i=0; i<depth; i++) {
00212 fprintf(fin,"\t");
00213 }
00214 fprintf(fin,"};\n\n");
00215 break;
00216
00217 case PV_MACRO_CALL:
00218 fprintf(fin,"&%s(", item->u1.str);
00219 for (lp=item->u2.arglist; lp; lp=lp->next) {
00220 if ( lp != item->u2.arglist )
00221 fprintf(fin,", ");
00222 fprintf(fin,"%s", lp->u1.str);
00223 }
00224 fprintf(fin,");\n");
00225 break;
00226
00227 case PV_APPLICATION_CALL:
00228 fprintf(fin,"%s(", item->u1.str);
00229 for (lp=item->u2.arglist; lp; lp=lp->next) {
00230 if ( lp != item->u2.arglist )
00231 fprintf(fin,",");
00232 fprintf(fin,"%s", lp->u1.str);
00233 }
00234 fprintf(fin,");\n");
00235 break;
00236
00237 case PV_CASE:
00238 fprintf(fin,"case %s:\n", item->u1.str);
00239 print_pval_list(fin,item->u2.statements, depth+1);
00240 break;
00241
00242 case PV_PATTERN:
00243 fprintf(fin,"pattern %s:\n", item->u1.str);
00244 print_pval_list(fin,item->u2.statements, depth+1);
00245 break;
00246
00247 case PV_DEFAULT:
00248 fprintf(fin,"default:\n");
00249 print_pval_list(fin,item->u2.statements, depth+1);
00250 break;
00251
00252 case PV_CATCH:
00253 fprintf(fin,"catch %s {\n", item->u1.str);
00254 print_pval_list(fin,item->u2.statements, depth+1);
00255 for (i=0; i<depth; i++) {
00256 fprintf(fin,"\t");
00257 }
00258 fprintf(fin,"};\n");
00259 break;
00260
00261 case PV_SWITCHES:
00262 fprintf(fin,"switches {\n");
00263 print_pval_list(fin,item->u1.list,depth+1);
00264 for (i=0; i<depth; i++) {
00265 fprintf(fin,"\t");
00266 }
00267 fprintf(fin,"};\n");
00268 break;
00269
00270 case PV_ESWITCHES:
00271 fprintf(fin,"eswitches {\n");
00272 print_pval_list(fin,item->u1.list,depth+1);
00273 for (i=0; i<depth; i++) {
00274 fprintf(fin,"\t");
00275 }
00276 fprintf(fin,"};\n");
00277 break;
00278
00279 case PV_INCLUDES:
00280 fprintf(fin,"includes {\n");
00281 for (lp=item->u1.list; lp; lp=lp->next) {
00282 for (i=0; i<depth+1; i++) {
00283 fprintf(fin,"\t");
00284 }
00285 fprintf(fin,"%s", lp->u1.str);
00286 if ( lp->u2.arglist )
00287 fprintf(fin,"|%s|%s|%s|%s",
00288 lp->u2.arglist->u1.str,
00289 lp->u2.arglist->next->u1.str,
00290 lp->u2.arglist->next->next->u1.str,
00291 lp->u2.arglist->next->next->next->u1.str
00292 );
00293 fprintf(fin,";\n");
00294 }
00295
00296 print_pval_list(fin,item->u1.list,depth+1);
00297 for (i=0; i<depth; i++) {
00298 fprintf(fin,"\t");
00299 }
00300 fprintf(fin,"};\n");
00301 break;
00302
00303 case PV_STATEMENTBLOCK:
00304 fprintf(fin,"{\n");
00305 print_pval_list(fin,item->u1.list, depth+1);
00306 for (i=0; i<depth; i++) {
00307 fprintf(fin,"\t");
00308 }
00309 fprintf(fin,"};\n");
00310 break;
00311
00312 case PV_VARDEC:
00313 fprintf(fin,"%s=%s;\n", item->u1.str, item->u2.val);
00314 break;
00315
00316 case PV_GOTO:
00317 fprintf(fin,"goto %s", item->u1.list->u1.str);
00318 if ( item->u1.list->next )
00319 fprintf(fin,"|%s", item->u1.list->next->u1.str);
00320 if ( item->u1.list->next && item->u1.list->next->next )
00321 fprintf(fin,"|%s", item->u1.list->next->next->u1.str);
00322 fprintf(fin,"\n");
00323 break;
00324
00325 case PV_LABEL:
00326 fprintf(fin,"%s:\n", item->u1.str);
00327 break;
00328
00329 case PV_FOR:
00330 fprintf(fin,"for (%s; %s; %s)\n", item->u1.for_init, item->u2.for_test, item->u3.for_inc);
00331 print_pval_list(fin,item->u4.for_statements,depth+1);
00332 break;
00333
00334 case PV_WHILE:
00335 fprintf(fin,"while (%s)\n", item->u1.str);
00336 print_pval_list(fin,item->u2.statements,depth+1);
00337 break;
00338
00339 case PV_BREAK:
00340 fprintf(fin,"break;\n");
00341 break;
00342
00343 case PV_RETURN:
00344 fprintf(fin,"return;\n");
00345 break;
00346
00347 case PV_CONTINUE:
00348 fprintf(fin,"continue;\n");
00349 break;
00350
00351 case PV_RANDOM:
00352 case PV_IFTIME:
00353 case PV_IF:
00354 if ( item->type == PV_IFTIME ) {
00355
00356 fprintf(fin,"ifTime ( %s|%s|%s|%s )\n",
00357 item->u1.list->u1.str,
00358 item->u1.list->next->u1.str,
00359 item->u1.list->next->next->u1.str,
00360 item->u1.list->next->next->next->u1.str
00361 );
00362 } else if ( item->type == PV_RANDOM ) {
00363 fprintf(fin,"random ( %s )\n", item->u1.str );
00364 } else
00365 fprintf(fin,"if ( %s )\n", item->u1.str);
00366 if ( item->u2.statements && item->u2.statements->next ) {
00367 for (i=0; i<depth; i++) {
00368 fprintf(fin,"\t");
00369 }
00370 fprintf(fin,"{\n");
00371 print_pval_list(fin,item->u2.statements,depth+1);
00372 for (i=0; i<depth; i++) {
00373 fprintf(fin,"\t");
00374 }
00375 if ( item->u3.else_statements )
00376 fprintf(fin,"}\n");
00377 else
00378 fprintf(fin,"};\n");
00379 } else if (item->u2.statements ) {
00380 print_pval_list(fin,item->u2.statements,depth+1);
00381 } else {
00382 if (item->u3.else_statements )
00383 fprintf(fin, " {} ");
00384 else
00385 fprintf(fin, " {}; ");
00386 }
00387 if ( item->u3.else_statements ) {
00388 for (i=0; i<depth; i++) {
00389 fprintf(fin,"\t");
00390 }
00391 fprintf(fin,"else\n");
00392 print_pval_list(fin,item->u3.else_statements, depth);
00393 }
00394 break;
00395
00396 case PV_SWITCH:
00397 fprintf(fin,"switch( %s ) {\n", item->u1.str);
00398 print_pval_list(fin,item->u2.statements,depth+1);
00399 for (i=0; i<depth; i++) {
00400 fprintf(fin,"\t");
00401 }
00402 fprintf(fin,"}\n");
00403 break;
00404
00405 case PV_EXTENSION:
00406 if ( item->u4.regexten )
00407 fprintf(fin, "regexten ");
00408 if ( item->u3.hints )
00409 fprintf(fin,"hints(%s) ", item->u3.hints);
00410
00411 fprintf(fin,"%s => \n", item->u1.str);
00412 print_pval_list(fin,item->u2.statements,depth+1);
00413 break;
00414
00415 case PV_IGNOREPAT:
00416 fprintf(fin,"ignorepat => %s\n", item->u1.str);
00417 break;
00418
00419 case PV_GLOBALS:
00420 fprintf(fin,"globals {\n");
00421 print_pval_list(fin,item->u1.statements,depth+1);
00422 for (i=0; i<depth; i++) {
00423 fprintf(fin,"\t");
00424 }
00425 fprintf(fin,"}\n");
00426 break;
00427 }
00428 }
00429
00430 static void print_pval_list(FILE *fin, pval *item, int depth)
00431 {
00432 pval *i;
00433
00434 for (i=item; i; i=i->next) {
00435 print_pval(fin, i, depth);
00436 }
00437 }
00438
00439 #if 0
00440 static void ael2_print(char *fname, pval *tree)
00441 {
00442 FILE *fin = fopen(fname,"w");
00443 if ( !fin ) {
00444 ast_log(LOG_ERROR, "Couldn't open %s for writing.\n", fname);
00445 return;
00446 }
00447 print_pval_list(fin, tree, 0);
00448 fclose(fin);
00449 }
00450 #endif
00451
00452
00453
00454
00455 void traverse_pval_template(pval *item, int depth);
00456 void traverse_pval_item_template(pval *item, int depth);
00457
00458
00459 void traverse_pval_item_template(pval *item, int depth)
00460
00461 {
00462 pval *lp;
00463
00464 switch ( item->type ) {
00465 case PV_WORD:
00466
00467 break;
00468
00469 case PV_MACRO:
00470
00471
00472
00473
00474
00475
00476
00477 for (lp=item->u2.arglist; lp; lp=lp->next) {
00478
00479 }
00480 traverse_pval_item_template(item->u3.macro_statements,depth+1);
00481 break;
00482
00483 case PV_CONTEXT:
00484
00485
00486
00487
00488 traverse_pval_item_template(item->u2.statements,depth+1);
00489 break;
00490
00491 case PV_MACRO_CALL:
00492
00493
00494
00495
00496
00497 for (lp=item->u2.arglist; lp; lp=lp->next) {
00498 }
00499 break;
00500
00501 case PV_APPLICATION_CALL:
00502
00503
00504
00505
00506
00507 for (lp=item->u2.arglist; lp; lp=lp->next) {
00508 }
00509 break;
00510
00511 case PV_CASE:
00512
00513
00514
00515 traverse_pval_item_template(item->u2.statements,depth+1);
00516 break;
00517
00518 case PV_PATTERN:
00519
00520
00521
00522 traverse_pval_item_template(item->u2.statements,depth+1);
00523 break;
00524
00525 case PV_DEFAULT:
00526
00527
00528
00529 traverse_pval_item_template(item->u2.statements,depth+1);
00530 break;
00531
00532 case PV_CATCH:
00533
00534
00535
00536 traverse_pval_item_template(item->u2.statements,depth+1);
00537 break;
00538
00539 case PV_SWITCHES:
00540
00541
00542 traverse_pval_item_template(item->u1.list,depth+1);
00543 break;
00544
00545 case PV_ESWITCHES:
00546
00547
00548 traverse_pval_item_template(item->u1.list,depth+1);
00549 break;
00550
00551 case PV_INCLUDES:
00552
00553
00554
00555 traverse_pval_item_template(item->u1.list,depth+1);
00556 traverse_pval_item_template(item->u2.arglist,depth+1);
00557 break;
00558
00559 case PV_STATEMENTBLOCK:
00560
00561
00562 traverse_pval_item_template(item->u1.list,depth+1);
00563 break;
00564
00565 case PV_VARDEC:
00566
00567
00568
00569 break;
00570
00571 case PV_GOTO:
00572
00573
00574
00575
00576 if ( item->u1.list->next )
00577 ;
00578 if ( item->u1.list->next && item->u1.list->next->next )
00579 ;
00580
00581 break;
00582
00583 case PV_LABEL:
00584
00585
00586 break;
00587
00588 case PV_FOR:
00589
00590
00591
00592
00593
00594
00595 traverse_pval_item_template(item->u4.for_statements,depth+1);
00596 break;
00597
00598 case PV_WHILE:
00599
00600
00601
00602
00603 traverse_pval_item_template(item->u2.statements,depth+1);
00604 break;
00605
00606 case PV_BREAK:
00607
00608
00609 break;
00610
00611 case PV_RETURN:
00612
00613
00614 break;
00615
00616 case PV_CONTINUE:
00617
00618
00619 break;
00620
00621 case PV_IFTIME:
00622
00623
00624
00625
00626
00627
00628 traverse_pval_item_template(item->u2.statements,depth+1);
00629 if ( item->u3.else_statements ) {
00630 traverse_pval_item_template(item->u3.else_statements,depth+1);
00631 }
00632 break;
00633
00634 case PV_RANDOM:
00635
00636
00637
00638
00639
00640
00641 traverse_pval_item_template(item->u2.statements,depth+1);
00642 if ( item->u3.else_statements ) {
00643 traverse_pval_item_template(item->u3.else_statements,depth+1);
00644 }
00645 break;
00646
00647 case PV_IF:
00648
00649
00650
00651
00652
00653
00654 traverse_pval_item_template(item->u2.statements,depth+1);
00655 if ( item->u3.else_statements ) {
00656 traverse_pval_item_template(item->u3.else_statements,depth+1);
00657 }
00658 break;
00659
00660 case PV_SWITCH:
00661
00662
00663
00664
00665
00666 traverse_pval_item_template(item->u2.statements,depth+1);
00667 break;
00668
00669 case PV_EXTENSION:
00670
00671
00672
00673
00674
00675
00676 traverse_pval_item_template(item->u2.statements,depth+1);
00677 break;
00678
00679 case PV_IGNOREPAT:
00680
00681
00682 break;
00683
00684 case PV_GLOBALS:
00685
00686
00687 traverse_pval_item_template(item->u1.statements,depth+1);
00688 break;
00689 }
00690 }
00691
00692 void traverse_pval_template(pval *item, int depth)
00693
00694 {
00695 pval *i;
00696
00697 for (i=item; i; i=i->next) {
00698 traverse_pval_item_template(i, depth);
00699 }
00700 }
00701
00702
00703
00704
00705
00706
00707
00708
00709 static int extension_matches(pval *here, const char *exten, const char *pattern)
00710 {
00711 int err1;
00712 regex_t preg;
00713
00714
00715 if( strcmp(pattern,exten) == 0 )
00716 return 1;
00717
00718 if ( pattern[0] == '_' ) {
00719 char reg1[2000];
00720 const char *p;
00721 char *r = reg1;
00722
00723 if ( strlen(pattern)*5 >= 2000 ) {
00724 ast_log(LOG_ERROR,"Error: The pattern %s is way too big. Pattern matching cancelled.\n",
00725 pattern);
00726 return 0;
00727 }
00728
00729 *r++ = '^';
00730 *r++ = '_';
00731 *r++ = '?';
00732 for (p=pattern+1; *p; p++) {
00733 switch ( *p ) {
00734 case 'X':
00735 *r++ = '[';
00736 *r++ = '0';
00737 *r++ = '-';
00738 *r++ = '9';
00739 *r++ = 'X';
00740 *r++ = ']';
00741 break;
00742
00743 case 'Z':
00744 *r++ = '[';
00745 *r++ = '1';
00746 *r++ = '-';
00747 *r++ = '9';
00748 *r++ = 'Z';
00749 *r++ = ']';
00750 break;
00751
00752 case 'N':
00753 *r++ = '[';
00754 *r++ = '2';
00755 *r++ = '-';
00756 *r++ = '9';
00757 *r++ = 'N';
00758 *r++ = ']';
00759 break;
00760
00761 case '[':
00762 while ( *p && *p != ']' ) {
00763 *r++ = *p++;
00764 }
00765 if ( *p != ']') {
00766 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The extension pattern '%s' is missing a closing bracket \n",
00767 here->filename, here->startline, here->endline, pattern);
00768 }
00769 break;
00770
00771 case '.':
00772 case '!':
00773 *r++ = '.';
00774 *r++ = '*';
00775 break;
00776 case '*':
00777 *r++ = '\\';
00778 *r++ = '*';
00779 break;
00780 default:
00781 *r++ = *p;
00782 break;
00783
00784 }
00785 }
00786 *r++ = '$';
00787 *r++ = *p++;
00788 err1 = regcomp(&preg, reg1, REG_NOSUB|REG_EXTENDED);
00789 if ( err1 ) {
00790 char errmess[500];
00791 regerror(err1,&preg,errmess,sizeof(errmess));
00792 regfree(&preg);
00793 ast_log(LOG_WARNING, "Regcomp of %s failed, error code %d\n",
00794 reg1, err1);
00795 return 0;
00796 }
00797 err1 = regexec(&preg, exten, 0, 0, 0);
00798 regfree(&preg);
00799
00800 if ( err1 ) {
00801
00802
00803 return 0;
00804 } else {
00805
00806
00807 return 1;
00808 }
00809
00810
00811 } else {
00812 if ( strcmp(exten,pattern) == 0 ) {
00813 return 1;
00814 } else
00815 return 0;
00816 }
00817 }
00818
00819
00820 static void check_expr2_input(pval *expr, char *str)
00821 {
00822 int spaces = strspn(str,"\t \n");
00823 if ( !strncmp(str+spaces,"$[",2) ) {
00824 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The expression '%s' is redundantly wrapped in '$[ ]'. \n",
00825 expr->filename, expr->startline, expr->endline, str);
00826 warns++;
00827 }
00828 }
00829
00830 static void check_includes(pval *includes)
00831 {
00832 struct pval *p4;
00833 for (p4=includes->u1.list; p4; p4=p4->next) {
00834
00835
00836 char *incl_context = p4->u1.str;
00837
00838 struct pval *that_other_context = find_context(incl_context);
00839 if (!that_other_context && strcmp(incl_context, "parkedcalls") != 0) {
00840 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The included context '%s' cannot be found.\n\
00841 (You may ignore this warning if '%s' exists in extensions.conf, or is created by another module. I cannot check for those.)\n",
00842 includes->filename, includes->startline, includes->endline, incl_context, incl_context);
00843 warns++;
00844 }
00845 }
00846 }
00847
00848
00849 static void check_timerange(pval *p)
00850 {
00851 char *times;
00852 char *e;
00853 int s1, s2;
00854 int e1, e2;
00855
00856 times = ast_strdupa(p->u1.str);
00857
00858
00859 if (ast_strlen_zero(times) || !strcmp(times, "*")) {
00860 return;
00861 }
00862
00863 e = strchr(times, '-');
00864 if (!e) {
00865 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",
00866 p->filename, p->startline, p->endline, times);
00867 warns++;
00868 return;
00869 }
00870 *e = '\0';
00871 e++;
00872 while (*e && !isdigit(*e))
00873 e++;
00874 if (!*e) {
00875 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The time range format (%s) is missing the end time!\n",
00876 p->filename, p->startline, p->endline, p->u1.str);
00877 warns++;
00878 }
00879 if (sscanf(times, "%d:%d", &s1, &s2) != 2) {
00880 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start time (%s) isn't quite right!\n",
00881 p->filename, p->startline, p->endline, times);
00882 warns++;
00883 }
00884 if (sscanf(e, "%d:%d", &e1, &e2) != 2) {
00885 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end time (%s) isn't quite right!\n",
00886 p->filename, p->startline, p->endline, times);
00887 warns++;
00888 }
00889
00890 s1 = s1 * 30 + s2/2;
00891 if ((s1 < 0) || (s1 >= 24*30)) {
00892 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start time (%s) is out of range!\n",
00893 p->filename, p->startline, p->endline, times);
00894 warns++;
00895 }
00896 e1 = e1 * 30 + e2/2;
00897 if ((e1 < 0) || (e1 >= 24*30)) {
00898 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end time (%s) is out of range!\n",
00899 p->filename, p->startline, p->endline, e);
00900 warns++;
00901 }
00902 return;
00903 }
00904
00905 static char *days[] =
00906 {
00907 "sun",
00908 "mon",
00909 "tue",
00910 "wed",
00911 "thu",
00912 "fri",
00913 "sat",
00914 };
00915
00916
00917 static void check_dow(pval *DOW)
00918 {
00919 char *dow;
00920 char *c;
00921
00922 int s, e;
00923
00924 dow = ast_strdupa(DOW->u1.str);
00925
00926
00927 if (ast_strlen_zero(dow) || !strcmp(dow, "*"))
00928 return;
00929
00930 c = strchr(dow, '-');
00931 if (c) {
00932 *c = '\0';
00933 c++;
00934 } else
00935 c = NULL;
00936
00937 s = 0;
00938 while ((s < 7) && strcasecmp(dow, days[s])) s++;
00939 if (s >= 7) {
00940 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",
00941 DOW->filename, DOW->startline, DOW->endline, dow);
00942 warns++;
00943 }
00944 if (c) {
00945 e = 0;
00946 while ((e < 7) && strcasecmp(c, days[e])) e++;
00947 if (e >= 7) {
00948 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",
00949 DOW->filename, DOW->startline, DOW->endline, c);
00950 warns++;
00951 }
00952 } else
00953 e = s;
00954 }
00955
00956 static void check_day(pval *DAY)
00957 {
00958 char *day;
00959 char *c;
00960
00961 int s, e;
00962
00963 day = ast_strdupa(DAY->u1.str);
00964
00965
00966 if (ast_strlen_zero(day) || !strcmp(day, "*")) {
00967 return;
00968 }
00969
00970 c = strchr(day, '-');
00971 if (c) {
00972 *c = '\0';
00973 c++;
00974 }
00975
00976 if (sscanf(day, "%d", &s) != 1) {
00977 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start day of month (%s) must be a number!\n",
00978 DAY->filename, DAY->startline, DAY->endline, day);
00979 warns++;
00980 }
00981 else if ((s < 1) || (s > 31)) {
00982 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",
00983 DAY->filename, DAY->startline, DAY->endline, day);
00984 warns++;
00985 }
00986 s--;
00987 if (c) {
00988 if (sscanf(c, "%d", &e) != 1) {
00989 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day of month (%s) must be a number!\n",
00990 DAY->filename, DAY->startline, DAY->endline, c);
00991 warns++;
00992 }
00993 else if ((e < 1) || (e > 31)) {
00994 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",
00995 DAY->filename, DAY->startline, DAY->endline, day);
00996 warns++;
00997 }
00998 e--;
00999 } else
01000 e = s;
01001 }
01002
01003 static char *months[] =
01004 {
01005 "jan",
01006 "feb",
01007 "mar",
01008 "apr",
01009 "may",
01010 "jun",
01011 "jul",
01012 "aug",
01013 "sep",
01014 "oct",
01015 "nov",
01016 "dec",
01017 };
01018
01019 static void check_month(pval *MON)
01020 {
01021 char *mon;
01022 char *c;
01023
01024 int s, e;
01025
01026 mon = ast_strdupa(MON->u1.str);
01027
01028
01029 if (ast_strlen_zero(mon) || !strcmp(mon, "*"))
01030 return ;
01031
01032 c = strchr(mon, '-');
01033 if (c) {
01034 *c = '\0';
01035 c++;
01036 }
01037
01038 s = 0;
01039 while ((s < 12) && strcasecmp(mon, months[s])) s++;
01040 if (s >= 12) {
01041 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n",
01042 MON->filename, MON->startline, MON->endline, mon);
01043 warns++;
01044 }
01045 if (c) {
01046 e = 0;
01047 while ((e < 12) && strcasecmp(mon, months[e])) e++;
01048 if (e >= 12) {
01049 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n",
01050 MON->filename, MON->startline, MON->endline, c);
01051 warns++;
01052 }
01053 } else
01054 e = s;
01055 }
01056
01057 static int check_break(pval *item)
01058 {
01059 pval *p = item;
01060
01061 while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) {
01062
01063
01064 if( p->type == PV_CASE || p->type == PV_DEFAULT || p->type == PV_PATTERN
01065 || p->type == PV_WHILE || p->type == PV_FOR ) {
01066 return 1;
01067 }
01068 p = p->dad;
01069 }
01070 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'break' not in switch, for, or while statement!\n",
01071 item->filename, item->startline, item->endline);
01072 errs++;
01073
01074 return 0;
01075 }
01076
01077 static int check_continue(pval *item)
01078 {
01079 pval *p = item;
01080
01081 while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) {
01082
01083
01084 if( p->type == PV_WHILE || p->type == PV_FOR ) {
01085 return 1;
01086 }
01087 p = p->dad;
01088 }
01089 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'continue' not in 'for' or 'while' statement!\n",
01090 item->filename, item->startline, item->endline);
01091 errs++;
01092
01093 return 0;
01094 }
01095
01096
01097
01098
01099 static void check_label(pval *item)
01100 {
01101
01102
01103
01104 struct pval *curr;
01105 struct pval *x;
01106
01107
01108 if( !current_extension )
01109 curr = current_context;
01110 else
01111 curr = current_extension;
01112
01113 x = find_first_label_in_current_context((char *)item->u1.str, curr);
01114
01115 if( x && x != item )
01116 {
01117 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: Duplicate label %s! Previously defined at file %s, line %d.\n",
01118 item->filename, item->startline, item->endline, item->u1.str, x->filename, x->startline);
01119 errs++;
01120 }
01121
01122 }
01123
01124 static pval *get_goto_target(pval *item)
01125 {
01126
01127 pval *curr_ext = get_extension_or_contxt(item);
01128 pval *curr_cont;
01129
01130 if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) {
01131 struct pval *x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), curr_ext);
01132 return x;
01133 }
01134
01135 curr_cont = get_contxt(item);
01136
01137
01138 if (item->u1.list->next && !item->u1.list->next->next) {
01139 if (!strstr((item->u1.list)->u1.str,"${")
01140 && !strstr(item->u1.list->next->u1.str,"${") ) {
01141 struct pval *x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, curr_cont);
01142 return x;
01143 }
01144 }
01145
01146
01147 if (item->u1.list->next && item->u1.list->next->next) {
01148
01149 pval *first = item->u1.list;
01150 pval *second = item->u1.list->next;
01151 pval *third = item->u1.list->next->next;
01152
01153 if (!strstr((item->u1.list)->u1.str,"${")
01154 && !strstr(item->u1.list->next->u1.str,"${")
01155 && !strstr(item->u1.list->next->next->u1.str,"${")) {
01156 struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str);
01157 if (!x) {
01158
01159 struct pval *p3;
01160 struct pval *that_context = find_context(item->u1.list->u1.str);
01161
01162
01163
01164 if (that_context) {
01165 for (p3=that_context->u2.statements; p3; p3=p3->next) {
01166 if (p3->type == PV_INCLUDES) {
01167 struct pval *p4;
01168 for (p4=p3->u1.list; p4; p4=p4->next) {
01169
01170
01171 char *incl_context = p4->u1.str;
01172
01173 struct pval *that_other_context = find_context(incl_context);
01174 if (that_other_context) {
01175 struct pval *x3;
01176 x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context);
01177 if (x3) {
01178 return x3;
01179 }
01180 }
01181 }
01182 }
01183 }
01184 }
01185 }
01186 return x;
01187 }
01188 }
01189 return 0;
01190 }
01191
01192 static void check_goto(pval *item)
01193 {
01194
01195 if ( !(item->u1.list)->next && !(item->u1.list)->u1.str ) {
01196 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: empty label reference found!\n",
01197 item->filename, item->startline, item->endline);
01198 errs++;
01199 }
01200
01201
01202
01203 if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) {
01204 struct pval *z = get_extension_or_contxt(item);
01205 struct pval *x = 0;
01206 if (z)
01207 x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), z);
01208
01209
01210 if (!x) {
01211 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s exists in the current extension!\n",
01212 item->filename, item->startline, item->endline, item->u1.list->u1.str);
01213 errs++;
01214 }
01215 else
01216 return;
01217 }
01218
01219
01220 if (item->u1.list->next && !item->u1.list->next->next) {
01221
01222
01223
01224 if (!strstr((item->u1.list)->u1.str,"${")
01225 && !strstr(item->u1.list->next->u1.str,"${") ) {
01226 struct pval *z = get_contxt(item);
01227 struct pval *x = 0;
01228
01229 if (z)
01230 x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, z);
01231
01232 if (!x) {
01233 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",
01234 item->filename, item->startline, item->endline, item->u1.list->u1.str, item->u1.list->next->u1.str );
01235 errs++;
01236 }
01237 else
01238 return;
01239 }
01240 }
01241
01242
01243 if (item->u1.list->next && item->u1.list->next->next) {
01244
01245 pval *first = item->u1.list;
01246 pval *second = item->u1.list->next;
01247 pval *third = item->u1.list->next->next;
01248
01249
01250
01251 if (!strstr((item->u1.list)->u1.str,"${")
01252 && !strstr(item->u1.list->next->u1.str,"${")
01253 && !strstr(item->u1.list->next->next->u1.str,"${")) {
01254 struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str);
01255 if (!x) {
01256 struct pval *p3;
01257 struct pval *found = 0;
01258 struct pval *that_context = find_context(item->u1.list->u1.str);
01259
01260
01261
01262 if (that_context) {
01263 for (p3=that_context->u2.statements; p3; p3=p3->next) {
01264 if (p3->type == PV_INCLUDES) {
01265 struct pval *p4;
01266 for (p4=p3->u1.list; p4; p4=p4->next) {
01267
01268
01269 char *incl_context = p4->u1.str;
01270
01271 struct pval *that_other_context = find_context(incl_context);
01272 if (that_other_context) {
01273 struct pval *x3;
01274 x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context);
01275 if (x3) {
01276 found = x3;
01277 break;
01278 }
01279 }
01280 }
01281 }
01282 }
01283 if (!found) {
01284 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s|%s exists in the context %s or its inclusions!\n",
01285 item->filename, item->startline, item->endline, item->u1.list->next->u1.str, item->u1.list->next->next->u1.str, item->u1.list->u1.str );
01286 errs++;
01287 }
01288 } else {
01289
01290 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: goto: no context %s could be found that matches the goto target!\n",
01291 item->filename, item->startline, item->endline, item->u1.list->u1.str);
01292 warns++;
01293 }
01294 }
01295 }
01296 }
01297 }
01298
01299
01300 static void find_pval_goto_item(pval *item, int lev)
01301 {
01302 struct pval *p4;
01303
01304 if (lev>100) {
01305 ast_log(LOG_ERROR,"find_pval_goto in infinite loop! item_type: %d\n\n", item->type);
01306 return;
01307 }
01308
01309 switch ( item->type ) {
01310 case PV_MACRO:
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320 find_pval_gotos(item->u3.macro_statements,lev+1);
01321
01322 break;
01323
01324 case PV_CONTEXT:
01325
01326
01327
01328
01329 break;
01330
01331 case PV_CASE:
01332
01333
01334
01335
01336 find_pval_gotos(item->u2.statements,lev+1);
01337 break;
01338
01339 case PV_PATTERN:
01340
01341
01342
01343
01344 find_pval_gotos(item->u2.statements,lev+1);
01345 break;
01346
01347 case PV_DEFAULT:
01348
01349
01350
01351
01352 find_pval_gotos(item->u2.statements,lev+1);
01353 break;
01354
01355 case PV_CATCH:
01356
01357
01358
01359
01360 find_pval_gotos(item->u2.statements,lev+1);
01361 break;
01362
01363 case PV_STATEMENTBLOCK:
01364
01365
01366
01367 find_pval_gotos(item->u1.list,lev+1);
01368 break;
01369
01370 case PV_GOTO:
01371
01372
01373
01374 check_goto(item);
01375 break;
01376
01377 case PV_INCLUDES:
01378
01379
01380 for (p4=item->u1.list; p4; p4=p4->next) {
01381
01382
01383 char *incl_context = p4->u1.str;
01384
01385 struct pval *that_context = find_context(incl_context);
01386 if (that_context && that_context->u2.statements) {
01387
01388 find_pval_gotos(that_context->u2.statements,lev+1);
01389 }
01390 }
01391 break;
01392
01393 case PV_FOR:
01394
01395
01396
01397
01398
01399
01400
01401 find_pval_gotos(item->u4.for_statements,lev+1);
01402 break;
01403
01404 case PV_WHILE:
01405
01406
01407
01408
01409
01410 find_pval_gotos(item->u2.statements,lev+1);
01411 break;
01412
01413 case PV_RANDOM:
01414
01415
01416
01417
01418
01419
01420
01421 case PV_IFTIME:
01422
01423
01424
01425
01426
01427
01428 case PV_IF:
01429
01430
01431
01432
01433
01434
01435
01436 find_pval_gotos(item->u2.statements,lev+1);
01437
01438 if (item->u3.else_statements) {
01439
01440 find_pval_gotos(item->u3.else_statements,lev+1);
01441 }
01442 break;
01443
01444 case PV_SWITCH:
01445
01446
01447
01448
01449
01450
01451 find_pval_gotos(item->u3.else_statements,lev+1);
01452 break;
01453
01454 case PV_EXTENSION:
01455
01456
01457
01458
01459
01460
01461
01462
01463 find_pval_gotos(item->u2.statements,lev+1);
01464 break;
01465
01466 default:
01467 break;
01468 }
01469 }
01470
01471 static void find_pval_gotos(pval *item,int lev)
01472 {
01473 pval *i;
01474
01475 for (i=item; i; i=i->next) {
01476
01477 find_pval_goto_item(i, lev);
01478 }
01479 }
01480
01481
01482
01483
01484 static struct pval *match_pval_item(pval *item)
01485 {
01486 pval *x;
01487
01488 switch ( item->type ) {
01489 case PV_MACRO:
01490
01491
01492
01493
01494
01495
01496
01497
01498 if (!strcmp(match_context,"*") || !strcmp(item->u1.str, match_context)) {
01499
01500
01501
01502 if (return_on_context_match && !strcmp(item->u1.str, match_context)) {
01503
01504 return item;
01505 }
01506
01507
01508 if (!return_on_context_match) {
01509
01510 if ((x=match_pval(item->u3.macro_statements))) {
01511
01512 return x;
01513 }
01514 }
01515 } else {
01516
01517 }
01518
01519 break;
01520
01521 case PV_CONTEXT:
01522
01523
01524
01525
01526
01527 if (!strcmp(match_context,"*") || !strcmp(item->u1.str, match_context)) {
01528 if (return_on_context_match && !strcmp(item->u1.str, match_context)) {
01529
01530
01531 return item;
01532 }
01533
01534 if (!return_on_context_match ) {
01535
01536 if ((x=match_pval(item->u2.statements))) {
01537
01538 return x;
01539 }
01540 }
01541 } else {
01542
01543 }
01544 break;
01545
01546 case PV_CASE:
01547
01548
01549
01550
01551 if ((x=match_pval(item->u2.statements))) {
01552
01553 return x;
01554 }
01555 break;
01556
01557 case PV_PATTERN:
01558
01559
01560
01561
01562 if ((x=match_pval(item->u2.statements))) {
01563
01564 return x;
01565 }
01566 break;
01567
01568 case PV_DEFAULT:
01569
01570
01571
01572
01573 if ((x=match_pval(item->u2.statements))) {
01574
01575 return x;
01576 }
01577 break;
01578
01579 case PV_CATCH:
01580
01581
01582
01583
01584 if (!strcmp(match_exten,"*") || extension_matches(item, match_exten, item->u1.str) ) {
01585
01586 if (strcmp(match_label,"1") == 0) {
01587 if (item->u2.statements) {
01588 struct pval *p5 = item->u2.statements;
01589 while (p5 && p5->type == PV_LABEL)
01590 p5 = p5->next;
01591 if (p5)
01592 return p5;
01593 else
01594 return 0;
01595 }
01596 else
01597 return 0;
01598 }
01599
01600 if ((x=match_pval(item->u2.statements))) {
01601
01602 return x;
01603 }
01604 } else {
01605
01606 }
01607 break;
01608
01609 case PV_STATEMENTBLOCK:
01610
01611
01612
01613 if ((x=match_pval(item->u1.list))) {
01614
01615 return x;
01616 }
01617 break;
01618
01619 case PV_LABEL:
01620
01621
01622
01623
01624
01625 if (count_labels) {
01626 if (!strcmp(match_label, item->u1.str)) {
01627 label_count++;
01628 last_matched_label = item;
01629 }
01630
01631 } else {
01632 if (!strcmp(match_label, item->u1.str)) {
01633
01634 return item;
01635 }
01636 }
01637 break;
01638
01639 case PV_FOR:
01640
01641
01642
01643
01644
01645
01646
01647 if ((x=match_pval(item->u4.for_statements))) {
01648
01649 return x;
01650 }
01651 break;
01652
01653 case PV_WHILE:
01654
01655
01656
01657
01658
01659 if ((x=match_pval(item->u2.statements))) {
01660
01661 return x;
01662 }
01663 break;
01664
01665 case PV_RANDOM:
01666
01667
01668
01669
01670
01671
01672
01673 case PV_IFTIME:
01674
01675
01676
01677
01678
01679
01680 case PV_IF:
01681
01682
01683
01684
01685
01686
01687
01688 if ((x=match_pval(item->u2.statements))) {
01689 return x;
01690 }
01691 if (item->u3.else_statements) {
01692 if ((x=match_pval(item->u3.else_statements))) {
01693
01694 return x;
01695 }
01696 }
01697 break;
01698
01699 case PV_SWITCH:
01700
01701
01702
01703
01704
01705
01706 if ((x=match_pval(item->u2.statements))) {
01707
01708 return x;
01709 }
01710 break;
01711
01712 case PV_EXTENSION:
01713
01714
01715
01716
01717
01718
01719
01720 if (!strcmp(match_exten,"*") || extension_matches(item, match_exten, item->u1.str) ) {
01721
01722 if (strcmp(match_label,"1") == 0) {
01723 if (item->u2.statements) {
01724 struct pval *p5 = item->u2.statements;
01725 while (p5 && p5->type == PV_LABEL)
01726 p5 = p5->next;
01727 if (p5)
01728 return p5;
01729 else
01730 return 0;
01731 }
01732 else
01733 return 0;
01734 }
01735
01736 if ((x=match_pval(item->u2.statements))) {
01737
01738 return x;
01739 }
01740 } else {
01741
01742 }
01743 break;
01744 default:
01745
01746 break;
01747 }
01748 return 0;
01749 }
01750
01751 struct pval *match_pval(pval *item)
01752 {
01753 pval *i;
01754
01755 for (i=item; i; i=i->next) {
01756 pval *x;
01757
01758
01759 if ((x = match_pval_item(i))) {
01760
01761 return x;
01762 }
01763 }
01764 return 0;
01765 }
01766
01767 #if 0
01768 int count_labels_in_current_context(char *label)
01769 {
01770 label_count = 0;
01771 count_labels = 1;
01772 return_on_context_match = 0;
01773 match_pval(current_context->u2.statements);
01774
01775 return label_count;
01776 }
01777 #endif
01778
01779 struct pval *find_first_label_in_current_context(char *label, pval *curr_cont)
01780 {
01781
01782 struct pval *ret;
01783 struct pval *p3;
01784 struct pval *startpt = ((curr_cont->type==PV_MACRO)?curr_cont->u3.macro_statements: curr_cont->u2.statements);
01785
01786 count_labels = 0;
01787 return_on_context_match = 0;
01788 match_context = "*";
01789 match_exten = "*";
01790 match_label = label;
01791
01792 ret = match_pval(curr_cont);
01793 if (ret)
01794 return ret;
01795
01796
01797
01798 for (p3=startpt; p3; p3=p3->next) {
01799 if (p3->type == PV_INCLUDES) {
01800 struct pval *p4;
01801 for (p4=p3->u1.list; p4; p4=p4->next) {
01802
01803
01804 char *incl_context = p4->u1.str;
01805
01806 struct pval *that_context = find_context(incl_context);
01807 if (that_context) {
01808 struct pval *x3;
01809 x3 = find_first_label_in_current_context(label, that_context);
01810 if (x3) {
01811 return x3;
01812 }
01813 }
01814 }
01815 }
01816 }
01817 return 0;
01818 }
01819
01820 struct pval *find_label_in_current_context(char *exten, char *label, pval *curr_cont)
01821 {
01822
01823 struct pval *ret;
01824 struct pval *p3;
01825 struct pval *startpt;
01826
01827 count_labels = 0;
01828 return_on_context_match = 0;
01829 match_context = "*";
01830 match_exten = exten;
01831 match_label = label;
01832 if (curr_cont->type == PV_MACRO)
01833 startpt = curr_cont->u3.macro_statements;
01834 else
01835 startpt = curr_cont->u2.statements;
01836
01837 ret = match_pval(startpt);
01838 if (ret)
01839 return ret;
01840
01841
01842
01843 for (p3=startpt; p3; p3=p3->next) {
01844 if (p3->type == PV_INCLUDES) {
01845 struct pval *p4;
01846 for (p4=p3->u1.list; p4; p4=p4->next) {
01847
01848
01849 char *incl_context = p4->u1.str;
01850
01851 struct pval *that_context = find_context(incl_context);
01852 if (that_context) {
01853 struct pval *x3;
01854 x3 = find_label_in_current_context(exten, label, that_context);
01855 if (x3) {
01856 return x3;
01857 }
01858 }
01859 }
01860 }
01861 }
01862 return 0;
01863 }
01864
01865 static struct pval *find_label_in_current_extension(const char *label, pval *curr_ext)
01866 {
01867
01868 count_labels = 0;
01869 return_on_context_match = 0;
01870 match_context = "*";
01871 match_exten = "*";
01872 match_label = label;
01873 return match_pval(curr_ext);
01874 }
01875
01876 static struct pval *find_label_in_current_db(const char *context, const char *exten, const char *label)
01877 {
01878
01879 count_labels = 0;
01880 return_on_context_match = 0;
01881
01882 match_context = context;
01883 match_exten = exten;
01884 match_label = label;
01885
01886 return match_pval(current_db);
01887 }
01888
01889
01890 struct pval *find_macro(char *name)
01891 {
01892 return_on_context_match = 1;
01893 count_labels = 0;
01894 match_context = name;
01895 match_exten = "*";
01896 match_label = "*";
01897 return match_pval(current_db);
01898 }
01899
01900 struct pval *find_context(char *name)
01901 {
01902 return_on_context_match = 1;
01903 count_labels = 0;
01904 match_context = name;
01905 match_exten = "*";
01906 match_label = "*";
01907 return match_pval(current_db);
01908 }
01909
01910 int is_float(char *arg )
01911 {
01912 char *s;
01913 for (s=arg; *s; s++) {
01914 if (*s != '.' && (*s < '0' || *s > '9'))
01915 return 0;
01916 }
01917 return 1;
01918 }
01919 int is_int(char *arg )
01920 {
01921 char *s;
01922 for (s=arg; *s; s++) {
01923 if (*s < '0' || *s > '9')
01924 return 0;
01925 }
01926 return 1;
01927 }
01928 int is_empty(char *arg)
01929 {
01930 if (!arg)
01931 return 1;
01932 if (*arg == 0)
01933 return 1;
01934 while (*arg) {
01935 if (*arg != ' ' && *arg != '\t')
01936 return 0;
01937 arg++;
01938 }
01939 return 1;
01940 }
01941
01942 #ifdef AAL_ARGCHECK
01943 int option_matches_j( struct argdesc *should, pval *is, struct argapp *app)
01944 {
01945 struct argchoice *ac;
01946 char *opcop,*q,*p;
01947
01948 switch (should->dtype) {
01949 case ARGD_OPTIONSET:
01950 if ( strstr(is->u1.str,"${") )
01951 return 0;
01952
01953 opcop = ast_strdupa(is->u1.str);
01954
01955 for (q=opcop;*q;q++) {
01956 if ( *q == '(' ) {
01957 p = q+1;
01958 while (*p && *p != ')' )
01959 *p++ = '+';
01960 q = p+1;
01961 }
01962 }
01963
01964 for (ac=app->opts; ac; ac=ac->next) {
01965 if (strlen(ac->name)>1 && strchr(ac->name,'(') == 0 && strcmp(ac->name,is->u1.str) == 0)
01966 return 0;
01967 }
01968 for (ac=app->opts; ac; ac=ac->next) {
01969 if (strlen(ac->name)==1 || strchr(ac->name,'(')) {
01970 char *p = strchr(opcop,ac->name[0]);
01971
01972 if (p && *p == 'j') {
01973 ast_log(LOG_ERROR, "Error: file %s, line %d-%d: The j option in the %s application call is not appropriate for AEL!\n",
01974 is->filename, is->startline, is->endline, app->name);
01975 errs++;
01976 }
01977
01978 if (p) {
01979 *p = '+';
01980 if (ac->name[1] == '(') {
01981 if (*(p+1) != '(') {
01982 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",
01983 is->filename, is->startline, is->endline, ac->name[0], app->name);
01984 warns++;
01985 }
01986 }
01987 }
01988 }
01989 }
01990 for (q=opcop; *q; q++) {
01991 if ( *q != '+' && *q != '(' && *q != ')') {
01992 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",
01993 is->filename, is->startline, is->endline, *q, app->name);
01994 warns++;
01995 }
01996 }
01997 return 1;
01998 break;
01999 default:
02000 return 0;
02001 }
02002
02003 }
02004
02005 int option_matches( struct argdesc *should, pval *is, struct argapp *app)
02006 {
02007 struct argchoice *ac;
02008 char *opcop;
02009
02010 switch (should->dtype) {
02011 case ARGD_STRING:
02012 if (is_empty(is->u1.str) && should->type == ARGD_REQUIRED)
02013 return 0;
02014 if (is->u1.str && strlen(is->u1.str) > 0)
02015 return 1;
02016 break;
02017
02018 case ARGD_INT:
02019 if (is_int(is->u1.str))
02020 return 1;
02021 else
02022 return 0;
02023 break;
02024
02025 case ARGD_FLOAT:
02026 if (is_float(is->u1.str))
02027 return 1;
02028 else
02029 return 0;
02030 break;
02031
02032 case ARGD_ENUM:
02033 if( !is->u1.str || strlen(is->u1.str) == 0 )
02034 return 1;
02035 for (ac=should->choices; ac; ac=ac->next) {
02036 if (strcmp(ac->name,is->u1.str) == 0)
02037 return 1;
02038 }
02039 return 0;
02040 break;
02041
02042 case ARGD_OPTIONSET:
02043 opcop = ast_strdupa(is->u1.str);
02044
02045 for (ac=app->opts; ac; ac=ac->next) {
02046 if (strlen(ac->name)>1 && strchr(ac->name,'(') == 0 && strcmp(ac->name,is->u1.str) == 0)
02047 return 1;
02048 }
02049 for (ac=app->opts; ac; ac=ac->next) {
02050 if (strlen(ac->name)==1 || strchr(ac->name,'(')) {
02051 char *p = strchr(opcop,ac->name[0]);
02052
02053 if (p) {
02054 *p = '+';
02055 if (ac->name[1] == '(') {
02056 if (*(p+1) == '(') {
02057 char *q = p+1;
02058 while (*q && *q != ')') {
02059 *q++ = '+';
02060 }
02061 *q = '+';
02062 }
02063 }
02064 }
02065 }
02066 }
02067 return 1;
02068 break;
02069 case ARGD_VARARG:
02070 return 1;
02071 break;
02072 }
02073 return 1;
02074 }
02075 #endif
02076
02077 int check_app_args(pval* appcall, pval *arglist, struct argapp *app)
02078 {
02079 #ifdef AAL_ARGCHECK
02080 struct argdesc *ad = app->args;
02081 pval *pa;
02082 int z;
02083
02084 for (pa = arglist; pa; pa=pa->next) {
02085 if (!ad) {
02086 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Extra argument %s not in application call to %s !\n",
02087 arglist->filename, arglist->startline, arglist->endline, pa->u1.str, app->name);
02088 warns++;
02089 return 1;
02090 } else {
02091
02092 do {
02093 if ( ad->dtype == ARGD_VARARG )
02094 break;
02095
02096 z= option_matches( ad, pa, app);
02097 if (!z) {
02098 if ( !arglist )
02099 arglist=appcall;
02100
02101 if (ad->type == ARGD_REQUIRED) {
02102 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
02103 arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
02104 warns++;
02105 return 1;
02106 }
02107 } else if (z && ad->dtype == ARGD_OPTIONSET) {
02108 option_matches_j( ad, pa, app);
02109 }
02110 ad = ad->next;
02111 } while (ad && !z);
02112 }
02113 }
02114
02115 for ( ; ad; ad=ad->next) {
02116 if (ad->type == ARGD_REQUIRED && ad->dtype != ARGD_VARARG) {
02117 if ( !arglist )
02118 arglist=appcall;
02119 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
02120 arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
02121 warns++;
02122 return 1;
02123 }
02124 }
02125 return 0;
02126 #else
02127 return 0;
02128 #endif
02129 }
02130
02131 void check_switch_expr(pval *item, struct argapp *apps)
02132 {
02133 #ifdef AAL_ARGCHECK
02134
02135 char *buff1, *p;
02136 struct argapp *a,*a2;
02137 struct appsetvar *v,*v2;
02138 struct argchoice *c;
02139 pval *t;
02140
02141 p = item->u1.str;
02142 while (p && *p && (*p == ' ' || *p == '\t' || *p == '$' || *p == '{' ) )
02143 p++;
02144
02145 buff1 = ast_strdupa(p);
02146
02147 while (strlen(buff1) > 0 && ( buff1[strlen(buff1)-1] == '}' || buff1[strlen(buff1)-1] == ' ' || buff1[strlen(buff1)-1] == '\t'))
02148 buff1[strlen(buff1)-1] = 0;
02149
02150 v = 0;
02151 for (a=apps; a; a=a->next) {
02152 for (v=a->setvars;v;v=v->next) {
02153 if (strcmp(v->name,buff1) == 0) {
02154 break;
02155 }
02156 }
02157 if ( v )
02158 break;
02159 }
02160 if (v && v->vals) {
02161
02162 int def= 0;
02163 int pat = 0;
02164 int f1 = 0;
02165
02166
02167 for (t=item->u2.statements; t; t=t->next) {
02168 if (t->type == PV_DEFAULT) {
02169 def =1;
02170 break;
02171 }
02172 if (t->type == PV_PATTERN) {
02173 pat++;
02174 }
02175 }
02176 if (def || pat)
02177 return;
02178 for (c=v->vals; c; c=c->next) {
02179 f1 = 0;
02180 for (t=item->u2.statements; t; t=t->next) {
02181 if (t->type == PV_CASE || t->type == PV_PATTERN) {
02182 if (!strcmp(t->u1.str,c->name)) {
02183 f1 = 1;
02184 break;
02185 }
02186 }
02187 }
02188 if (!f1) {
02189 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: switch with expression(%s) does not handle the case of %s !\n",
02190 item->filename, item->startline, item->endline, item->u1.str, c->name);
02191 warns++;
02192 }
02193 }
02194
02195 f1 = 0;
02196 t = current_extension->u2.statements;
02197 if ( t && t->type == PV_STATEMENTBLOCK )
02198 t = t->u1.statements;
02199 for (; t && t != item; t=t->next) {
02200 if (t->type == PV_APPLICATION_CALL) {
02201
02202 for (a2=apps; a2; a2=a2->next) {
02203 if (strcasecmp(a2->name, t->u1.str)==0) {
02204 for (v2=a2->setvars; v2; v2=v2->next) {
02205 if (strcmp(v2->name, buff1) == 0) {
02206
02207 f1 = 1;
02208 break;
02209 }
02210 }
02211 }
02212 if (f1)
02213 break;
02214 }
02215 }
02216 if (f1)
02217 break;
02218 }
02219
02220
02221 if (!f1) {
02222 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",
02223 item->filename, item->startline, item->endline, item->u1.str);
02224 warns++;
02225 }
02226 }
02227 #else
02228 pval *t,*tl=0,*p2;
02229 int def= 0;
02230
02231
02232 for (t=item->u2.statements; t; t=t->next) {
02233 if (t->type == PV_DEFAULT) {
02234 def =1;
02235 break;
02236 }
02237 tl = t;
02238 }
02239 if (def)
02240 return;
02241
02242 p2 = tl->next = calloc(1, sizeof(struct pval));
02243
02244 p2->type = PV_DEFAULT;
02245 p2->startline = tl->startline;
02246 p2->endline = tl->endline;
02247 p2->startcol = tl->startcol;
02248 p2->endcol = tl->endcol;
02249 p2->filename = strdup(tl->filename);
02250 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: A default case was automatically added to the switch.\n",
02251 p2->filename, p2->startline, p2->endline);
02252 warns++;
02253
02254 #endif
02255 }
02256
02257 static void check_context_names(void)
02258 {
02259 pval *i,*j;
02260 for (i=current_db; i; i=i->next) {
02261 if (i->type == PV_CONTEXT || i->type == PV_MACRO) {
02262 for (j=i->next; j; j=j->next) {
02263 if ( j->type == PV_CONTEXT || j->type == PV_MACRO ) {
02264 if ( !strcmp(i->u1.str, j->u1.str) && !(i->u3.abstract&2) && !(j->u3.abstract&2) )
02265 {
02266 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: The context name (%s) is also declared in file %s, line %d-%d! (and neither is marked 'extend')\n",
02267 i->filename, i->startline, i->endline, i->u1.str, j->filename, j->startline, j->endline);
02268 errs++;
02269 }
02270 }
02271 }
02272 }
02273 }
02274 }
02275
02276 static void check_abstract_reference(pval *abstract_context)
02277 {
02278 pval *i,*j;
02279
02280
02281
02282
02283 for (i=current_db; i; i=i->next) {
02284 if (i->type == PV_CONTEXT) {
02285 for (j=i->u2. statements; j; j=j->next) {
02286 if ( j->type == PV_INCLUDES ) {
02287 struct pval *p4;
02288 for (p4=j->u1.list; p4; p4=p4->next) {
02289
02290
02291 if ( !strcmp(p4->u1.str, abstract_context->u1.str) )
02292 return;
02293 }
02294 }
02295 }
02296 }
02297 }
02298 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",
02299 abstract_context->filename, abstract_context->startline, abstract_context->endline, abstract_context->u1.str);
02300 warns++;
02301 }
02302
02303
02304 void check_pval_item(pval *item, struct argapp *apps, int in_globals)
02305 {
02306 pval *lp;
02307 #ifdef AAL_ARGCHECK
02308 struct argapp *app, *found;
02309 #endif
02310 struct pval *macro_def;
02311 struct pval *app_def;
02312
02313 char errmsg[4096];
02314 char *strp;
02315
02316 switch (item->type) {
02317 case PV_WORD:
02318
02319
02320 break;
02321
02322 case PV_MACRO:
02323
02324
02325
02326
02327
02328
02329
02330 in_abstract_context = 0;
02331 current_context = item;
02332 current_extension = 0;
02333 for (lp=item->u2.arglist; lp; lp=lp->next) {
02334
02335 }
02336 check_pval(item->u3.macro_statements, apps,in_globals);
02337 break;
02338
02339 case PV_CONTEXT:
02340
02341
02342
02343
02344 current_context = item;
02345 current_extension = 0;
02346 if ( item->u3.abstract ) {
02347 in_abstract_context = 1;
02348 check_abstract_reference(item);
02349 } else
02350 in_abstract_context = 0;
02351 check_pval(item->u2.statements, apps,in_globals);
02352 break;
02353
02354 case PV_MACRO_CALL:
02355
02356
02357
02358
02359
02360 macro_def = find_macro(item->u1.str);
02361 if (!macro_def) {
02362
02363 ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: macro call to non-existent %s ! Hopefully it is present in extensions.conf! \n",
02364 item->filename, item->startline, item->endline, item->u1.str);
02365 warns++;
02366 } else if (macro_def->type != PV_MACRO) {
02367 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: macro call to %s references a context, not a macro!\n",
02368 item->filename, item->startline, item->endline, item->u1.str);
02369 errs++;
02370 } else {
02371
02372 int hereargs = 0;
02373 int thereargs = 0;
02374
02375 for (lp=item->u2.arglist; lp; lp=lp->next) {
02376 hereargs++;
02377 }
02378 for (lp=macro_def->u2.arglist; lp; lp=lp->next) {
02379 thereargs++;
02380 }
02381 if (hereargs != thereargs ) {
02382 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",
02383 item->filename, item->startline, item->endline, item->u1.str, hereargs, thereargs);
02384 errs++;
02385 }
02386 }
02387 break;
02388
02389 case PV_APPLICATION_CALL:
02390
02391
02392
02393
02394
02395
02396 app_def = find_context(item->u1.str);
02397 if (app_def && app_def->type == PV_MACRO) {
02398 ast_log(LOG_ERROR,"Error: file %s, line %d-%d: application call to %s references an existing macro, but had no & preceding it!\n",
02399 item->filename, item->startline, item->endline, item->u1.str);
02400 errs++;
02401 }
02402 if (strcasecmp(item->u1.str,"GotoIf") == 0
02403 || strcasecmp(item->u1.str,"GotoIfTime") == 0
02404 || strcasecmp(item->u1.str,"while") == 0
02405 || strcasecmp(item->u1.str,"endwhile") == 0
02406 || strcasecmp(item->u1.str,"random") == 0
02407 || strcasecmp(item->u1.str,"execIf") == 0 ) {
02408 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: application call to %s needs to be re-written using AEL if, while, goto, etc. keywords instead!\n",
02409 item->filename, item->startline, item->endline, item->u1.str);
02410 warns++;
02411 }
02412 #ifdef AAL_ARGCHECK
02413 found = 0;
02414 for (app=apps; app; app=app->next) {
02415 if (strcasecmp(app->name, item->u1.str) == 0) {
02416 found =app;
02417 break;
02418 }
02419 }
02420 if (!found) {
02421 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: application call to %s not listed in applist database!\n",
02422 item->filename, item->startline, item->endline, item->u1.str);
02423 warns++;
02424 } else
02425 check_app_args(item, item->u2.arglist, app);
02426 #endif
02427 break;
02428
02429 case PV_CASE:
02430
02431
02432
02433
02434
02435 check_pval(item->u2.statements, apps,in_globals);
02436 break;
02437
02438 case PV_PATTERN:
02439
02440
02441
02442
02443
02444
02445 check_pval(item->u2.statements, apps,in_globals);
02446 break;
02447
02448 case PV_DEFAULT:
02449
02450
02451
02452
02453 check_pval(item->u2.statements, apps,in_globals);
02454 break;
02455
02456 case PV_CATCH:
02457
02458
02459
02460 check_pval(item->u2.statements, apps,in_globals);
02461 break;
02462
02463 case PV_SWITCHES:
02464
02465
02466 check_pval(item->u1.list, apps,in_globals);
02467 break;
02468
02469 case PV_ESWITCHES:
02470
02471
02472 check_pval(item->u1.list, apps,in_globals);
02473 break;
02474
02475 case PV_INCLUDES:
02476
02477
02478 check_pval(item->u1.list, apps,in_globals);
02479 check_includes(item);
02480 for (lp=item->u1.list; lp; lp=lp->next){
02481 char *incl_context = lp->u1.str;
02482 struct pval *that_context = find_context(incl_context);
02483
02484 if ( lp->u2.arglist ) {
02485 check_timerange(lp->u2.arglist);
02486 check_dow(lp->u2.arglist->next);
02487 check_day(lp->u2.arglist->next->next);
02488 check_month(lp->u2.arglist->next->next->next);
02489 }
02490
02491 if (that_context) {
02492 find_pval_gotos(that_context->u2.statements,0);
02493
02494 }
02495 }
02496 break;
02497
02498 case PV_STATEMENTBLOCK:
02499
02500
02501 check_pval(item->u1.list, apps,in_globals);
02502 break;
02503
02504 case PV_VARDEC:
02505
02506
02507
02508
02509 if( !in_globals ) {
02510 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);
02511 ast_expr_register_extra_error_info(errmsg);
02512 ast_expr(item->u2.val, expr_output, sizeof(expr_output));
02513 ast_expr_clear_extra_error_info();
02514 if ( strpbrk(item->u2.val,"~!-+<>=*/&^") && !strstr(item->u2.val,"${") ) {
02515 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
02516 item->filename, item->startline, item->endline, item->u2.val);
02517 warns++;
02518 }
02519 check_expr2_input(item,item->u2.val);
02520 }
02521 break;
02522
02523 case PV_GOTO:
02524
02525
02526
02527
02528 if ( in_abstract_context )
02529 break;
02530
02531 check_goto(item);
02532 break;
02533
02534 case PV_LABEL:
02535
02536
02537 if ( strspn(item->u1.str, "0123456789") == strlen(item->u1.str) ) {
02538 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: label '%s' is numeric, this is bad practice!\n",
02539 item->filename, item->startline, item->endline, item->u1.str);
02540 warns++;
02541 }
02542
02543 check_label(item);
02544 break;
02545
02546 case PV_FOR:
02547
02548
02549
02550
02551
02552
02553 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);
02554 ast_expr_register_extra_error_info(errmsg);
02555
02556 strp = strchr(item->u1.for_init, '=');
02557 if (strp) {
02558 ast_expr(strp+1, expr_output, sizeof(expr_output));
02559 }
02560 ast_expr(item->u2.for_test, expr_output, sizeof(expr_output));
02561 strp = strchr(item->u3.for_inc, '=');
02562 if (strp) {
02563 ast_expr(strp+1, expr_output, sizeof(expr_output));
02564 }
02565 if ( strpbrk(item->u2.for_test,"~!-+<>=*/&^") && !strstr(item->u2.for_test,"${") ) {
02566 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
02567 item->filename, item->startline, item->endline, item->u2.for_test);
02568 warns++;
02569 }
02570 if ( strpbrk(item->u3.for_inc,"~!-+<>=*/&^") && !strstr(item->u3.for_inc,"${") ) {
02571 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
02572 item->filename, item->startline, item->endline, item->u3.for_inc);
02573 warns++;
02574 }
02575 check_expr2_input(item,item->u2.for_test);
02576 check_expr2_input(item,item->u3.for_inc);
02577
02578 ast_expr_clear_extra_error_info();
02579 check_pval(item->u4.for_statements, apps,in_globals);
02580 break;
02581
02582 case PV_WHILE:
02583
02584
02585
02586
02587 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, while expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
02588 ast_expr_register_extra_error_info(errmsg);
02589 ast_expr(item->u1.str, expr_output, sizeof(expr_output));
02590 ast_expr_clear_extra_error_info();
02591 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
02592 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
02593 item->filename, item->startline, item->endline, item->u1.str);
02594 warns++;
02595 }
02596 check_expr2_input(item,item->u1.str);
02597 check_pval(item->u2.statements, apps,in_globals);
02598 break;
02599
02600 case PV_BREAK:
02601
02602
02603 check_break(item);
02604 break;
02605
02606 case PV_RETURN:
02607
02608
02609 break;
02610
02611 case PV_CONTINUE:
02612
02613
02614 check_continue(item);
02615 break;
02616
02617 case PV_RANDOM:
02618
02619
02620
02621
02622
02623
02624 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, random expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
02625 ast_expr_register_extra_error_info(errmsg);
02626 ast_expr(item->u1.str, expr_output, sizeof(expr_output));
02627 ast_expr_clear_extra_error_info();
02628 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
02629 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: random expression '%s' has operators, but no variables. Interesting...\n",
02630 item->filename, item->startline, item->endline, item->u1.str);
02631 warns++;
02632 }
02633 check_expr2_input(item,item->u1.str);
02634 check_pval(item->u2.statements, apps,in_globals);
02635 if (item->u3.else_statements) {
02636 check_pval(item->u3.else_statements, apps,in_globals);
02637 }
02638 break;
02639
02640 case PV_IFTIME:
02641
02642
02643
02644
02645
02646
02647 if ( item->u2.arglist ) {
02648 check_timerange(item->u1.list);
02649 check_dow(item->u1.list->next);
02650 check_day(item->u1.list->next->next);
02651 check_month(item->u1.list->next->next->next);
02652 }
02653
02654 check_pval(item->u2.statements, apps,in_globals);
02655 if (item->u3.else_statements) {
02656 check_pval(item->u3.else_statements, apps,in_globals);
02657 }
02658 break;
02659
02660 case PV_IF:
02661
02662
02663
02664
02665
02666
02667 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, if expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
02668 ast_expr_register_extra_error_info(errmsg);
02669 ast_expr(item->u1.str, expr_output, sizeof(expr_output));
02670 ast_expr_clear_extra_error_info();
02671 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
02672 ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression '%s' has operators, but no variables. Interesting...\n",
02673 item->filename, item->startline, item->endline, item->u1.str);
02674 warns++;
02675 }
02676 check_expr2_input(item,item->u1.str);
02677 check_pval(item->u2.statements, apps,in_globals);
02678 if (item->u3.else_statements) {
02679 check_pval(item->u3.else_statements, apps,in_globals);
02680 }
02681 break;
02682
02683 case PV_SWITCH:
02684
02685
02686
02687
02688
02689
02690
02691 check_switch_expr(item, apps);
02692 check_pval(item->u2.statements, apps,in_globals);
02693 break;
02694
02695 case PV_EXTENSION:
02696
02697
02698
02699
02700
02701
02702 current_extension = item ;
02703
02704 check_pval(item->u2.statements, apps,in_globals);
02705 break;
02706
02707 case PV_IGNOREPAT:
02708
02709
02710 break;
02711
02712 case PV_GLOBALS:
02713
02714
02715 in_abstract_context = 0;
02716 check_pval(item->u1.statements, apps, 1);
02717 break;
02718 default:
02719 break;
02720 }
02721 }
02722
02723 void check_pval(pval *item, struct argapp *apps, int in_globals)
02724 {
02725 pval *i;
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738 for (i=item; i; i=i->next) {
02739 check_pval_item(i,apps,in_globals);
02740 }
02741 }
02742
02743 static void ael2_semantic_check(pval *item, int *arg_errs, int *arg_warns, int *arg_notes)
02744 {
02745
02746 #ifdef AAL_ARGCHECK
02747 int argapp_errs =0;
02748 char *rfilename;
02749 #endif
02750 struct argapp *apps=0;
02751
02752 if (!item)
02753 return;
02754 #ifdef AAL_ARGCHECK
02755 rfilename = alloca(10 + strlen(ast_config_AST_VAR_DIR));
02756 sprintf(rfilename, "%s/applist", ast_config_AST_VAR_DIR);
02757
02758 apps = argdesc_parse(rfilename, &argapp_errs);
02759 #endif
02760 current_db = item;
02761 errs = warns = notes = 0;
02762
02763 check_context_names();
02764 check_pval(item, apps, 0);
02765
02766 #ifdef AAL_ARGCHECK
02767 argdesc_destroy(apps);
02768 #endif
02769 current_db = 0;
02770
02771 *arg_errs = errs;
02772 *arg_warns = warns;
02773 *arg_notes = notes;
02774 }
02775
02776
02777
02778
02779
02780 static int control_statement_count = 0;
02781
02782 struct ael_priority *new_prio(void)
02783 {
02784 struct ael_priority *x = (struct ael_priority *)calloc(sizeof(struct ael_priority),1);
02785 return x;
02786 }
02787
02788 struct ael_extension *new_exten(void)
02789 {
02790 struct ael_extension *x = (struct ael_extension *)calloc(sizeof(struct ael_extension),1);
02791 return x;
02792 }
02793
02794 void linkprio(struct ael_extension *exten, struct ael_priority *prio, struct ael_extension *mother_exten)
02795 {
02796 char *p1, *p2;
02797
02798 if (!exten->plist) {
02799 exten->plist = prio;
02800 exten->plist_last = prio;
02801 } else {
02802 exten->plist_last->next = prio;
02803 exten->plist_last = prio;
02804 }
02805 if( !prio->exten )
02806 prio->exten = exten;
02807
02808
02809
02810
02811
02812 if (prio->appargs && ((mother_exten && mother_exten->has_switch) || exten->has_switch) ) {
02813 while ((p1 = strstr(prio->appargs, "${EXTEN}"))) {
02814 p2 = malloc(strlen(prio->appargs)+5);
02815 *p1 = 0;
02816 strcpy(p2, prio->appargs);
02817 strcat(p2, "${~~EXTEN~~}");
02818 if (*(p1+8))
02819 strcat(p2, p1+8);
02820 free(prio->appargs);
02821 prio->appargs = p2;
02822 }
02823 while ((p1 = strstr(prio->appargs, "${EXTEN:"))) {
02824 p2 = malloc(strlen(prio->appargs)+5);
02825 *p1 = 0;
02826 strcpy(p2, prio->appargs);
02827 strcat(p2, "${~~EXTEN~~:");
02828 if (*(p1+8))
02829 strcat(p2, p1+8);
02830 free(prio->appargs);
02831 prio->appargs = p2;
02832 }
02833 }
02834 }
02835
02836 void destroy_extensions(struct ael_extension *exten)
02837 {
02838 struct ael_extension *ne, *nen;
02839 for (ne=exten; ne; ne=nen) {
02840 struct ael_priority *pe, *pen;
02841
02842 if (ne->name)
02843 free(ne->name);
02844
02845
02846
02847
02848
02849 if (ne->hints)
02850 free(ne->hints);
02851
02852 for (pe=ne->plist; pe; pe=pen) {
02853 pen = pe->next;
02854 if (pe->app)
02855 free(pe->app);
02856 pe->app = 0;
02857 if (pe->appargs)
02858 free(pe->appargs);
02859 pe->appargs = 0;
02860 pe->origin = 0;
02861 pe->goto_true = 0;
02862 pe->goto_false = 0;
02863 free(pe);
02864 }
02865 nen = ne->next_exten;
02866 ne->next_exten = 0;
02867 ne->plist =0;
02868 ne->plist_last = 0;
02869 ne->next_exten = 0;
02870 ne->loop_break = 0;
02871 ne->loop_continue = 0;
02872 free(ne);
02873 }
02874 }
02875
02876 static int label_inside_case(pval *label)
02877 {
02878 pval *p = label;
02879
02880 while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) {
02881 if( p->type == PV_CASE || p->type == PV_DEFAULT || p->type == PV_PATTERN ) {
02882 return 1;
02883 }
02884
02885 p = p->dad;
02886 }
02887 return 0;
02888 }
02889
02890 static void linkexten(struct ael_extension *exten, struct ael_extension *add)
02891 {
02892 add->next_exten = exten->next_exten;
02893 exten->next_exten = add;
02894 }
02895
02896 static void remove_spaces_before_equals(char *str)
02897 {
02898 char *p;
02899 while( str && *str && *str != '=' )
02900 {
02901 if( *str == ' ' || *str == '\n' || *str == '\r' || *str == '\t' )
02902 {
02903 p = str;
02904 while( *p )
02905 {
02906 *p = *(p+1);
02907 p++;
02908 }
02909 }
02910 else
02911 str++;
02912 }
02913 }
02914
02915 static void gen_match_to_pattern(char *pattern, char *result)
02916 {
02917
02918 char *p=pattern, *t=result;
02919 while (*p) {
02920 if (*p == 'x' || *p == 'n' || *p == 'z' || *p == 'X' || *p == 'N' || *p == 'Z')
02921 *t++ = '9';
02922 else if (*p == '[') {
02923 char *z = p+1;
02924 while (*z != ']')
02925 z++;
02926 if (*(z+1)== ']')
02927 z++;
02928 *t++=*(p+1);
02929 p = z;
02930 } else {
02931 *t++ = *p;
02932 }
02933 p++;
02934 }
02935 *t++ = 0;
02936 }
02937
02938
02939
02940 int find_switch_item(pval *item);
02941 int contains_switch(pval *item);
02942
02943
02944 int find_switch_item(pval *item)
02945 {
02946 switch ( item->type ) {
02947 case PV_WORD:
02948
02949 break;
02950
02951 case PV_MACRO:
02952
02953
02954
02955
02956
02957
02958
02959
02960 if (contains_switch(item->u3.macro_statements))
02961 return 1;
02962 break;
02963
02964 case PV_CONTEXT:
02965
02966
02967
02968
02969
02970 if (contains_switch(item->u2.statements))
02971 return 1;
02972 break;
02973
02974 case PV_MACRO_CALL:
02975
02976
02977
02978
02979
02980 break;
02981
02982 case PV_APPLICATION_CALL:
02983
02984
02985
02986
02987
02988 break;
02989
02990 case PV_CASE:
02991
02992
02993
02994
02995 if (contains_switch(item->u2.statements))
02996 return 1;
02997 break;
02998
02999 case PV_PATTERN:
03000
03001
03002
03003
03004 if (contains_switch(item->u2.statements))
03005 return 1;
03006 break;
03007
03008 case PV_DEFAULT:
03009
03010
03011
03012
03013 if (contains_switch(item->u2.statements))
03014 return 1;
03015 break;
03016
03017 case PV_CATCH:
03018
03019
03020
03021
03022 if (contains_switch(item->u2.statements))
03023 return 1;
03024 break;
03025
03026 case PV_SWITCHES:
03027
03028
03029 break;
03030
03031 case PV_ESWITCHES:
03032
03033
03034 break;
03035
03036 case PV_INCLUDES:
03037
03038
03039
03040 break;
03041
03042 case PV_STATEMENTBLOCK:
03043
03044
03045 if (contains_switch(item->u1.list) )
03046 return 1;
03047 break;
03048
03049 case PV_VARDEC:
03050
03051
03052
03053 break;
03054
03055 case PV_GOTO:
03056
03057
03058
03059 break;
03060
03061 case PV_LABEL:
03062
03063
03064 break;
03065
03066 case PV_FOR:
03067
03068
03069
03070
03071
03072
03073 if (contains_switch(item->u4.for_statements))
03074 return 1;
03075 break;
03076
03077 case PV_WHILE:
03078
03079
03080
03081
03082 if (contains_switch(item->u2.statements))
03083 return 1;
03084 break;
03085
03086 case PV_BREAK:
03087
03088
03089 break;
03090
03091 case PV_RETURN:
03092
03093
03094 break;
03095
03096 case PV_CONTINUE:
03097
03098
03099 break;
03100
03101 case PV_IFTIME:
03102
03103
03104
03105
03106
03107
03108 if (contains_switch(item->u2.statements))
03109 return 1;
03110 if ( item->u3.else_statements ) {
03111 if (contains_switch(item->u3.else_statements))
03112 return 1;
03113 }
03114 break;
03115
03116 case PV_RANDOM:
03117
03118
03119
03120
03121
03122
03123 if (contains_switch(item->u2.statements))
03124 return 1;
03125 if ( item->u3.else_statements ) {
03126 if (contains_switch(item->u3.else_statements))
03127 return 1;
03128 }
03129 break;
03130
03131 case PV_IF:
03132
03133
03134
03135
03136
03137
03138 if (contains_switch(item->u2.statements))
03139 return 1;
03140 if ( item->u3.else_statements ) {
03141 if (contains_switch(item->u3.else_statements))
03142 return 1;
03143 }
03144 break;
03145
03146 case PV_SWITCH:
03147
03148
03149
03150
03151
03152 return 1;
03153 break;
03154
03155 case PV_EXTENSION:
03156
03157
03158
03159
03160
03161
03162 if (contains_switch(item->u2.statements))
03163 return 1;
03164 break;
03165
03166 case PV_IGNOREPAT:
03167
03168
03169 break;
03170
03171 case PV_GLOBALS:
03172
03173
03174 break;
03175 }
03176 return 0;
03177 }
03178
03179 int contains_switch(pval *item)
03180 {
03181 pval *i;
03182
03183 for (i=item; i; i=i->next) {
03184 if (find_switch_item(i))
03185 return 1;
03186 }
03187 return 0;
03188 }
03189
03190
03191 static void gen_prios(struct ael_extension *exten, char *label, pval *statement, struct ael_extension *mother_exten, struct ast_context *this_context )
03192 {
03193 pval *p,*p2,*p3;
03194 struct ael_priority *pr;
03195 struct ael_priority *for_init, *for_test, *for_inc, *for_loop, *for_end;
03196 struct ael_priority *while_test, *while_loop, *while_end;
03197 struct ael_priority *switch_set, *switch_test, *switch_end, *fall_thru, *switch_empty;
03198 struct ael_priority *if_test, *if_end, *if_skip, *if_false;
03199 #ifdef OLD_RAND_ACTION
03200 struct ael_priority *rand_test, *rand_end, *rand_skip;
03201 #endif
03202 char buf1[2000];
03203 char buf2[2000];
03204 char *strp, *strp2;
03205 char new_label[2000];
03206 int default_exists;
03207 int local_control_statement_count;
03208 struct ael_priority *loop_break_save;
03209 struct ael_priority *loop_continue_save;
03210 struct ael_extension *switch_case,*switch_null;
03211
03212 if ((mother_exten && !mother_exten->checked_switch) || (exten && !exten->checked_switch)) {
03213 if (contains_switch(statement)) {
03214 if (mother_exten) {
03215 if (!mother_exten->has_switch) {
03216 switch_set = new_prio();
03217 switch_set->type = AEL_APPCALL;
03218 switch_set->app = strdup("Set");
03219 switch_set->appargs = strdup("~~EXTEN~~=${EXTEN}");
03220 linkprio(exten, switch_set, mother_exten);
03221 mother_exten->has_switch = 1;
03222 mother_exten->checked_switch = 1;
03223 if (exten) {
03224 exten->has_switch = 1;
03225 exten->checked_switch = 1;
03226 }
03227 }
03228 } else if (exten) {
03229 if (!exten->has_switch) {
03230 switch_set = new_prio();
03231 switch_set->type = AEL_APPCALL;
03232 switch_set->app = strdup("Set");
03233 switch_set->appargs = strdup("~~EXTEN~~=${EXTEN}");
03234 linkprio(exten, switch_set, mother_exten);
03235 exten->has_switch = 1;
03236 exten->checked_switch = 1;
03237 if (mother_exten) {
03238 mother_exten->has_switch = 1;
03239 mother_exten->checked_switch = 1;
03240 }
03241 }
03242 }
03243 } else {
03244 if (mother_exten) {
03245 mother_exten->checked_switch = 1;
03246 }
03247 if (exten) {
03248 exten->checked_switch = 1;
03249 }
03250 }
03251 }
03252 for (p=statement; p; p=p->next) {
03253 switch (p->type) {
03254 case PV_VARDEC:
03255 pr = new_prio();
03256 pr->type = AEL_APPCALL;
03257 snprintf(buf1,sizeof(buf1),"%s=$[%s]", p->u1.str, p->u2.val);
03258 pr->app = strdup("Set");
03259 remove_spaces_before_equals(buf1);
03260 pr->appargs = strdup(buf1);
03261 pr->origin = p;
03262 linkprio(exten, pr, mother_exten);
03263 break;
03264
03265 case PV_GOTO:
03266 pr = new_prio();
03267 pr->type = AEL_APPCALL;
03268 p->u2.goto_target = get_goto_target(p);
03269 if( p->u2.goto_target ) {
03270 p->u3.goto_target_in_case = label_inside_case(p->u2.goto_target);
03271 }
03272
03273 if (!p->u1.list->next) {
03274 pr->app = strdup("Goto");
03275 if (!mother_exten)
03276 pr->appargs = strdup(p->u1.list->u1.str);
03277 else {
03278 snprintf(buf1,sizeof(buf1),"%s|%s", mother_exten->name, p->u1.list->u1.str);
03279 pr->appargs = strdup(buf1);
03280 }
03281
03282 } else if (p->u1.list->next && !p->u1.list->next->next) {
03283 snprintf(buf1,sizeof(buf1),"%s|%s", p->u1.list->u1.str, p->u1.list->next->u1.str);
03284 pr->app = strdup("Goto");
03285 pr->appargs = strdup(buf1);
03286 } else if (p->u1.list->next && p->u1.list->next->next) {
03287 snprintf(buf1,sizeof(buf1),"%s|%s|%s", p->u1.list->u1.str,
03288 p->u1.list->next->u1.str,
03289 p->u1.list->next->next->u1.str);
03290 pr->app = strdup("Goto");
03291 pr->appargs = strdup(buf1);
03292 }
03293 pr->origin = p;
03294 linkprio(exten, pr, mother_exten);
03295 break;
03296
03297 case PV_LABEL:
03298 pr = new_prio();
03299 pr->type = AEL_LABEL;
03300 pr->origin = p;
03301 p->u3.compiled_label = exten;
03302 linkprio(exten, pr, mother_exten);
03303 break;
03304
03305 case PV_FOR:
03306 control_statement_count++;
03307 loop_break_save = exten->loop_break;
03308 loop_continue_save = exten->loop_continue;
03309 snprintf(new_label,sizeof(new_label),"for-%s-%d", label, control_statement_count);
03310 for_init = new_prio();
03311 for_inc = new_prio();
03312 for_test = new_prio();
03313 for_loop = new_prio();
03314 for_end = new_prio();
03315 for_init->type = AEL_APPCALL;
03316 for_inc->type = AEL_APPCALL;
03317 for_test->type = AEL_FOR_CONTROL;
03318 for_test->goto_false = for_end;
03319 for_loop->type = AEL_CONTROL1;
03320 for_end->type = AEL_APPCALL;
03321 for_init->app = strdup("Set");
03322
03323 strcpy(buf2,p->u1.for_init);
03324 remove_spaces_before_equals(buf2);
03325 strp = strchr(buf2, '=');
03326 if (strp) {
03327 strp2 = strchr(p->u1.for_init, '=');
03328 *(strp+1) = 0;
03329 strcat(buf2,"$[");
03330 strncat(buf2,strp2+1, sizeof(buf2)-strlen(strp2+1)-2);
03331 strcat(buf2,"]");
03332 for_init->appargs = strdup(buf2);
03333
03334 } else {
03335 strp2 = p->u1.for_init;
03336 while (*strp2 && isspace(*strp2))
03337 strp2++;
03338 if (*strp2 == '&') {
03339 char *strp3 = strp2+1;
03340 while (*strp3 && isspace(*strp3))
03341 strp3++;
03342 strcpy(buf2, strp3);
03343 strp3 = strchr(buf2,'(');
03344 if (strp3) {
03345 *strp3 = '|';
03346 }
03347 while ((strp3=strchr(buf2,','))) {
03348 *strp3 = '|';
03349 }
03350 strp3 = strrchr(buf2, ')');
03351 if (strp3)
03352 *strp3 = 0;
03353
03354 for_init->appargs = strdup(buf2);
03355 if (for_init->app)
03356 free(for_init->app);
03357 for_init->app = strdup("Macro");
03358 } else {
03359 char *strp3;
03360 strcpy(buf2, strp2);
03361 strp3 = strchr(buf2,'(');
03362 if (strp3) {
03363 *strp3 = 0;
03364 if (for_init->app)
03365 free(for_init->app);
03366 for_init->app = strdup(buf2);
03367 for_init->appargs = strdup(strp3+1);
03368 strp3 = strrchr(for_init->appargs, ')');
03369 if (strp3)
03370 *strp3 = 0;
03371 }
03372 }
03373 }
03374
03375 strcpy(buf2,p->u3.for_inc);
03376 remove_spaces_before_equals(buf2);
03377 strp = strchr(buf2, '=');
03378 if (strp) {
03379 strp2 = strchr(p->u3.for_inc, '=');
03380 *(strp+1) = 0;
03381 strcat(buf2,"$[");
03382 strncat(buf2,strp2+1, sizeof(buf2)-strlen(strp2+1)-2);
03383 strcat(buf2,"]");
03384 for_inc->appargs = strdup(buf2);
03385 for_inc->app = strdup("Set");
03386 } else {
03387 strp2 = p->u3.for_inc;
03388 while (*strp2 && isspace(*strp2))
03389 strp2++;
03390 if (*strp2 == '&') {
03391 char *strp3 = strp2+1;
03392 while (*strp3 && isspace(*strp3))
03393 strp3++;
03394 strcpy(buf2, strp3);
03395 strp3 = strchr(buf2,'(');
03396 if (strp3) {
03397 *strp3 = '|';
03398 }
03399 while ((strp3=strchr(buf2,','))) {
03400 *strp3 = '|';
03401 }
03402 strp3 = strrchr(buf2, ')');
03403 if (strp3)
03404 *strp3 = 0;
03405
03406 for_inc->appargs = strdup(buf2);
03407
03408 for_inc->app = strdup("Macro");
03409 } else {
03410 char *strp3;
03411 strcpy(buf2, strp2);
03412 strp3 = strchr(buf2,'(');
03413 if (strp3) {
03414 *strp3 = 0;
03415 for_inc->app = strdup(buf2);
03416 for_inc->appargs = strdup(strp3+1);
03417 strp3 = strrchr(for_inc->appargs, ')');
03418 if (strp3)
03419 *strp3 = 0;
03420 }
03421 }
03422 }
03423 snprintf(buf1,sizeof(buf1),"$[%s]",p->u2.for_test);
03424 for_test->app = 0;
03425 for_test->appargs = strdup(buf1);
03426 for_loop->goto_true = for_test;
03427 snprintf(buf1,sizeof(buf1),"Finish for-%s-%d", label, control_statement_count);
03428 for_end->app = strdup("NoOp");
03429 for_end->appargs = strdup(buf1);
03430
03431 linkprio(exten, for_init, mother_exten);
03432 linkprio(exten, for_test, mother_exten);
03433
03434
03435 exten->loop_break = for_end;
03436 exten->loop_continue = for_inc;
03437
03438 gen_prios(exten, new_label, p->u4.for_statements, mother_exten, this_context);
03439
03440 linkprio(exten, for_inc, mother_exten);
03441 linkprio(exten, for_loop, mother_exten);
03442 linkprio(exten, for_end, mother_exten);
03443
03444
03445 exten->loop_break = loop_break_save;
03446 exten->loop_continue = loop_continue_save;
03447 for_loop->origin = p;
03448 break;
03449
03450 case PV_WHILE:
03451 control_statement_count++;
03452 loop_break_save = exten->loop_break;
03453 loop_continue_save = exten->loop_continue;
03454 snprintf(new_label,sizeof(new_label),"while-%s-%d", label, control_statement_count);
03455 while_test = new_prio();
03456 while_loop = new_prio();
03457 while_end = new_prio();
03458 while_test->type = AEL_FOR_CONTROL;
03459 while_test->goto_false = while_end;
03460 while_loop->type = AEL_CONTROL1;
03461 while_end->type = AEL_APPCALL;
03462 snprintf(buf1,sizeof(buf1),"$[%s]",p->u1.str);
03463 while_test->app = 0;
03464 while_test->appargs = strdup(buf1);
03465 while_loop->goto_true = while_test;
03466 snprintf(buf1,sizeof(buf1),"Finish while-%s-%d", label, control_statement_count);
03467 while_end->app = strdup("NoOp");
03468 while_end->appargs = strdup(buf1);
03469
03470 linkprio(exten, while_test, mother_exten);
03471
03472
03473 exten->loop_break = while_end;
03474 exten->loop_continue = while_test;
03475
03476 gen_prios(exten, new_label, p->u2.statements, mother_exten, this_context);
03477
03478 linkprio(exten, while_loop, mother_exten);
03479 linkprio(exten, while_end, mother_exten);
03480
03481
03482 exten->loop_break = loop_break_save;
03483 exten->loop_continue = loop_continue_save;
03484 while_loop->origin = p;
03485 break;
03486
03487 case PV_SWITCH:
03488 control_statement_count++;
03489 local_control_statement_count = control_statement_count;
03490 loop_break_save = exten->loop_break;
03491 loop_continue_save = exten->loop_continue;
03492 snprintf(new_label,sizeof(new_label),"sw-%s-%d", label, control_statement_count);
03493 switch_test = new_prio();
03494 switch_end = new_prio();
03495 switch_test->type = AEL_APPCALL;
03496 switch_end->type = AEL_APPCALL;
03497 strncpy(buf2,p->u1.str,sizeof(buf2));
03498 buf2[sizeof(buf2)-1] = 0;
03499 substitute_commas(buf2);
03500 snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",control_statement_count, buf2);
03501 switch_test->app = strdup("Goto");
03502 switch_test->appargs = strdup(buf1);
03503 snprintf(buf1,sizeof(buf1),"Finish switch-%s-%d", label, control_statement_count);
03504 switch_end->app = strdup("NoOp");
03505 switch_end->appargs = strdup(buf1);
03506 switch_end->origin = p;
03507 switch_end->exten = exten;
03508
03509 linkprio(exten, switch_test, mother_exten);
03510 linkprio(exten, switch_end, mother_exten);
03511
03512 exten->loop_break = switch_end;
03513 exten->loop_continue = 0;
03514 default_exists = 0;
03515
03516 for (p2=p->u2.statements; p2; p2=p2->next) {
03517
03518 if (p2->type == PV_CASE) {
03519
03520 switch_case = new_exten();
03521 if (mother_exten && mother_exten->checked_switch) {
03522 switch_case->has_switch = mother_exten->has_switch;
03523 switch_case->checked_switch = mother_exten->checked_switch;
03524 }
03525 if (exten && exten->checked_switch) {
03526 switch_case->has_switch = exten->has_switch;
03527 switch_case->checked_switch = exten->checked_switch;
03528 }
03529 switch_case->context = this_context;
03530 switch_case->is_switch = 1;
03531
03532 switch_case->loop_break = exten->loop_break;
03533 switch_case->loop_continue = exten->loop_continue;
03534
03535 linkexten(exten,switch_case);
03536 strncpy(buf2,p2->u1.str,sizeof(buf2));
03537 buf2[sizeof(buf2)-1] = 0;
03538 substitute_commas(buf2);
03539 snprintf(buf1,sizeof(buf1),"sw-%d-%s", local_control_statement_count, buf2);
03540 switch_case->name = strdup(buf1);
03541 snprintf(new_label,sizeof(new_label),"sw-%s-%s-%d", label, buf2, local_control_statement_count);
03542
03543 gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context);
03544
03545
03546 for (p3=p2->u2.statements; p3; p3=p3->next) {
03547 if (!p3->next)
03548 break;
03549 }
03550
03551 if (!p3 || ( p3->type != PV_GOTO && p3->type != PV_BREAK && p3->type != PV_RETURN) ) {
03552
03553 if (p2->next && p2->next->type == PV_CASE) {
03554 fall_thru = new_prio();
03555 fall_thru->type = AEL_APPCALL;
03556 fall_thru->app = strdup("Goto");
03557 strncpy(buf2,p2->next->u1.str,sizeof(buf2));
03558 buf2[sizeof(buf2)-1] = 0;
03559 substitute_commas(buf2);
03560 snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
03561 fall_thru->appargs = strdup(buf1);
03562 linkprio(switch_case, fall_thru, mother_exten);
03563 } else if (p2->next && p2->next->type == PV_PATTERN) {
03564 fall_thru = new_prio();
03565 fall_thru->type = AEL_APPCALL;
03566 fall_thru->app = strdup("Goto");
03567 gen_match_to_pattern(p2->next->u1.str, buf2);
03568 substitute_commas(buf2);
03569 snprintf(buf1,sizeof(buf1),"sw-%d-%s|10", local_control_statement_count, buf2);
03570 fall_thru->appargs = strdup(buf1);
03571 linkprio(switch_case, fall_thru, mother_exten);
03572 } else if (p2->next && p2->next->type == PV_DEFAULT) {
03573 fall_thru = new_prio();
03574 fall_thru->type = AEL_APPCALL;
03575 fall_thru->app = strdup("Goto");
03576 snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
03577 fall_thru->appargs = strdup(buf1);
03578 linkprio(switch_case, fall_thru, mother_exten);
03579 } else if (!p2->next) {
03580 fall_thru = new_prio();
03581 fall_thru->type = AEL_CONTROL1;
03582 fall_thru->goto_true = switch_end;
03583 fall_thru->app = strdup("Goto");
03584 linkprio(switch_case, fall_thru, mother_exten);
03585 }
03586 }
03587 if (switch_case->return_needed) {
03588 char buf[2000];
03589 struct ael_priority *np2 = new_prio();
03590 np2->type = AEL_APPCALL;
03591 np2->app = strdup("NoOp");
03592 snprintf(buf,sizeof(buf),"End of Extension %s", switch_case->name);
03593 np2->appargs = strdup(buf);
03594 linkprio(switch_case, np2, mother_exten);
03595 switch_case-> return_target = np2;
03596 }
03597 } else if (p2->type == PV_PATTERN) {
03598
03599 switch_case = new_exten();
03600 if (mother_exten && mother_exten->checked_switch) {
03601 switch_case->has_switch = mother_exten->has_switch;
03602 switch_case->checked_switch = mother_exten->checked_switch;
03603 }
03604 if (exten && exten->checked_switch) {
03605 switch_case->has_switch = exten->has_switch;
03606 switch_case->checked_switch = exten->checked_switch;
03607 }
03608 switch_case->context = this_context;
03609 switch_case->is_switch = 1;
03610
03611 switch_case->loop_break = exten->loop_break;
03612 switch_case->loop_continue = exten->loop_continue;
03613
03614 linkexten(exten,switch_case);
03615 strncpy(buf2,p2->u1.str,sizeof(buf2));
03616 buf2[sizeof(buf2)-1] = 0;
03617 substitute_commas(buf2);
03618 snprintf(buf1,sizeof(buf1),"_sw-%d-%s", local_control_statement_count, buf2);
03619 switch_case->name = strdup(buf1);
03620 snprintf(new_label,sizeof(new_label),"sw-%s-%s-%d", label, buf2, local_control_statement_count);
03621
03622 gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context);
03623
03624 for (p3=p2->u2.statements; p3; p3=p3->next) {
03625 if (!p3->next)
03626 break;
03627 }
03628
03629 if (!p3 || ( p3->type != PV_GOTO && p3->type != PV_BREAK && p3->type != PV_RETURN)) {
03630
03631 if (p2->next && p2->next->type == PV_CASE) {
03632 fall_thru = new_prio();
03633 fall_thru->type = AEL_APPCALL;
03634 fall_thru->app = strdup("Goto");
03635 strncpy(buf2,p2->next->u1.str,sizeof(buf2));
03636 buf2[sizeof(buf2)-1] = 0;
03637 substitute_commas(buf2);
03638 snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
03639 fall_thru->appargs = strdup(buf1);
03640 linkprio(switch_case, fall_thru, mother_exten);
03641 } else if (p2->next && p2->next->type == PV_PATTERN) {
03642 fall_thru = new_prio();
03643 fall_thru->type = AEL_APPCALL;
03644 fall_thru->app = strdup("Goto");
03645 gen_match_to_pattern(p2->next->u1.str, buf2);
03646 substitute_commas(buf2);
03647 snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
03648 fall_thru->appargs = strdup(buf1);
03649 linkprio(switch_case, fall_thru, mother_exten);
03650 } else if (p2->next && p2->next->type == PV_DEFAULT) {
03651 fall_thru = new_prio();
03652 fall_thru->type = AEL_APPCALL;
03653 fall_thru->app = strdup("Goto");
03654 snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
03655 fall_thru->appargs = strdup(buf1);
03656 linkprio(switch_case, fall_thru, mother_exten);
03657 } else if (!p2->next) {
03658 fall_thru = new_prio();
03659 fall_thru->type = AEL_CONTROL1;
03660 fall_thru->goto_true = switch_end;
03661 fall_thru->app = strdup("Goto");
03662 linkprio(switch_case, fall_thru, mother_exten);
03663 }
03664 }
03665 if (switch_case->return_needed) {
03666 char buf[2000];
03667 struct ael_priority *np2 = new_prio();
03668 np2->type = AEL_APPCALL;
03669 np2->app = strdup("NoOp");
03670 snprintf(buf,sizeof(buf),"End of Extension %s", switch_case->name);
03671 np2->appargs = strdup(buf);
03672 linkprio(switch_case, np2, mother_exten);
03673 switch_case-> return_target = np2;
03674 }
03675 } else if (p2->type == PV_DEFAULT) {
03676
03677 switch_case = new_exten();
03678 if (mother_exten && mother_exten->checked_switch) {
03679 switch_case->has_switch = mother_exten->has_switch;
03680 switch_case->checked_switch = mother_exten->checked_switch;
03681 }
03682 if (exten && exten->checked_switch) {
03683 switch_case->has_switch = exten->has_switch;
03684 switch_case->checked_switch = exten->checked_switch;
03685 }
03686 switch_case->context = this_context;
03687 switch_case->is_switch = 1;
03688
03689
03690
03691
03692
03693 default_exists++;
03694 switch_null = new_exten();
03695 if (mother_exten && mother_exten->checked_switch) {
03696 switch_null->has_switch = mother_exten->has_switch;
03697 switch_null->checked_switch = mother_exten->checked_switch;
03698 }
03699 if (exten && exten->checked_switch) {
03700 switch_null->has_switch = exten->has_switch;
03701 switch_null->checked_switch = exten->checked_switch;
03702 }
03703 switch_null->context = this_context;
03704 switch_null->is_switch = 1;
03705 switch_empty = new_prio();
03706 snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
03707 switch_empty->app = strdup("Goto");
03708 switch_empty->appargs = strdup(buf1);
03709 linkprio(switch_null, switch_empty, mother_exten);
03710 snprintf(buf1,sizeof(buf1),"sw-%d-", local_control_statement_count);
03711 switch_null->name = strdup(buf1);
03712 switch_null->loop_break = exten->loop_break;
03713 switch_null->loop_continue = exten->loop_continue;
03714 linkexten(exten,switch_null);
03715
03716
03717 switch_case->loop_break = exten->loop_break;
03718 switch_case->loop_continue = exten->loop_continue;
03719 linkexten(exten,switch_case);
03720 snprintf(buf1,sizeof(buf1),"_sw-%d-.", local_control_statement_count);
03721 switch_case->name = strdup(buf1);
03722
03723 snprintf(new_label,sizeof(new_label),"sw-%s-default-%d", label, local_control_statement_count);
03724
03725 gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context);
03726
03727
03728 for (p3=p2->u2.statements; p3; p3=p3->next) {
03729 if (!p3->next)
03730 break;
03731 }
03732
03733 if (!p3 || (p3->type != PV_GOTO && p3->type != PV_BREAK && p3->type != PV_RETURN)) {
03734
03735 if (p2->next && p2->next->type == PV_CASE) {
03736 fall_thru = new_prio();
03737 fall_thru->type = AEL_APPCALL;
03738 fall_thru->app = strdup("Goto");
03739 strncpy(buf2,p2->next->u1.str,sizeof(buf2));
03740 buf2[sizeof(buf2)-1] = 0;
03741 substitute_commas(buf2);
03742 snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
03743 fall_thru->appargs = strdup(buf1);
03744 linkprio(switch_case, fall_thru, mother_exten);
03745 } else if (p2->next && p2->next->type == PV_PATTERN) {
03746 fall_thru = new_prio();
03747 fall_thru->type = AEL_APPCALL;
03748 fall_thru->app = strdup("Goto");
03749 gen_match_to_pattern(p2->next->u1.str, buf2);
03750 substitute_commas(buf2);
03751 snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
03752 fall_thru->appargs = strdup(buf1);
03753 linkprio(switch_case, fall_thru, mother_exten);
03754 } else if (p2->next && p2->next->type == PV_DEFAULT) {
03755 fall_thru = new_prio();
03756 fall_thru->type = AEL_APPCALL;
03757 fall_thru->app = strdup("Goto");
03758 snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
03759 fall_thru->appargs = strdup(buf1);
03760 linkprio(switch_case, fall_thru, mother_exten);
03761 } else if (!p2->next) {
03762 fall_thru = new_prio();
03763 fall_thru->type = AEL_CONTROL1;
03764 fall_thru->goto_true = switch_end;
03765 fall_thru->app = strdup("Goto");
03766 linkprio(switch_case, fall_thru, mother_exten);
03767 }
03768 }
03769 if (switch_case->return_needed) {
03770 char buf[2000];
03771 struct ael_priority *np2 = new_prio();
03772 np2->type = AEL_APPCALL;
03773 np2->app = strdup("NoOp");
03774 snprintf(buf,sizeof(buf),"End of Extension %s", switch_case->name);
03775 np2->appargs = strdup(buf);
03776 linkprio(switch_case, np2, mother_exten);
03777 switch_case-> return_target = np2;
03778 }
03779 } else {
03780
03781 }
03782 }
03783
03784 exten->loop_break = loop_break_save;
03785 exten->loop_continue = loop_continue_save;
03786 switch_test->origin = p;
03787 switch_end->origin = p;
03788 break;
03789
03790 case PV_MACRO_CALL:
03791 pr = new_prio();
03792 pr->type = AEL_APPCALL;
03793 snprintf(buf1,sizeof(buf1),"%s", p->u1.str);
03794 for (p2 = p->u2.arglist; p2; p2 = p2->next) {
03795 strcat(buf1,"|");
03796 strcat(buf1,p2->u1.str);
03797 }
03798 pr->app = strdup("Macro");
03799 pr->appargs = strdup(buf1);
03800 pr->origin = p;
03801 linkprio(exten, pr, mother_exten);
03802 break;
03803
03804 case PV_APPLICATION_CALL:
03805 pr = new_prio();
03806 pr->type = AEL_APPCALL;
03807 buf1[0] = 0;
03808 for (p2 = p->u2.arglist; p2; p2 = p2->next) {
03809 if (p2 != p->u2.arglist )
03810 strcat(buf1,"|");
03811 substitute_commas(p2->u1.str);
03812 strcat(buf1,p2->u1.str);
03813 }
03814 pr->app = strdup(p->u1.str);
03815 pr->appargs = strdup(buf1);
03816 pr->origin = p;
03817 linkprio(exten, pr, mother_exten);
03818 break;
03819
03820 case PV_BREAK:
03821 pr = new_prio();
03822 pr->type = AEL_CONTROL1;
03823 pr->goto_true = exten->loop_break;
03824 pr->origin = p;
03825 linkprio(exten, pr, mother_exten);
03826 break;
03827
03828 case PV_RETURN:
03829 pr = new_prio();
03830 pr->type = AEL_RETURN;
03831 exten->return_needed++;
03832 pr->app = strdup("Goto");
03833 pr->appargs = strdup("");
03834 pr->origin = p;
03835 linkprio(exten, pr, mother_exten);
03836 break;
03837
03838 case PV_CONTINUE:
03839 pr = new_prio();
03840 pr->type = AEL_CONTROL1;
03841 pr->goto_true = exten->loop_continue;
03842 pr->origin = p;
03843 linkprio(exten, pr, mother_exten);
03844 break;
03845
03846 #ifdef OLD_RAND_ACTION
03847 case PV_RANDOM:
03848 control_statement_count++;
03849 snprintf(new_label,sizeof(new_label),"rand-%s-%d", label, control_statement_count);
03850 rand_test = new_prio();
03851 rand_test->type = AEL_RAND_CONTROL;
03852 snprintf(buf1,sizeof(buf1),"$[%s]",
03853 p->u1.str );
03854 rand_test->app = 0;
03855 rand_test->appargs = strdup(buf1);
03856 rand_test->origin = p;
03857
03858 rand_end = new_prio();
03859 rand_end->type = AEL_APPCALL;
03860 snprintf(buf1,sizeof(buf1),"Finish rand-%s-%d", label, control_statement_count);
03861 rand_end->app = strdup("NoOp");
03862 rand_end->appargs = strdup(buf1);
03863
03864 rand_skip = new_prio();
03865 rand_skip->type = AEL_CONTROL1;
03866 rand_skip->goto_true = rand_end;
03867 rand_skip->origin = p;
03868
03869 rand_test->goto_true = rand_skip;
03870
03871 linkprio(exten, rand_test, mother_exten);
03872
03873 if (p->u3.else_statements) {
03874 gen_prios(exten, new_label, p->u3.else_statements, mother_exten, this_context);
03875 }
03876
03877 linkprio(exten, rand_skip, mother_exten);
03878
03879 gen_prios(exten, new_label, p->u2.statements, mother_exten, this_context);
03880
03881 linkprio(exten, rand_end, mother_exten);
03882
03883 break;
03884 #endif
03885
03886 case PV_IFTIME:
03887 control_statement_count++;
03888 snprintf(new_label,sizeof(new_label),"iftime-%s-%d", label, control_statement_count);
03889
03890 if_test = new_prio();
03891 if_test->type = AEL_IFTIME_CONTROL;
03892 snprintf(buf1,sizeof(buf1),"%s|%s|%s|%s",
03893 p->u1.list->u1.str,
03894 p->u1.list->next->u1.str,
03895 p->u1.list->next->next->u1.str,
03896 p->u1.list->next->next->next->u1.str);
03897 if_test->app = 0;
03898 if_test->appargs = strdup(buf1);
03899 if_test->origin = p;
03900
03901 if_end = new_prio();
03902 if_end->type = AEL_APPCALL;
03903 snprintf(buf1,sizeof(buf1),"Finish iftime-%s-%d", label, control_statement_count);
03904 if_end->app = strdup("NoOp");
03905 if_end->appargs = strdup(buf1);
03906
03907 if (p->u3.else_statements) {
03908 if_skip = new_prio();
03909 if_skip->type = AEL_CONTROL1;
03910 if_skip->goto_true = if_end;
03911 if_skip->origin = p;
03912
03913 } else {
03914 if_skip = 0;
03915
03916 if_test->goto_false = if_end;
03917 }
03918
03919 if_false = new_prio();
03920 if_false->type = AEL_CONTROL1;
03921 if (p->u3.else_statements) {
03922 if_false->goto_true = if_skip;
03923 } else {
03924 if_false->goto_true = if_end;
03925 }
03926
03927
03928 linkprio(exten, if_test, mother_exten);
03929 linkprio(exten, if_false, mother_exten);
03930
03931
03932
03933 gen_prios(exten, new_label, p->u2.statements, mother_exten, this_context);
03934
03935 if (p->u3.else_statements) {
03936 linkprio(exten, if_skip, mother_exten);
03937 gen_prios(exten, new_label, p->u3.else_statements, mother_exten, this_context);
03938
03939 }
03940
03941 linkprio(exten, if_end, mother_exten);
03942
03943 break;
03944
03945 case PV_RANDOM:
03946 case PV_IF:
03947 control_statement_count++;
03948 snprintf(new_label,sizeof(new_label),"if-%s-%d", label, control_statement_count);
03949
03950 if_test = new_prio();
03951 if_end = new_prio();
03952 if_test->type = AEL_IF_CONTROL;
03953 if_end->type = AEL_APPCALL;
03954 if ( p->type == PV_RANDOM )
03955 snprintf(buf1,sizeof(buf1),"$[${RAND(0|99)} < (%s)]",p->u1.str);
03956 else {
03957 char buf[8000];
03958 strcpy(buf,p->u1.str);
03959 substitute_commas(buf);
03960 snprintf(buf1,sizeof(buf1),"$[%s]",buf);
03961 }
03962
03963 if_test->app = 0;
03964 if_test->appargs = strdup(buf1);
03965 snprintf(buf1,sizeof(buf1),"Finish if-%s-%d", label, control_statement_count);
03966 if_end->app = strdup("NoOp");
03967 if_end->appargs = strdup(buf1);
03968 if_test->origin = p;
03969
03970 if (p->u3.else_statements) {
03971 if_skip = new_prio();
03972 if_skip->type = AEL_CONTROL1;
03973 if_skip->goto_true = if_end;
03974 if_test->goto_false = if_skip;;
03975 } else {
03976 if_skip = 0;
03977 if_test->goto_false = if_end;;
03978 }
03979
03980
03981 linkprio(exten, if_test, mother_exten);
03982
03983
03984
03985 gen_prios(exten, new_label, p->u2.statements, mother_exten, this_context);
03986
03987 if (p->u3.else_statements) {
03988 linkprio(exten, if_skip, mother_exten);
03989 gen_prios(exten, new_label, p->u3.else_statements, mother_exten, this_context);
03990
03991 }
03992
03993 linkprio(exten, if_end, mother_exten);
03994
03995 break;
03996
03997 case PV_STATEMENTBLOCK:
03998 gen_prios(exten, label, p->u1.list, mother_exten, this_context );
03999 break;
04000
04001 case PV_CATCH:
04002 control_statement_count++;
04003
04004
04005 switch_case = new_exten();
04006 if (mother_exten && mother_exten->checked_switch) {
04007 switch_case->has_switch = mother_exten->has_switch;
04008 switch_case->checked_switch = mother_exten->checked_switch;
04009 }
04010 if (exten && exten->checked_switch) {
04011 switch_case->has_switch = exten->has_switch;
04012 switch_case->checked_switch = exten->checked_switch;
04013 }
04014
04015 switch_case->context = this_context;
04016 linkexten(exten,switch_case);
04017 switch_case->name = strdup(p->u1.str);
04018 snprintf(new_label,sizeof(new_label),"catch-%s-%d",p->u1.str, control_statement_count);
04019
04020 gen_prios(switch_case, new_label, p->u2.statements,mother_exten,this_context);
04021 if (switch_case->return_needed) {
04022 char buf[2000];
04023 struct ael_priority *np2 = new_prio();
04024 np2->type = AEL_APPCALL;
04025 np2->app = strdup("NoOp");
04026 snprintf(buf,sizeof(buf),"End of Extension %s", switch_case->name);
04027 np2->appargs = strdup(buf);
04028 linkprio(switch_case, np2, mother_exten);
04029 switch_case-> return_target = np2;
04030 }
04031
04032 break;
04033 default:
04034 break;
04035 }
04036 }
04037 }
04038
04039 void set_priorities(struct ael_extension *exten)
04040 {
04041 int i;
04042 struct ael_priority *pr;
04043 do {
04044 if (exten->is_switch)
04045 i = 10;
04046 else if (exten->regexten)
04047 i=2;
04048 else
04049 i=1;
04050
04051 for (pr=exten->plist; pr; pr=pr->next) {
04052 pr->priority_num = i;
04053
04054 if (!pr->origin || (pr->origin && pr->origin->type != PV_LABEL) )
04055
04056
04057
04058 i++;
04059 }
04060
04061 exten = exten->next_exten;
04062 } while ( exten );
04063 }
04064
04065 void add_extensions(struct ael_extension *exten)
04066 {
04067 struct ael_priority *pr;
04068 char *label=0;
04069 char realext[AST_MAX_EXTENSION];
04070 if (!exten) {
04071 ast_log(LOG_WARNING, "This file is Empty!\n" );
04072 return;
04073 }
04074 do {
04075 struct ael_priority *last = 0;
04076
04077 memset(realext, '\0', sizeof(realext));
04078 pbx_substitute_variables_helper(NULL, exten->name, realext, sizeof(realext) - 1);
04079 if (exten->hints) {
04080 if (ast_add_extension2(exten->context, 0 , realext, PRIORITY_HINT, NULL, exten->cidmatch,
04081 exten->hints, NULL, ast_free, registrar)) {
04082 ast_log(LOG_WARNING, "Unable to add step at priority 'hint' of extension '%s'\n",
04083 exten->name);
04084 }
04085 }
04086
04087 for (pr=exten->plist; pr; pr=pr->next) {
04088 char app[2000];
04089 char appargs[2000];
04090
04091
04092
04093
04094 if (pr->type == AEL_LABEL) {
04095 last = pr;
04096 continue;
04097 }
04098
04099 if (pr->app)
04100 strcpy(app, pr->app);
04101 else
04102 app[0] = 0;
04103 if (pr->appargs )
04104 strcpy(appargs, pr->appargs);
04105 else
04106 appargs[0] = 0;
04107 switch( pr->type ) {
04108 case AEL_APPCALL:
04109
04110 break;
04111
04112 case AEL_CONTROL1:
04113
04114 strcpy(app,"Goto");
04115 if (pr->goto_true->origin && pr->goto_true->origin->type == PV_SWITCH ) {
04116 snprintf(appargs,sizeof(appargs),"%s|%d", pr->goto_true->exten->name, pr->goto_true->priority_num);
04117 } else if (pr->goto_true->origin && pr->goto_true->origin->type == PV_IFTIME && pr->goto_true->origin->u3.else_statements ) {
04118 snprintf(appargs,sizeof(appargs),"%d", pr->goto_true->priority_num+1);
04119 } else
04120 snprintf(appargs,sizeof(appargs),"%d", pr->goto_true->priority_num);
04121 break;
04122
04123 case AEL_FOR_CONTROL:
04124 strcpy(app,"GotoIf");
04125 snprintf(appargs,sizeof(appargs),"%s?%d:%d", pr->appargs, pr->priority_num+1, pr->goto_false->priority_num);
04126 break;
04127
04128 case AEL_IF_CONTROL:
04129 strcpy(app,"GotoIf");
04130 if (pr->origin->u3.else_statements )
04131 snprintf(appargs,sizeof(appargs),"%s?%d:%d", pr->appargs, pr->priority_num+1, pr->goto_false->priority_num+1);
04132 else
04133 snprintf(appargs,sizeof(appargs),"%s?%d:%d", pr->appargs, pr->priority_num+1, pr->goto_false->priority_num);
04134 break;
04135
04136 case AEL_RAND_CONTROL:
04137 strcpy(app,"Random");
04138 snprintf(appargs,sizeof(appargs),"%s:%d", pr->appargs, pr->goto_true->priority_num+1);
04139 break;
04140
04141 case AEL_IFTIME_CONTROL:
04142 strcpy(app,"GotoIfTime");
04143 snprintf(appargs,sizeof(appargs),"%s?%d", pr->appargs, pr->priority_num+2);
04144 break;
04145
04146 case AEL_RETURN:
04147 strcpy(app,"Goto");
04148 snprintf(appargs,sizeof(appargs), "%d", exten->return_target->priority_num);
04149 break;
04150
04151 default:
04152 break;
04153 }
04154 if (last && last->type == AEL_LABEL ) {
04155 label = last->origin->u1.str;
04156 }
04157 else
04158 label = 0;
04159
04160 if (ast_add_extension2(exten->context, 0 , realext, pr->priority_num, (label?label:NULL), exten->cidmatch,
04161 app, strdup(appargs), ast_free, registrar)) {
04162 ast_log(LOG_WARNING, "Unable to add step at priority '%d' of extension '%s'\n", pr->priority_num,
04163 exten->name);
04164 }
04165 last = pr;
04166 }
04167 exten = exten->next_exten;
04168 } while ( exten );
04169 }
04170
04171 static void attach_exten(struct ael_extension **list, struct ael_extension *newmem)
04172 {
04173
04174 struct ael_extension *lptr;
04175 if( !*list ) {
04176 *list = newmem;
04177 return;
04178 }
04179 lptr = *list;
04180
04181 while( lptr->next_exten ) {
04182 lptr = lptr->next_exten;
04183 }
04184
04185 lptr->next_exten = newmem;
04186 }
04187
04188 static pval *get_extension_or_contxt(pval *p)
04189 {
04190 while( p && p->type != PV_EXTENSION && p->type != PV_CONTEXT && p->type != PV_MACRO ) {
04191
04192 p = p->dad;
04193 }
04194
04195 return p;
04196 }
04197
04198 static pval *get_contxt(pval *p)
04199 {
04200 while( p && p->type != PV_CONTEXT && p->type != PV_MACRO ) {
04201
04202 p = p->dad;
04203 }
04204
04205 return p;
04206 }
04207
04208 static void fix_gotos_in_extensions(struct ael_extension *exten)
04209 {
04210 struct ael_extension *e;
04211 for(e=exten;e;e=e->next_exten) {
04212
04213 struct ael_priority *p;
04214 for(p=e->plist;p;p=p->next) {
04215
04216 if( p->origin && p->origin->type == PV_GOTO && p->origin->u3.goto_target_in_case ) {
04217
04218
04219
04220 pval *target = p->origin->u2.goto_target;
04221 struct ael_extension *z = target->u3.compiled_label;
04222 pval *pv2 = p->origin;
04223 char buf1[500];
04224 char *apparg_save = p->appargs;
04225
04226 p->appargs = 0;
04227 if (!pv2->u1.list->next) {
04228 snprintf(buf1,sizeof(buf1),"%s|%s", z->name, pv2->u1.list->u1.str);
04229 p->appargs = strdup(buf1);
04230
04231 } else if (pv2->u1.list->next && !pv2->u1.list->next->next) {
04232 snprintf(buf1,sizeof(buf1),"%s|%s", z->name, pv2->u1.list->next->u1.str);
04233 p->appargs = strdup(buf1);
04234 } else if (pv2->u1.list->next && pv2->u1.list->next->next) {
04235 snprintf(buf1,sizeof(buf1),"%s|%s|%s", pv2->u1.list->u1.str,
04236 z->name,
04237 pv2->u1.list->next->next->u1.str);
04238 p->appargs = strdup(buf1);
04239 }
04240 else
04241 printf("WHAT? The goto doesn't fall into one of three cases for GOTO????\n");
04242
04243 if( apparg_save ) {
04244 free(apparg_save);
04245 }
04246 }
04247 }
04248 }
04249 }
04250
04251
04252 void ast_compile_ael2(struct ast_context **local_contexts, struct pval *root)
04253 {
04254 pval *p,*p2;
04255 struct ast_context *context;
04256 char buf[2000];
04257 struct ael_extension *exten;
04258 struct ael_extension *exten_list = 0;
04259
04260 for (p=root; p; p=p->next ) {
04261
04262 switch (p->type) {
04263 case PV_GLOBALS:
04264
04265 for (p2=p->u1.list; p2; p2=p2->next) {
04266 char buf2[2000];
04267 snprintf(buf2,sizeof(buf2),"%s=%s", p2->u1.str, p2->u2.val);
04268 pbx_builtin_setvar(NULL, buf2);
04269 }
04270 break;
04271 default:
04272 break;
04273 }
04274 }
04275
04276 for (p=root; p; p=p->next ) {
04277 pval *lp;
04278 int argc;
04279
04280 switch (p->type) {
04281 case PV_MACRO:
04282 strcpy(buf,"macro-");
04283 strcat(buf,p->u1.str);
04284 context = ast_context_create(local_contexts, buf, registrar);
04285
04286 exten = new_exten();
04287 exten->context = context;
04288 exten->name = strdup("s");
04289 argc = 1;
04290 for (lp=p->u2.arglist; lp; lp=lp->next) {
04291
04292 struct ael_priority *np2 = new_prio();
04293 np2->type = AEL_APPCALL;
04294 np2->app = strdup("Set");
04295 snprintf(buf,sizeof(buf),"%s=${ARG%d}", lp->u1.str, argc++);
04296 remove_spaces_before_equals(buf);
04297 np2->appargs = strdup(buf);
04298 linkprio(exten, np2, NULL);
04299 }
04300
04301 for (p2=p->u3.macro_statements; p2; p2=p2->next) {
04302 pval *p3;
04303
04304 switch (p2->type) {
04305 case PV_INCLUDES:
04306 for (p3 = p2->u1.list; p3 ;p3=p3->next) {
04307 if ( p3->u2.arglist ) {
04308 snprintf(buf,sizeof(buf), "%s|%s|%s|%s|%s",
04309 p3->u1.str,
04310 p3->u2.arglist->u1.str,
04311 p3->u2.arglist->next->u1.str,
04312 p3->u2.arglist->next->next->u1.str,
04313 p3->u2.arglist->next->next->next->u1.str);
04314 ast_context_add_include2(context, buf, registrar);
04315 } else
04316 ast_context_add_include2(context, p3->u1.str, registrar);
04317 }
04318 break;
04319 default:
04320 break;
04321 }
04322 }
04323
04324 gen_prios(exten, p->u1.str, p->u3.macro_statements, 0, context );
04325 if (exten->return_needed) {
04326 struct ael_priority *np2 = new_prio();
04327 np2->type = AEL_APPCALL;
04328 np2->app = strdup("NoOp");
04329 snprintf(buf,sizeof(buf),"End of Macro %s-%s",p->u1.str, exten->name);
04330 np2->appargs = strdup(buf);
04331 linkprio(exten, np2, NULL);
04332 exten-> return_target = np2;
04333 }
04334
04335 set_priorities(exten);
04336 attach_exten(&exten_list, exten);
04337 break;
04338
04339 case PV_GLOBALS:
04340
04341 break;
04342
04343 case PV_CONTEXT:
04344 context = ast_context_find_or_create(local_contexts, p->u1.str, registrar);
04345
04346
04347 for (p2=p->u2.statements; p2; p2=p2->next) {
04348 pval *p3;
04349 char *s3;
04350
04351 switch (p2->type) {
04352 case PV_EXTENSION:
04353 exten = new_exten();
04354 exten->name = strdup(p2->u1.str);
04355 exten->context = context;
04356
04357 if( (s3=strchr(exten->name, '/') ) != 0 )
04358 {
04359 *s3 = 0;
04360 exten->cidmatch = s3+1;
04361 }
04362
04363 if ( p2->u3.hints )
04364 exten->hints = strdup(p2->u3.hints);
04365 exten->regexten = p2->u4.regexten;
04366 gen_prios(exten, p->u1.str, p2->u2.statements, 0, context );
04367 if (exten->return_needed) {
04368 struct ael_priority *np2 = new_prio();
04369 np2->type = AEL_APPCALL;
04370 np2->app = strdup("NoOp");
04371 snprintf(buf,sizeof(buf),"End of Extension %s", exten->name);
04372 np2->appargs = strdup(buf);
04373 linkprio(exten, np2, NULL);
04374 exten-> return_target = np2;
04375 }
04376
04377 if ( exten->plist_last && exten->plist_last->type == AEL_LABEL ) {
04378 struct ael_priority *np2 = new_prio();
04379 np2->type = AEL_APPCALL;
04380 np2->app = strdup("NoOp");
04381 snprintf(buf,sizeof(buf),"A NoOp to follow a trailing label %s", exten->plist_last->origin->u1.str);
04382 np2->appargs = strdup(buf);
04383 linkprio(exten, np2, NULL);
04384 }
04385
04386 set_priorities(exten);
04387 attach_exten(&exten_list, exten);
04388 break;
04389
04390 case PV_IGNOREPAT:
04391 ast_context_add_ignorepat2(context, p2->u1.str, registrar);
04392 break;
04393
04394 case PV_INCLUDES:
04395 for (p3 = p2->u1.list; p3 ;p3=p3->next) {
04396 if ( p3->u2.arglist ) {
04397 snprintf(buf,sizeof(buf), "%s|%s|%s|%s|%s",
04398 p3->u1.str,
04399 p3->u2.arglist->u1.str,
04400 p3->u2.arglist->next->u1.str,
04401 p3->u2.arglist->next->next->u1.str,
04402 p3->u2.arglist->next->next->next->u1.str);
04403 ast_context_add_include2(context, buf, registrar);
04404 } else
04405 ast_context_add_include2(context, p3->u1.str, registrar);
04406 }
04407 break;
04408
04409 case PV_SWITCHES:
04410 for (p3 = p2->u1.list; p3 ;p3=p3->next) {
04411 char *c = strchr(p3->u1.str, '/');
04412 if (c) {
04413 *c = '\0';
04414 c++;
04415 } else
04416 c = "";
04417
04418 ast_context_add_switch2(context, p3->u1.str, c, 0, registrar);
04419 }
04420 break;
04421
04422 case PV_ESWITCHES:
04423 for (p3 = p2->u1.list; p3 ;p3=p3->next) {
04424 char *c = strchr(p3->u1.str, '/');
04425 if (c) {
04426 *c = '\0';
04427 c++;
04428 } else
04429 c = "";
04430
04431 ast_context_add_switch2(context, p3->u1.str, c, 1, registrar);
04432 }
04433 break;
04434 default:
04435 break;
04436 }
04437 }
04438
04439 break;
04440
04441 default:
04442
04443 break;
04444
04445 }
04446 }
04447
04448
04449
04450 fix_gotos_in_extensions(exten_list);
04451 add_extensions(exten_list);
04452 destroy_extensions(exten_list);
04453
04454 }
04455
04456
04457 static int aeldebug = 0;
04458
04459
04460
04461
04462
04463 static int pbx_load_module(void)
04464 {
04465 int errs=0, sem_err=0, sem_warn=0, sem_note=0;
04466 char *rfilename;
04467 struct ast_context *local_contexts=NULL, *con;
04468 struct pval *parse_tree;
04469
04470 ast_log(LOG_NOTICE, "Starting AEL load process.\n");
04471 if (config[0] == '/')
04472 rfilename = (char *)config;
04473 else {
04474 rfilename = alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
04475 sprintf(rfilename, "%s/%s", ast_config_AST_CONFIG_DIR, config);
04476 }
04477 ast_log(LOG_NOTICE, "AEL load process: calculated config file name '%s'.\n", rfilename);
04478
04479 if (access(rfilename,R_OK) != 0) {
04480 ast_log(LOG_NOTICE, "File %s not found; AEL declining load\n", rfilename);
04481 return AST_MODULE_LOAD_DECLINE;
04482 }
04483
04484 parse_tree = ael2_parse(rfilename, &errs);
04485 ast_log(LOG_NOTICE, "AEL load process: parsed config file name '%s'.\n", rfilename);
04486 ael2_semantic_check(parse_tree, &sem_err, &sem_warn, &sem_note);
04487 if (errs == 0 && sem_err == 0) {
04488 ast_log(LOG_NOTICE, "AEL load process: checked config file name '%s'.\n", rfilename);
04489 ast_compile_ael2(&local_contexts, parse_tree);
04490 ast_log(LOG_NOTICE, "AEL load process: compiled config file name '%s'.\n", rfilename);
04491
04492 ast_merge_contexts_and_delete(&local_contexts, registrar);
04493 ast_log(LOG_NOTICE, "AEL load process: merged config file name '%s'.\n", rfilename);
04494 for (con = ast_walk_contexts(NULL); con; con = ast_walk_contexts(con))
04495 ast_context_verify_includes(con);
04496 ast_log(LOG_NOTICE, "AEL load process: verified config file name '%s'.\n", rfilename);
04497 } else {
04498 ast_log(LOG_ERROR, "Sorry, but %d syntax errors and %d semantic errors were detected. It doesn't make sense to compile.\n", errs, sem_err);
04499 destroy_pval(parse_tree);
04500 return AST_MODULE_LOAD_DECLINE;
04501 }
04502 destroy_pval(parse_tree);
04503
04504 return AST_MODULE_LOAD_SUCCESS;
04505 }
04506
04507
04508 static int ael2_debug_read(int fd, int argc, char *argv[])
04509 {
04510 aeldebug |= DEBUG_READ;
04511 return 0;
04512 }
04513
04514 static int ael2_debug_tokens(int fd, int argc, char *argv[])
04515 {
04516 aeldebug |= DEBUG_TOKENS;
04517 return 0;
04518 }
04519
04520 static int ael2_debug_macros(int fd, int argc, char *argv[])
04521 {
04522 aeldebug |= DEBUG_MACROS;
04523 return 0;
04524 }
04525
04526 static int ael2_debug_contexts(int fd, int argc, char *argv[])
04527 {
04528 aeldebug |= DEBUG_CONTEXTS;
04529 return 0;
04530 }
04531
04532 static int ael2_no_debug(int fd, int argc, char *argv[])
04533 {
04534 aeldebug = 0;
04535 return 0;
04536 }
04537
04538 static int ael2_reload(int fd, int argc, char *argv[])
04539 {
04540 return (pbx_load_module());
04541 }
04542
04543 static struct ast_cli_entry cli_ael_no_debug = {
04544 { "ael", "no", "debug", NULL },
04545 ael2_no_debug, NULL,
04546 NULL };
04547
04548 static struct ast_cli_entry cli_ael[] = {
04549 { { "ael", "reload", NULL },
04550 ael2_reload, "Reload AEL configuration" },
04551
04552 { { "ael", "debug", "read", NULL },
04553 ael2_debug_read, "Enable AEL read debug (does nothing)" },
04554
04555 { { "ael", "debug", "tokens", NULL },
04556 ael2_debug_tokens, "Enable AEL tokens debug (does nothing)" },
04557
04558 { { "ael", "debug", "macros", NULL },
04559 ael2_debug_macros, "Enable AEL macros debug (does nothing)" },
04560
04561 { { "ael", "debug", "contexts", NULL },
04562 ael2_debug_contexts, "Enable AEL contexts debug (does nothing)" },
04563
04564 { { "ael", "nodebug", NULL },
04565 ael2_no_debug, "Disable AEL debug messages",
04566 NULL, NULL, &cli_ael_no_debug },
04567 };
04568
04569 static int unload_module(void)
04570 {
04571 ast_context_destroy(NULL, registrar);
04572 ast_cli_unregister_multiple(cli_ael, sizeof(cli_ael) / sizeof(struct ast_cli_entry));
04573 return 0;
04574 }
04575
04576 static int load_module(void)
04577 {
04578 ast_cli_register_multiple(cli_ael, sizeof(cli_ael) / sizeof(struct ast_cli_entry));
04579 return (pbx_load_module());
04580 }
04581
04582 static int reload(void)
04583 {
04584 return pbx_load_module();
04585 }
04586
04587 #ifdef STANDALONE_AEL
04588 #define AST_MODULE "ael"
04589 int ael_external_load_module(void);
04590 int ael_external_load_module(void)
04591 {
04592 pbx_load_module();
04593 return 1;
04594 }
04595 #endif
04596
04597 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk Extension Language Compiler",
04598 .load = load_module,
04599 .unload = unload_module,
04600 .reload = reload,
04601 );
04602
04603
04604
04605
04606
04607
04608 void destroy_pval_item(pval *item)
04609 {
04610 if (item == NULL) {
04611 ast_log(LOG_WARNING, "null item\n");
04612 return;
04613 }
04614
04615 if (item->filename)
04616 free(item->filename);
04617
04618 switch (item->type) {
04619 case PV_WORD:
04620
04621 if (item->u1.str )
04622 free(item->u1.str);
04623 if ( item->u2.arglist )
04624 destroy_pval(item->u2.arglist);
04625 break;
04626
04627 case PV_MACRO:
04628
04629
04630
04631
04632
04633
04634
04635 destroy_pval(item->u2.arglist);
04636 if (item->u1.str )
04637 free(item->u1.str);
04638 destroy_pval(item->u3.macro_statements);
04639 break;
04640
04641 case PV_CONTEXT:
04642
04643
04644
04645
04646 if (item->u1.str)
04647 free(item->u1.str);
04648 destroy_pval(item->u2.statements);
04649 break;
04650
04651 case PV_MACRO_CALL:
04652
04653
04654
04655
04656
04657 if (item->u1.str)
04658 free(item->u1.str);
04659 destroy_pval(item->u2.arglist);
04660 break;
04661
04662 case PV_APPLICATION_CALL:
04663
04664
04665
04666
04667
04668 if (item->u1.str)
04669 free(item->u1.str);
04670 destroy_pval(item->u2.arglist);
04671 break;
04672
04673 case PV_CASE:
04674
04675
04676
04677 if (item->u1.str)
04678 free(item->u1.str);
04679 destroy_pval(item->u2.statements);
04680 break;
04681
04682 case PV_PATTERN:
04683
04684
04685
04686 if (item->u1.str)
04687 free(item->u1.str);
04688 destroy_pval(item->u2.statements);
04689 break;
04690
04691 case PV_DEFAULT:
04692
04693
04694
04695 destroy_pval(item->u2.statements);
04696 break;
04697
04698 case PV_CATCH:
04699
04700
04701
04702 if (item->u1.str)
04703 free(item->u1.str);
04704 destroy_pval(item->u2.statements);
04705 break;
04706
04707 case PV_SWITCHES:
04708
04709
04710 destroy_pval(item->u1.list);
04711 break;
04712
04713 case PV_ESWITCHES:
04714
04715
04716 destroy_pval(item->u1.list);
04717 break;
04718
04719 case PV_INCLUDES:
04720
04721
04722
04723 destroy_pval(item->u1.list);
04724 break;
04725
04726 case PV_STATEMENTBLOCK:
04727
04728
04729 destroy_pval(item->u1.list);
04730 break;
04731
04732 case PV_VARDEC:
04733
04734
04735
04736 if (item->u1.str)
04737 free(item->u1.str);
04738 if (item->u2.val)
04739 free(item->u2.val);
04740 break;
04741
04742 case PV_GOTO:
04743
04744
04745
04746
04747 destroy_pval(item->u1.list);
04748 break;
04749
04750 case PV_LABEL:
04751
04752
04753 if (item->u1.str)
04754 free(item->u1.str);
04755 break;
04756
04757 case PV_FOR:
04758
04759
04760
04761
04762
04763
04764 if (item->u1.for_init)
04765 free(item->u1.for_init);
04766 if (item->u2.for_test)
04767 free(item->u2.for_test);
04768 if (item->u3.for_inc)
04769 free(item->u3.for_inc);
04770 destroy_pval(item->u4.for_statements);
04771 break;
04772
04773 case PV_WHILE:
04774
04775
04776
04777
04778 if (item->u1.str)
04779 free(item->u1.str);
04780 destroy_pval(item->u2.statements);
04781 break;
04782
04783 case PV_BREAK:
04784
04785
04786 break;
04787
04788 case PV_RETURN:
04789
04790
04791 break;
04792
04793 case PV_CONTINUE:
04794
04795
04796 break;
04797
04798 case PV_IFTIME:
04799
04800
04801
04802
04803
04804
04805 destroy_pval(item->u1.list);
04806 destroy_pval(item->u2.statements);
04807 if (item->u3.else_statements) {
04808 destroy_pval(item->u3.else_statements);
04809 }
04810 break;
04811
04812 case PV_RANDOM:
04813
04814
04815
04816
04817
04818
04819 case PV_IF:
04820
04821
04822
04823
04824
04825
04826 if (item->u1.str)
04827 free(item->u1.str);
04828 destroy_pval(item->u2.statements);
04829 if (item->u3.else_statements) {
04830 destroy_pval(item->u3.else_statements);
04831 }
04832 break;
04833
04834 case PV_SWITCH:
04835
04836
04837
04838
04839
04840 if (item->u1.str)
04841 free(item->u1.str);
04842 destroy_pval(item->u2.statements);
04843 break;
04844
04845 case PV_EXTENSION:
04846
04847
04848
04849
04850
04851
04852 if (item->u1.str)
04853 free(item->u1.str);
04854 if (item->u3.hints)
04855 free(item->u3.hints);
04856 destroy_pval(item->u2.statements);
04857 break;
04858
04859 case PV_IGNOREPAT:
04860
04861
04862 if (item->u1.str)
04863 free(item->u1.str);
04864 break;
04865
04866 case PV_GLOBALS:
04867
04868
04869 destroy_pval(item->u1.statements);
04870 break;
04871 }
04872 free(item);
04873 }
04874
04875 void destroy_pval(pval *item)
04876 {
04877 pval *i,*nxt;
04878
04879 for (i=item; i; i=nxt) {
04880 nxt = i->next;
04881
04882 destroy_pval_item(i);
04883 }
04884 }
04885
04886 #ifdef AAL_ARGCHECK
04887 static char *ael_funclist[] =
04888 {
04889 "AGENT",
04890 "ARRAY",
04891 "BASE64_DECODE",
04892 "BASE64_ENCODE",
04893 "CALLERID",
04894 "CDR",
04895 "CHANNEL",
04896 "CHECKSIPDOMAIN",
04897 "CHECK_MD5",
04898 "CURL",
04899 "CUT",
04900 "DB",
04901 "DB_EXISTS",
04902 "DUNDILOOKUP",
04903 "ENUMLOOKUP",
04904 "ENV",
04905 "EVAL",
04906 "EXISTS",
04907 "FIELDQTY",
04908 "FILTER",
04909 "GROUP",
04910 "GROUP_COUNT",
04911 "GROUP_LIST",
04912 "GROUP_MATCH_COUNT",
04913 "IAXPEER",
04914 "IF",
04915 "IFTIME",
04916 "ISNULL",
04917 "KEYPADHASH",
04918 "LANGUAGE",
04919 "LEN",
04920 "MATH",
04921 "MD5",
04922 "MUSICCLASS",
04923 "QUEUEAGENTCOUNT",
04924 "QUEUE_MEMBER_COUNT",
04925 "QUEUE_MEMBER_LIST",
04926 "QUOTE",
04927 "RAND",
04928 "REGEX",
04929 "SET",
04930 "SHA1",
04931 "SIPCHANINFO",
04932 "SIPPEER",
04933 "SIP_HEADER",
04934 "SORT",
04935 "STAT",
04936 "STRFTIME",
04937 "STRPTIME",
04938 "TIMEOUT",
04939 "TXTCIDNAME",
04940 "URIDECODE",
04941 "URIENCODE",
04942 "VMCOUNT"
04943 };
04944
04945
04946 int ael_is_funcname(char *name)
04947 {
04948 int s,t;
04949 t = sizeof(ael_funclist)/sizeof(char*);
04950 s = 0;
04951 while ((s < t) && strcasecmp(name, ael_funclist[s]))
04952 s++;
04953 if ( s < t )
04954 return 1;
04955 else
04956 return 0;
04957 }
04958 #endif