Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
if (p && *p == 'j') {
ast_log(LOG_ERROR, "Error: file %s, line %d-%d: The j option in the %s application call is not appropriate for AEL!\n",
is->filename, is->startline, is->endline, app->name);
errs++;
}
if (p) {
*p = '+';
if (ac->name[1] == '(') {
if (*(p+1) != '(') {
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",
is->filename, is->startline, is->endline, ac->name[0], app->name);
warns++;
}
}
}
}
}
for (q=opcop; *q; q++) {
if ( *q != '+' && *q != '(' && *q != ')') {
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",
is->filename, is->startline, is->endline, *q, app->name);
warns++;
}
}
return 1;
break;
default:
return 0;
}
}
int option_matches( struct argdesc *should, pval *is, struct argapp *app)
{
struct argchoice *ac;
char *opcop;
switch (should->dtype) {
case ARGD_STRING:
if (is_empty(is->u1.str) && should->type == ARGD_REQUIRED)
return 0;
if (is->u1.str && strlen(is->u1.str) > 0) /* most will match */
return 1;
break;
case ARGD_INT:
if (is_int(is->u1.str))
return 1;
else
return 0;
break;
case ARGD_FLOAT:
if (is_float(is->u1.str))
return 1;
else
return 0;
break;
case ARGD_ENUM:
if( !is->u1.str || strlen(is->u1.str) == 0 )
return 1; /* a null arg in the call will match an enum, I guess! */
for (ac=should->choices; ac; ac=ac->next) {
if (strcmp(ac->name,is->u1.str) == 0)
return 1;
}
return 0;
break;
case ARGD_OPTIONSET:
opcop = ast_strdupa(is->u1.str);
for (ac=app->opts; ac; ac=ac->next) {
if (strlen(ac->name)>1 && strchr(ac->name,'(') == 0 && strcmp(ac->name,is->u1.str) == 0) /* multichar option, no parens, and a match? */
return 1;
}
for (ac=app->opts; ac; ac=ac->next) {
if (strlen(ac->name)==1 || strchr(ac->name,'(')) {
char *p = strchr(opcop,ac->name[0]); /* wipe out all matched options in the user-supplied string */
if (p) {
*p = '+';
if (ac->name[1] == '(') {
if (*(p+1) == '(') {
char *q = p+1;
while (*q && *q != ')') {
*q++ = '+';
}
*q = '+';
}
}
}
}
}
return 1;
break;
case ARGD_VARARG:
return 1; /* matches anything */
break;
}
return 1; /* unless some for-sure match or non-match returns, then it must be close enough ... */
}
#endif
int check_app_args(pval* appcall, pval *arglist, struct argapp *app)
{
#ifdef AAL_ARGCHECK
struct argdesc *ad = app->args;
pval *pa;
int z;
for (pa = arglist; pa; pa=pa->next) {
if (!ad) {
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Extra argument %s not in application call to %s !\n",
arglist->filename, arglist->startline, arglist->endline, pa->u1.str, app->name);
warns++;
return 1;
} else {
/* find the first entry in the ad list that will match */
do {
if ( ad->dtype == ARGD_VARARG ) /* once we hit the VARARG, all bets are off. Discontinue the comparisons */
break;
z= option_matches( ad, pa, app);
if (!z) {
if ( !arglist )
arglist=appcall;
if (ad->type == ARGD_REQUIRED) {
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
warns++;
return 1;
}
} else if (z && ad->dtype == ARGD_OPTIONSET) {
option_matches_j( ad, pa, app);
}
ad = ad->next;
} while (ad && !z);
}
}
/* any app nodes left, that are not optional? */
for ( ; ad; ad=ad->next) {
if (ad->type == ARGD_REQUIRED && ad->dtype != ARGD_VARARG) {
if ( !arglist )
arglist=appcall;
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: Required argument %s not in application call to %s !\n",
arglist->filename, arglist->startline, arglist->endline, ad->dtype==ARGD_OPTIONSET?"options":ad->name, app->name);
warns++;
return 1;
}
}
return 0;
#else
return 0;
#endif
}
void check_switch_expr(pval *item, struct argapp *apps)
{
#ifdef AAL_ARGCHECK
/* get and clean the variable name */
char *buff1, *p;
struct argapp *a,*a2;
struct appsetvar *v,*v2;
struct argchoice *c;
pval *t;
p = item->u1.str;
while (p && *p && (*p == ' ' || *p == '\t' || *p == '$' || *p == '{' ) )
p++;
buff1 = ast_strdupa(p);
while (strlen(buff1) > 0 && ( buff1[strlen(buff1)-1] == '}' || buff1[strlen(buff1)-1] == ' ' || buff1[strlen(buff1)-1] == '\t'))
buff1[strlen(buff1)-1] = 0;
/* buff1 now contains the variable name */
v = 0;
for (a=apps; a; a=a->next) {
for (v=a->setvars;v;v=v->next) {
if (strcmp(v->name,buff1) == 0) {
break;
}
}
if ( v )
break;
}
if (v && v->vals) {
/* we have a match, to a variable that has a set of determined values */
int def= 0;
int pat = 0;
int f1 = 0;
/* first of all, does this switch have a default case ? */
for (t=item->u2.statements; t; t=t->next) {
if (t->type == PV_DEFAULT) {
def =1;
break;
}
if (t->type == PV_PATTERN) {
pat++;
}
}
if (def || pat) /* nothing to check. All cases accounted for! */
return;
for (c=v->vals; c; c=c->next) {
f1 = 0;
for (t=item->u2.statements; t; t=t->next) {
if (t->type == PV_CASE || t->type == PV_PATTERN) {
if (!strcmp(t->u1.str,c->name)) {
f1 = 1;
break;
}
}
}
if (!f1) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: switch with expression(%s) does not handle the case of %s !\n",
item->filename, item->startline, item->endline, item->u1.str, c->name);
warns++;
}
}
/* next, is there an app call in the current exten, that would set this var? */
f1 = 0;
t = current_extension->u2.statements;
if ( t && t->type == PV_STATEMENTBLOCK )
t = t->u1.statements;
for (; t && t != item; t=t->next) {
if (t->type == PV_APPLICATION_CALL) {
/* find the application that matches the u1.str */
for (a2=apps; a2; a2=a2->next) {
if (strcasecmp(a2->name, t->u1.str)==0) {
for (v2=a2->setvars; v2; v2=v2->next) {
if (strcmp(v2->name, buff1) == 0) {
/* found an app that sets the var */
f1 = 1;
break;
}
}
}
if (f1)
break;
}
}
if (f1)
break;
}
/* see if it sets the var */
if (!f1) {
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",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
}
#else
pval *t,*tl=0,*p2;
int def= 0;
/* first of all, does this switch have a default case ? */
for (t=item->u2.statements; t; t=t->next) {
if (t->type == PV_DEFAULT) {
def =1;
break;
}
tl = t;
}
if (def) /* nothing to check. All cases accounted for! */
return;
/* if no default, warn and insert a default case at the end */
p2 = tl->next = calloc(1, sizeof(struct pval));
p2->type = PV_DEFAULT;
p2->startline = tl->startline;
p2->endline = tl->endline;
p2->startcol = tl->startcol;
p2->endcol = tl->endcol;
p2->filename = strdup(tl->filename);
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: A default case was automatically added to the switch.\n",
p2->filename, p2->startline, p2->endline);
warns++;
#endif
}
static void check_context_names(void)
{
pval *i,*j;
for (i=current_db; i; i=i->next) {
if (i->type == PV_CONTEXT || i->type == PV_MACRO) {
for (j=i->next; j; j=j->next) {
if ( j->type == PV_CONTEXT || j->type == PV_MACRO ) {
if ( !strcmp(i->u1.str, j->u1.str) )
{
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: The context name (%s) is also declared in file %s, line %d-%d!\n",
i->filename, i->startline, i->endline, i->u1.str, j->filename, j->startline, j->endline);
warns++;
}
}
}
}
}
}
static void check_abstract_reference(pval *abstract_context)
{
pval *i,*j;
/* find some context includes that reference this context */
/* otherwise, print out a warning */
for (i=current_db; i; i=i->next) {
if (i->type == PV_CONTEXT) {
for (j=i->u2. statements; j; j=j->next) {
if ( j->type == PV_INCLUDES ) {
struct pval *p4;
for (p4=j->u1.list; p4; p4=p4->next) {
/* for each context pointed to, find it, then find a context/label that matches the
target here! */
if ( !strcmp(p4->u1.str, abstract_context->u1.str) )
return; /* found a match! */
}
}
}
}
}
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",
abstract_context->filename, abstract_context->startline, abstract_context->endline, abstract_context->u1.str);
warns++;
}
void check_pval_item(pval *item, struct argapp *apps, int in_globals)
{
pval *lp;
#ifdef AAL_ARGCHECK
struct argapp *app, *found;
#endif
struct pval *macro_def;
struct pval *app_def;
char errmsg[4096];
char *strp;
switch (item->type) {
case PV_WORD:
/* fields: item->u1.str == string associated with this (word).
item->u2.arglist == pval list of 4 PV_WORD elements for time values (only in PV_INCLUDES) */
break;
case PV_MACRO:
/* fields: item->u1.str == name of macro
item->u2.arglist == pval list of PV_WORD arguments of macro, as given by user
item->u2.arglist->u1.str == argument
item->u2.arglist->next == next arg
item->u3.macro_statements == pval list of statements in macro body.
*/
in_abstract_context = 0;
current_context = item;
current_extension = 0;
check_macro_returns(item);
for (lp=item->u2.arglist; lp; lp=lp->next) {
}
check_pval(item->u3.macro_statements, apps,in_globals);
break;
case PV_CONTEXT:
/* fields: item->u1.str == name of context
item->u2.statements == pval list of statements in context body
item->u3.abstract == int 1 if an abstract keyword were present
*/
current_context = item;
current_extension = 0;
if ( item->u3.abstract ) {
in_abstract_context = 1;
check_abstract_reference(item);
} else
in_abstract_context = 0;
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_MACRO_CALL:
/* fields: item->u1.str == name of macro to call
item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
item->u2.arglist->u1.str == argument
item->u2.arglist->next == next arg
*/
#ifdef STANDALONE
/* if this is a standalone, we will need to make sure the
localized load of extensions.conf is done */
if (!extensions_dot_conf_loaded) {
localized_pbx_load_module();
extensions_dot_conf_loaded++;
}
#endif
macro_def = find_macro(item->u1.str);
if (!macro_def) {
#ifdef STANDALONE
struct pbx_find_info pfiq = {.stacklen = 0 };
struct pbx_find_info pfiq2 = {.stacklen = 0 };
/* look for the macro in the extensions.conf world */
pbx_find_extension(NULL, NULL, &pfiq, item->u1.str, "s", 1, NULL, NULL, E_MATCH);
if (pfiq.status != STATUS_SUCCESS) {
char namebuf2[256];
snprintf(namebuf2, 256, "macro-%s", item->u1.str);
/* look for the macro in the extensions.conf world */
pbx_find_extension(NULL, NULL, &pfiq2, namebuf2, "s", 1, NULL, NULL, E_MATCH);
if (pfiq2.status == STATUS_SUCCESS) {
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: macro call to non-existent %s! (macro-%s was found in the extensions.conf stuff, but we are using gosubs!)\n",
item->filename, item->startline, item->endline, item->u1.str, item->u1.str);
warns++;
} else {
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: macro call to non-existent %s! (Not even in the extensions.conf stuff!)\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
}
#else
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: macro call to %s cannot be found in the AEL code!\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
#endif
#ifdef THIS_IS_1DOT4
char namebuf2[256];
snprintf(namebuf2, 256, "macro-%s", item->u1.str);
/* look for the macro in the extensions.conf world */
pbx_find_extension(NULL, NULL, &pfiq, namebuf2, "s", 1, NULL, NULL, E_MATCH);
if (pfiq.status != STATUS_SUCCESS) {
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: macro call to %s was not found in the AEL, nor the extensions.conf !\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
#endif
} else if (macro_def->type != PV_MACRO) {
ast_log(LOG_ERROR,"Error: file %s, line %d-%d: macro call to %s references a context, not a macro!\n",
item->filename, item->startline, item->endline, item->u1.str);
errs++;
} else {
/* macro_def is a MACRO, so do the args match in number? */
int hereargs = 0;
int thereargs = 0;
for (lp=item->u2.arglist; lp; lp=lp->next) {
hereargs++;
}
for (lp=macro_def->u2.arglist; lp; lp=lp->next) {
thereargs++;
}
if (hereargs != thereargs ) {
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",
item->filename, item->startline, item->endline, item->u1.str, hereargs, thereargs);
errs++;
}
}
break;
case PV_APPLICATION_CALL:
/* fields: item->u1.str == name of application to call
item->u2.arglist == pval list of PV_WORD arguments of macro call, as given by user
item->u2.arglist->u1.str == argument
item->u2.arglist->next == next arg
*/
/* Need to check to see if the application is available! */
app_def = find_context(item->u1.str);
if (app_def && app_def->type == PV_MACRO) {
ast_log(LOG_ERROR,"Error: file %s, line %d-%d: application call to %s references an existing macro, but had no & preceding it!\n",
item->filename, item->startline, item->endline, item->u1.str);
errs++;
}
if (strcasecmp(item->u1.str,"GotoIf") == 0
|| strcasecmp(item->u1.str,"GotoIfTime") == 0
|| strcasecmp(item->u1.str,"while") == 0
|| strcasecmp(item->u1.str,"endwhile") == 0
|| strcasecmp(item->u1.str,"random") == 0
|| strcasecmp(item->u1.str,"gosub") == 0
|| strcasecmp(item->u1.str,"return") == 0
|| strcasecmp(item->u1.str,"gosubif") == 0
|| strcasecmp(item->u1.str,"continuewhile") == 0
|| strcasecmp(item->u1.str,"endwhile") == 0
|| strcasecmp(item->u1.str,"execif") == 0
|| strcasecmp(item->u1.str,"execiftime") == 0
|| strcasecmp(item->u1.str,"exitwhile") == 0
|| strcasecmp(item->u1.str,"goto") == 0
|| strcasecmp(item->u1.str,"macro") == 0
|| strcasecmp(item->u1.str,"macroexclusive") == 0
|| strcasecmp(item->u1.str,"macroif") == 0
|| strcasecmp(item->u1.str,"stackpop") == 0
|| strcasecmp(item->u1.str,"execIf") == 0 ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: application call to %s affects flow of control, and needs to be re-written using AEL if, while, goto, etc. keywords instead!\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
if (strcasecmp(item->u1.str,"macroexit") == 0) {
ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: I am converting the MacroExit call here to a return statement.\n",
item->filename, item->startline, item->endline);
item->type = PV_RETURN;
free(item->u1.str);
item->u1.str = 0;
}
#ifdef AAL_ARGCHECK
found = 0;
for (app=apps; app; app=app->next) {
if (strcasecmp(app->name, item->u1.str) == 0) {
found =app;
break;
}
}
if (!found) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: application call to %s not listed in applist database!\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
} else
check_app_args(item, item->u2.arglist, app);
#endif
break;
case PV_CASE:
/* fields: item->u1.str == value of case
item->u2.statements == pval list of statements under the case
*/
/* Make sure sequence of statements under case is terminated with goto, return, or break */
/* find the last statement */
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_PATTERN:
/* fields: item->u1.str == value of case
item->u2.statements == pval list of statements under the case
*/
/* Make sure sequence of statements under case is terminated with goto, return, or break */
/* find the last statement */
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_DEFAULT:
/* fields:
item->u2.statements == pval list of statements under the case
*/
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_CATCH:
/* fields: item->u1.str == name of extension to catch
item->u2.statements == pval list of statements in context body
*/
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_SWITCHES:
/* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
*/
check_pval(item->u1.list, apps,in_globals);
break;
case PV_ESWITCHES:
/* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
*/
check_pval(item->u1.list, apps,in_globals);
break;
case PV_INCLUDES:
/* fields: item->u1.list == pval list of PV_WORD elements, one per entry in the list
*/
check_pval(item->u1.list, apps,in_globals);
check_includes(item);
for (lp=item->u1.list; lp; lp=lp->next){
char *incl_context = lp->u1.str;
struct pval *that_context = find_context(incl_context);
if ( lp->u2.arglist ) {
check_timerange(lp->u2.arglist);
check_dow(lp->u2.arglist->next);
check_day(lp->u2.arglist->next->next);
check_month(lp->u2.arglist->next->next->next);
}
if (that_context) {
find_pval_gotos(that_context->u2.statements,0);
}
}
break;
case PV_STATEMENTBLOCK:
/* fields: item->u1.list == pval list of statements in block, one per entry in the list
*/
check_pval(item->u1.list, apps,in_globals);
break;
case PV_VARDEC:
/* fields: item->u1.str == variable name
item->u2.val == variable value to assign
*/
/* the RHS of a vardec is encapsulated in a $[] expr. Is it legal? */
if( !in_globals ) { /* don't check stuff inside the globals context; no wrapping in $[ ] there... */
snprintf(errmsg,sizeof(errmsg), "file %s, line %d, columns %d-%d, variable declaration expr '%s':", item->filename, item->startline, item->startcol, item->endcol, item->u2.val);
ast_expr_register_extra_error_info(errmsg);
ast_expr(item->u2.val, expr_output, sizeof(expr_output),NULL);
ast_expr_clear_extra_error_info();
if ( strpbrk(item->u2.val,"~!-+<>=*/&^") && !strstr(item->u2.val,"${") ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
item->filename, item->startline, item->endline, item->u2.val);
warns++;
}
check_expr2_input(item,item->u2.val);
}
break;
case PV_LOCALVARDEC:
/* fields: item->u1.str == variable name
item->u2.val == variable value to assign
*/
/* the RHS of a vardec is encapsulated in a $[] expr. Is it legal? */
snprintf(errmsg,sizeof(errmsg), "file %s, line %d, columns %d-%d, variable declaration expr '%s':", item->filename, item->startline, item->startcol, item->endcol, item->u2.val);
ast_expr_register_extra_error_info(errmsg);
ast_expr(item->u2.val, expr_output, sizeof(expr_output),NULL);
ast_expr_clear_extra_error_info();
if ( strpbrk(item->u2.val,"~!-+<>=*/&^") && !strstr(item->u2.val,"${") ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
item->filename, item->startline, item->endline, item->u2.val);
warns++;
}
check_expr2_input(item,item->u2.val);
break;
case PV_GOTO:
/* fields: item->u1.list == pval list of PV_WORD target names, up to 3, in order as given by user.
item->u1.list->u1.str == where the data on a PV_WORD will always be.
*/
/* don't check goto's in abstract contexts */
if ( in_abstract_context )
break;
check_goto(item);
break;
case PV_LABEL:
/* fields: item->u1.str == label name
*/
if ( strspn(item->u1.str, "0123456789") == strlen(item->u1.str) ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: label '%s' is numeric, this is bad practice!\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
check_label(item);
break;
case PV_FOR:
/* fields: item->u1.for_init == a string containing the initalizer
item->u2.for_test == a string containing the loop test
item->u3.for_inc == a string containing the loop increment
item->u4.for_statements == a pval list of statements in the for ()
*/
snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, for test expr '%s':", item->filename, item->startline, item->startcol, item->endcol, item->u2.for_test);
ast_expr_register_extra_error_info(errmsg);
strp = strchr(item->u1.for_init, '=');
if (strp) {
ast_expr(strp+1, expr_output, sizeof(expr_output),NULL);
}
ast_expr(item->u2.for_test, expr_output, sizeof(expr_output),NULL);
strp = strchr(item->u3.for_inc, '=');
if (strp) {
ast_expr(strp+1, expr_output, sizeof(expr_output),NULL);
}
if ( strpbrk(item->u2.for_test,"~!-+<>=*/&^") && !strstr(item->u2.for_test,"${") ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
item->filename, item->startline, item->endline, item->u2.for_test);
warns++;
}
if ( strpbrk(item->u3.for_inc,"~!-+<>=*/&^") && !strstr(item->u3.for_inc,"${") ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
item->filename, item->startline, item->endline, item->u3.for_inc);
warns++;
}
check_expr2_input(item,item->u2.for_test);
check_expr2_input(item,item->u3.for_inc);
ast_expr_clear_extra_error_info();
check_pval(item->u4.for_statements, apps,in_globals);
break;
case PV_WHILE:
/* fields: item->u1.str == the while conditional, as supplied by user
item->u2.statements == a pval list of statements in the while ()
*/
snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, while expr '%s':", item->filename, item->startline, item->startcol, item->endcol, item->u1.str);
ast_expr_register_extra_error_info(errmsg);
ast_expr(item->u1.str, expr_output, sizeof(expr_output),NULL);
ast_expr_clear_extra_error_info();
if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
check_expr2_input(item,item->u1.str);
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_BREAK:
/* fields: none
*/
check_break(item);
break;
case PV_RETURN:
/* fields: none
*/
break;
case PV_CONTINUE:
/* fields: none
*/
check_continue(item);
break;
case PV_RANDOM:
/* fields: item->u1.str == the random number expression, as supplied by user
item->u2.statements == a pval list of statements in the if ()
item->u3.else_statements == a pval list of statements in the else
(could be zero)
*/
snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, random expr '%s':", item->filename, item->startline, item->startcol, item->endcol, item->u1.str);
ast_expr_register_extra_error_info(errmsg);
ast_expr(item->u1.str, expr_output, sizeof(expr_output),NULL);
ast_expr_clear_extra_error_info();
if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: random expression '%s' has operators, but no variables. Interesting...\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
check_expr2_input(item,item->u1.str);
check_pval(item->u2.statements, apps,in_globals);
if (item->u3.else_statements) {
check_pval(item->u3.else_statements, apps,in_globals);
}
break;
case PV_IFTIME:
/* fields: item->u1.list == the if time values, 4 of them, each in PV_WORD, linked list
item->u2.statements == a pval list of statements in the if ()
item->u3.else_statements == a pval list of statements in the else
(could be zero)
*/
if ( item->u2.arglist ) {
check_timerange(item->u1.list);
check_dow(item->u1.list->next);
check_day(item->u1.list->next->next);
check_month(item->u1.list->next->next->next);
}
check_pval(item->u2.statements, apps,in_globals);
if (item->u3.else_statements) {
check_pval(item->u3.else_statements, apps,in_globals);
}
break;
case PV_IF:
/* fields: item->u1.str == the if conditional, as supplied by user
item->u2.statements == a pval list of statements in the if ()
item->u3.else_statements == a pval list of statements in the else
(could be zero)
*/
snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, if expr '%s':", item->filename, item->startline, item->startcol, item->endcol, item->u1.str);
ast_expr_register_extra_error_info(errmsg);
ast_expr(item->u1.str, expr_output, sizeof(expr_output),NULL);
ast_expr_clear_extra_error_info();
if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: expression '%s' has operators, but no variables. Interesting...\n",
item->filename, item->startline, item->endline, item->u1.str);
warns++;
}
check_expr2_input(item,item->u1.str);
check_pval(item->u2.statements, apps,in_globals);
if (item->u3.else_statements) {
check_pval(item->u3.else_statements, apps,in_globals);
}
break;
case PV_SWITCH:
/* fields: item->u1.str == the switch expression
item->u2.statements == a pval list of statements in the switch,
(will be case statements, most likely!)
*/
/* we can check the switch expression, see if it matches any of the app variables...
if it does, then, are all the possible cases accounted for? */
check_switch_expr(item, apps);
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_EXTENSION:
/* fields: item->u1.str == the extension name, label, whatever it's called
item->u2.statements == a pval list of statements in the extension
item->u3.hints == a char * hint argument
item->u4.regexten == an int boolean. non-zero says that regexten was specified
*/
current_extension = item ;
check_pval(item->u2.statements, apps,in_globals);
break;
case PV_IGNOREPAT:
/* fields: item->u1.str == the ignorepat data
*/
break;
case PV_GLOBALS:
/* fields: item->u1.statements == pval list of statements, usually vardecs
*/
in_abstract_context = 0;
check_pval(item->u1.statements, apps, 1);
break;
default:
break;
}
}
void check_pval(pval *item, struct argapp *apps, int in_globals)
{
pval *i;
/* checks to do:
1. Do goto's point to actual labels?
2. Do macro calls reference a macro?
3. Does the number of macro args match the definition?
4. Is a macro call missing its & at the front?
5. Application calls-- we could check syntax for existing applications,
but I need some some sort of universal description bnf for a general
sort of method for checking arguments, in number, maybe even type, at least.
Don't want to hand code checks for hundreds of applications.
*/
for (i=item; i; i=i->next) {
check_pval_item(i,apps,in_globals);
}
}
void ael2_semantic_check(pval *item, int *arg_errs, int *arg_warns, int *arg_notes)
{
#ifdef AAL_ARGCHECK
int argapp_errs =0;
char *rfilename;
#endif
struct argapp *apps=0;
#ifdef AAL_ARGCHECK
rfilename = alloca(10 + strlen(ast_config_AST_VAR_DIR));
sprintf(rfilename, "%s/applist", ast_config_AST_VAR_DIR);
apps = argdesc_parse(rfilename, &argapp_errs); /* giveth */
#endif
current_db = item;
errs = warns = notes = 0;
check_context_names();
check_pval(item, apps, 0);
#ifdef AAL_ARGCHECK
argdesc_destroy(apps); /* taketh away */
#endif
current_db = 0;
*arg_errs = errs;
*arg_warns = warns;
*arg_notes = notes;
}
/* =============================================================================================== */
/* "CODE" GENERATOR -- Convert the AEL representation to asterisk extension language */
/* =============================================================================================== */
static int control_statement_count = 0;
struct ael_priority *new_prio(void)
{
struct ael_priority *x = (struct ael_priority *)calloc(sizeof(struct ael_priority),1);
return x;
}
struct ael_extension *new_exten(void)
{
struct ael_extension *x = (struct ael_extension *)calloc(sizeof(struct ael_extension),1);
return x;
}
void linkprio(struct ael_extension *exten, struct ael_priority *prio)
{
if (!exten->plist) {
exten->plist = prio;
exten->plist_last = prio;
} else {
exten->plist_last->next = prio;
exten->plist_last = prio;
}
if( !prio->exten )
prio->exten = exten; /* don't override the switch value */
}
void destroy_extensions(struct ael_extension *exten)
{
struct ael_extension *ne, *nen;
for (ne=exten; ne; ne=nen) {
struct ael_priority *pe, *pen;
if (ne->name)
free(ne->name);
/* cidmatch fields are allocated with name, and freed when
the name field is freed. Don't do a free for this field,
unless you LIKE to see a crash! */
if (ne->hints)
free(ne->hints);
for (pe=ne->plist; pe; pe=pen) {
pen = pe->next;
if (pe->app)
free(pe->app);
pe->app = 0;
if (pe->appargs)
free(pe->appargs);
pe->appargs = 0;
pe->origin = 0;
pe->goto_true = 0;
pe->goto_false = 0;
free(pe);
}
nen = ne->next_exten;
ne->next_exten = 0;
ne->plist =0;
ne->plist_last = 0;
ne->next_exten = 0;
ne->loop_break = 0;
ne->loop_continue = 0;
free(ne);
}
}
static int label_inside_case(pval *label)
{
pval *p = label;
while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) /* early cutout, sort of */ {
if( p->type == PV_CASE || p->type == PV_DEFAULT || p->type == PV_PATTERN ) {
return 1;
}
p = p->dad;
}
return 0;
}
static void linkexten(struct ael_extension *exten, struct ael_extension *add)
{
add->next_exten = exten->next_exten; /* this will reverse the order. Big deal. */
exten->next_exten = add;
}
static void remove_spaces_before_equals(char *str)
{
char *p;
while( str && *str && *str != '=' )
{
if( *str == ' ' || *str == '\n' || *str == '\r' || *str == '\t' )
{
p = str;
while( *p )
{
*p = *(p+1);
p++;
}
}
else
str++;