File: cfg.y

package info (click to toggle)
kamailio 4.2.0-2+deb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 56,276 kB
  • sloc: ansic: 552,836; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (3903 lines) | stat: -rw-r--r-- 114,371 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
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
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
/*
 * $Id$
 *
 *  cfg grammar
 *
 * Copyright (C) 2001-2003 FhG Fokus
 *
 * This file is part of ser, a free SIP server.
 *
 * ser is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version
 *
 * For a license to use the ser software under conditions
 * other than those described here, or to purchase support for this
 * software, please contact iptel.org by e-mail at the following addresses:
 *    info@iptel.org
 *
 * ser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 /*
 * History:
 * ---------
 * 2003-01-29  src_port added (jiri)
 * 2003-01-23  mhomed added (jiri)
 * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
 * 2003-03-19  Added support for route type in find_export (janakj)
 * 2003-03-20  Regex support in modparam (janakj)
 * 2003-04-01  added dst_port, proto , af (andrei)
 * 2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
 * 2003-04-12  added force_rport, chroot and wdir (andrei)
 * 2003-04-15  added tcp_children, disable_tcp (andrei)
 * 2003-04-22  strip_tail added (jiri)
 * 2003-07-03  tls* (disable, certificate, private_key, ca_list, verify,
 *              require_certificate added (andrei)
 * 2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
 * 2003-10-02  added {,set_}advertised_{address,port} (andrei)
 * 2003-10-10  added <,>,<=,>=, != operators support
 *             added msg:len (andrei)
 * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
 * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
 * 2003-10-24  converted to the new socket_info lists (andrei)
 * 2003-10-28  added tcp_accept_aliases (andrei)
 * 2003-11-20  added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
 * 2004-03-30  added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
 * 2004-04-29  added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
 * 2004-05-03  applied multicast support patch (MCAST_LOOPBACK) from janakj
 *             added MCAST_TTL (andrei)
 * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
 *              (andrei)
 * 2004-10-19  added FROM_URI, TO_URI (andrei)
 * 2004-11-30  added force_send_socket (andrei)
 * 2005-07-08  added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
 *              (andrei)
 * 2005-07-11 added DNS_RETR_TIME, DNS_RETR_NO, DNS_SERVERS_NO, DNS_USE_SEARCH,
 *             DNS_TRY_IPV6 (andrei)
 * 2005-07-12  default onreply route added (andrei)
 * 2005-11-16  fixed if (cond) cmd; (andrei)
 * 2005-12-11  added onsend_route support, fcmd (filtered cmd),
 *             snd_{ip,port,proto,af}, to_{ip,proto} (andrei)
 * 2005-12-19  select framework (mma)
 * 2006-01-06  AVP index support (mma)
 * 2005-01-07  optional semicolon in statement, PARAM_STR&PARAM_STRING
 * 2006-02-02  named flags support (andrei)
 * 2006-02-06  named routes support (andrei)
 * 2006-05-30  avp flags (tma)
 * 2006-09-11  added dns cache (use, flags, ttls, mem ,gc) & dst blacklist
 *              options (andrei)
 * 2006-10-13  added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL
 *              (vlada)
 * 2007-02-09  separated command needed for tls-in-core and for tls in general
 *              (andrei)
 * 2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
 *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
 *              RT_TIMER2_POLICY (andrei)
 * 2007-06-16  added DDNS_SRV_LB, DNS_TRY_NAPTR (andrei)
 * 2007-09-10  introduced phone2tel option which allows NOT to consider
 *             user=phone URIs as TEL URIs (jiri)
 * 2007-10-10  added DNS_SEARCH_FMATCH (mma)
 * 2007-11-28  added TCP_OPT_{FD_CACHE, DEFER_ACCEPT, DELAYED_ACK, SYNCNT,
 *              LINGER2, KEEPALIVE, KEEPIDLE, KEEPINTVL, KEEPCNT} (andrei)
 * 2008-01-24  added cfg_var definition (Miklos)
 * 2008-11-18  support for variable parameter module functions (andrei)
 * 2007-12-03  support for generalised lvalues and rvalues:
 *               lval=rval_expr, where lval=avp|pvar  (andrei)
 * 2007-12-06  expression are now evaluated in terms of rvalues;
 *             NUMBER is now always positive; cleanup (andrei)
 * 2009-01-26  case/switch() support (andrei)
 * 2009-03-10  added SET_USERPHONE action (Miklos)
 * 2009-05-04  switched if to rval_expr (andrei)
 * 2010-01-10  init shm on first mod_param or route block;
 *             added SHM_MEM_SZ (andrei)
 * 2010-02-17  added blacklist imask (DST_BLST_*_IMASK) support (andrei)
*/

%expect 6

%{

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>
#include "route_struct.h"
#include "globals.h"
#ifdef SHM_MEM
#include "shm_init.h"
#endif /* SHM_MEM */
#include "route.h"
#include "switch.h"
#include "dprint.h"
#include "sr_module.h"
#include "modparam.h"
#include "ip_addr.h"
#include "resolve.h"
#include "socket_info.h"
#include "name_alias.h"
#include "ut.h"
#include "dset.h"
#include "select.h"
#include "flags.h"
#include "tcp_init.h"
#include "tcp_options.h"
#include "sctp_core.h"
#include "pvar.h"
#include "lvalue.h"
#include "rvalue.h"
#include "sr_compat.h"
#include "msg_translator.h"
#include "async_task.h"

#include "ppcfg.h"
#include "pvapi.h"
#include "config.h"
#include "cfg_core.h"
#include "cfg/cfg.h"
#ifdef CORE_TLS
#include "tls/tls_config.h"
#endif
#include "timer_ticks.h"

#ifdef DEBUG_DMALLOC
#include <dmalloc.h>
#endif

/* hack to avoid alloca usage in the generated C file (needed for compiler
 with no built in alloca, like icc*/
#undef _ALLOCA_H

#define onsend_check(s) \
	do{\
		if (rt!=ONSEND_ROUTE) yyerror( s " allowed only in onsend_routes");\
	}while(0)

	#define IF_AUTO_BIND_IPV6(x) x

#ifdef USE_DNS_CACHE
	#define IF_DNS_CACHE(x) x
#else
	#define IF_DNS_CACHE(x) warn("dns cache support not compiled in")
#endif

#ifdef USE_DNS_FAILOVER
	#define IF_DNS_FAILOVER(x) x
#else
	#define IF_DNS_FAILOVER(x) warn("dns failover support not compiled in")
#endif

#ifdef USE_NAPTR
	#define IF_NAPTR(x) x
#else
	#define IF_NAPTR(x) warn("dns naptr support not compiled in")
#endif

#ifdef USE_DST_BLACKLIST
	#define IF_DST_BLACKLIST(x) x
#else
	#define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
#endif

#ifdef USE_SCTP
	#define IF_SCTP(x) x
#else
	#define IF_SCTP(x) warn("sctp support not compiled in")
#endif

#ifdef USE_RAW_SOCKS
	#define IF_RAW_SOCKS(x) x
#else
	#define IF_RAW_SOCKS(x) warn("raw socket support not compiled in")
#endif


extern int yylex();
/* safer then using yytext which can be array or pointer */
extern char* yy_number_str;

static void yyerror(char* s, ...);
static void yyerror_at(struct cfg_pos* pos, char* s, ...);
static char* tmp;
static int i_tmp;
static unsigned u_tmp;
static struct socket_id* lst_tmp;
static struct name_lst*  nl_tmp;
static int rt;  /* Type of route block for find_export */
static str* str_tmp;
static str s_tmp;
static struct ip_addr* ip_tmp;
static struct avp_spec* s_attr;
static select_t sel;
static select_t* sel_ptr;
static pv_spec_t* pv_spec;
static struct action *mod_func_action;
static struct lvalue* lval_tmp;
static struct rvalue* rval_tmp;

static void warn(char* s, ...);
static void warn_at(struct cfg_pos* pos, char* s, ...);
static void get_cpos(struct cfg_pos* pos);
static struct rval_expr* mk_rve_rval(enum rval_type, void* v);
static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1);
static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
									struct rval_expr* rve2);
static int rval_expr_int_check(struct rval_expr *rve);
static int warn_ct_rve(struct rval_expr *rve, char* name);
static struct socket_id* mk_listen_id(char*, int, int);
static struct name_lst* mk_name_lst(char* name, int flags);
static struct socket_id* mk_listen_id2(struct name_lst*, int, int);
static void free_name_lst(struct name_lst* lst);
static void free_socket_id_lst(struct socket_id* i);

static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re, 
									struct action* a, int* err);
static int case_check_type(struct case_stms* stms);
static int case_check_default(struct case_stms* stms);
static int mod_f_params_pre_fixup(struct action* a);
static void free_mod_func_action(struct action* a);


extern int line;
extern int column;
extern int startcolumn;
extern int startline;
extern char *finame;
extern char *routename;
extern char *default_routename;

#define set_cfg_pos(x) \
	do{\
		if(x) {\
		(x)->cline = line;\
		(x)->cfile = (finame!=0)?finame:((cfg_file!=0)?cfg_file:"default");\
		(x)->rname = (routename!=0)?routename:((default_routename!=0)?default_routename:"DEFAULT");\
		}\
	}while(0)


%}

%union {
	long intval;
	unsigned long uval;
	char* strval;
	struct expr* expr;
	struct action* action;
	struct case_stms* case_stms;
	struct net* ipnet;
	struct ip_addr* ipaddr;
	struct socket_id* sockid;
	struct name_lst* name_l;
	struct avp_spec* attr;
	struct _pv_spec* pvar;
	struct lvalue* lval;
	struct rvalue* rval;
	struct rval_expr* rv_expr;
	select_t* select;
}

/* terminals */


/* keywords */
%token FORWARD
%token FORWARD_TCP
%token FORWARD_TLS
%token FORWARD_SCTP
%token FORWARD_UDP
%token EXIT
%token DROP
%token RETURN
%token BREAK
%token LOG_TOK
%token ERROR
%token ROUTE
%token ROUTE_REQUEST
%token ROUTE_FAILURE
%token ROUTE_ONREPLY
%token ROUTE_REPLY
%token ROUTE_BRANCH
%token ROUTE_SEND
%token ROUTE_EVENT
%token EXEC
%token SET_HOST
%token SET_HOSTPORT
%token SET_HOSTPORTTRANS
%token PREFIX
%token STRIP
%token STRIP_TAIL
%token SET_USERPHONE
%token APPEND_BRANCH
%token REMOVE_BRANCH
%token CLEAR_BRANCHES
%token SET_USER
%token SET_USERPASS
%token SET_PORT
%token SET_URI
%token REVERT_URI
%token FORCE_RPORT
%token ADD_LOCAL_RPORT
%token FORCE_TCP_ALIAS
%token UDP_MTU
%token UDP_MTU_TRY_PROTO
%token UDP4_RAW
%token UDP4_RAW_MTU
%token UDP4_RAW_TTL
%token IF
%token ELSE
%token SET_ADV_ADDRESS
%token SET_ADV_PORT
%token FORCE_SEND_SOCKET
%token SET_FWD_NO_CONNECT
%token SET_RPL_NO_CONNECT
%token SET_FWD_CLOSE
%token SET_RPL_CLOSE
%token SWITCH
%token CASE
%token DEFAULT
%token WHILE
%token CFG_SELECT
%token CFG_RESET
%token URIHOST
%token URIPORT
%token MAX_LEN
%token SETFLAG
%token RESETFLAG
%token ISFLAGSET
%token SETAVPFLAG
%token RESETAVPFLAG
%token ISAVPFLAGSET
%token METHOD
%token URI
%token FROM_URI
%token TO_URI
%token SRCIP
%token SRCPORT
%token DSTIP
%token DSTPORT
%token TOIP
%token TOPORT
%token SNDIP
%token SNDPORT
%token SNDPROTO
%token SNDAF
%token PROTO
%token AF
%token MYSELF
%token MSGLEN
%token UDP
%token TCP
%token TLS
%token SCTP
%token WS
%token WSS

/* config vars. */
%token DEBUG_V
%token FORK
%token FORK_DELAY
%token MODINIT_DELAY
%token LOGSTDERROR
%token LOGFACILITY
%token LOGNAME
%token LOGCOLOR
%token LOGPREFIX
%token LISTEN
%token ADVERTISE
%token ALIAS
%token SR_AUTO_ALIASES
%token DNS
%token REV_DNS
%token DNS_TRY_IPV6
%token DNS_TRY_NAPTR
%token DNS_SRV_LB
%token DNS_UDP_PREF
%token DNS_TCP_PREF
%token DNS_TLS_PREF
%token DNS_SCTP_PREF
%token DNS_RETR_TIME
%token DNS_RETR_NO
%token DNS_SERVERS_NO
%token DNS_USE_SEARCH
%token DNS_SEARCH_FMATCH
%token DNS_NAPTR_IGNORE_RFC
%token DNS_CACHE_INIT
%token DNS_USE_CACHE
%token DNS_USE_FAILOVER
%token DNS_CACHE_FLAGS
%token DNS_CACHE_NEG_TTL
%token DNS_CACHE_MIN_TTL
%token DNS_CACHE_MAX_TTL
%token DNS_CACHE_MEM
%token DNS_CACHE_GC_INT
%token DNS_CACHE_DEL_NONEXP

/* ipv6 auto bind */
%token AUTO_BIND_IPV6

/*blacklist*/
%token DST_BLST_INIT
%token USE_DST_BLST
%token DST_BLST_MEM
%token DST_BLST_TTL
%token DST_BLST_GC_INT
%token DST_BLST_UDP_IMASK
%token DST_BLST_TCP_IMASK
%token DST_BLST_TLS_IMASK
%token DST_BLST_SCTP_IMASK

%token PORT
%token STAT
%token CHILDREN
%token SOCKET_WORKERS
%token ASYNC_WORKERS
%token CHECK_VIA
%token PHONE2TEL
%token MEMLOG
%token MEMDBG
%token MEMSUM
%token MEMSAFETY
%token MEMJOIN
%token CORELOG
%token SIP_WARNING
%token SERVER_SIGNATURE
%token SERVER_HEADER
%token USER_AGENT_HEADER
%token REPLY_TO_VIA
%token LOADMODULE
%token LOADPATH
%token MODPARAM
%token MAXBUFFER
%token SQL_BUFFER_SIZE
%token USER
%token GROUP
%token CHROOT
%token WDIR
%token MHOMED
%token DISABLE_TCP
%token TCP_ACCEPT_ALIASES
%token TCP_CHILDREN
%token TCP_CONNECT_TIMEOUT
%token TCP_SEND_TIMEOUT
%token TCP_CON_LIFETIME
%token TCP_POLL_METHOD
%token TCP_MAX_CONNECTIONS
%token TLS_MAX_CONNECTIONS
%token TCP_NO_CONNECT
%token TCP_SOURCE_IPV4
%token TCP_SOURCE_IPV6
%token TCP_OPT_FD_CACHE
%token TCP_OPT_BUF_WRITE
%token TCP_OPT_CONN_WQ_MAX
%token TCP_OPT_WQ_MAX
%token TCP_OPT_RD_BUF
%token TCP_OPT_WQ_BLK
%token TCP_OPT_DEFER_ACCEPT
%token TCP_OPT_DELAYED_ACK
%token TCP_OPT_SYNCNT
%token TCP_OPT_LINGER2
%token TCP_OPT_KEEPALIVE
%token TCP_OPT_KEEPIDLE
%token TCP_OPT_KEEPINTVL
%token TCP_OPT_KEEPCNT
%token TCP_OPT_CRLF_PING
%token TCP_OPT_ACCEPT_NO_CL
%token TCP_CLONE_RCVBUF
%token DISABLE_TLS
%token ENABLE_TLS
%token TLSLOG
%token TLS_PORT_NO
%token TLS_METHOD
%token TLS_HANDSHAKE_TIMEOUT
%token TLS_SEND_TIMEOUT
%token SSLv23
%token SSLv2
%token SSLv3
%token TLSv1
%token TLS_VERIFY
%token TLS_REQUIRE_CERTIFICATE
%token TLS_CERTIFICATE
%token TLS_PRIVATE_KEY
%token TLS_CA_LIST
%token DISABLE_SCTP
%token ENABLE_SCTP
%token SCTP_CHILDREN
%token ADVERTISED_ADDRESS
%token ADVERTISED_PORT
%token DISABLE_CORE
%token OPEN_FD_LIMIT
%token SHM_MEM_SZ
%token SHM_FORCE_ALLOC
%token MLOCK_PAGES
%token REAL_TIME
%token RT_PRIO
%token RT_POLICY
%token RT_TIMER1_PRIO
%token RT_TIMER1_POLICY
%token RT_TIMER2_PRIO
%token RT_TIMER2_POLICY
%token MCAST_LOOPBACK
%token MCAST_TTL
%token TOS
%token PMTU_DISCOVERY
%token KILL_TIMEOUT
%token MAX_WLOOPS
%token PVBUFSIZE
%token PVBUFSLOTS
%token HTTP_REPLY_PARSE
%token VERSION_TABLE_CFG
%token CFG_DESCRIPTION
%token SERVER_ID
%token MAX_RECURSIVE_LEVEL
%token LATENCY_LOG
%token LATENCY_LIMIT_DB
%token LATENCY_LIMIT_ACTION
%token MSG_TIME
%token ONSEND_RT_REPLY

%token FLAGS_DECL
%token AVPFLAGS_DECL

%token ATTR_MARK
%token SELECT_MARK
%token ATTR_FROM
%token ATTR_TO
%token ATTR_FROMURI
%token ATTR_TOURI
%token ATTR_FROMUSER
%token ATTR_TOUSER
%token ATTR_FROMDOMAIN
%token ATTR_TODOMAIN
%token ATTR_GLOBAL
%token ADDEQ


/*pre-processor*/
%token SUBST
%token SUBSTDEF
%token SUBSTDEFS

/* operators, C like precedence */
%right EQUAL
%left LOG_OR
%left LOG_AND
%left BIN_OR
%left BIN_AND
%left BIN_XOR
%left BIN_LSHIFT
%left BIN_RSHIFT
%left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF
%left GT LT GTE LTE
%left PLUS MINUS
%left STAR SLASH MODULO
%right NOT UNARY BIN_NOT
%right DEFINED
%right INTCAST STRCAST
%left DOT

/* no precedence, they use () */
%token STRLEN
%token STREMPTY

/* values */
%token <intval> NUMBER
%token <strval> ID
%token <strval> NUM_ID
%token <strval> STRING
%token <strval> IPV6ADDR
%token <strval> PVAR
/* not clear yet if this is an avp or pvar */
%token <strval> AVP_OR_PVAR
%token <strval> EVENT_RT_NAME

/* other */
%token COMMA
%token SEMICOLON
%token RPAREN
%token LPAREN
%token LBRACE
%token RBRACE
%token LBRACK
%token RBRACK
%token CR
%token COLON


/*non-terminals */
/*%type <expr> exp */
%type <expr> exp_elem
%type <intval> intno eint_op eint_op_onsend
%type <intval> eip_op eip_op_onsend
%type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
%type <action> switch_cmd while_cmd ret_cmd
%type <case_stms> single_case case_stms
%type <ipaddr> ipv4 ipv6 ipv6addr ip
%type <ipnet> ipnet
%type <strval> host host_or_if host_if_id
%type <strval> listen_id
%type <name_l> listen_id_lst
%type <name_l> listen_id2
%type <sockid>  id_lst
%type <sockid>  phostport
%type <sockid>  listen_phostport
%type <intval> proto eqproto port
%type <intval> equalop strop cmpop rve_cmpop rve_equalop
%type <intval> uri_type
%type <attr> attr_id
%type <attr> attr_id_num_idx
%type <attr> attr_id_no_idx
%type <attr> attr_id_ass
/*%type <attr> attr_id_val*/
%type <attr> attr_id_any
%type <attr> attr_id_any_str
%type <pvar> pvar
%type <lval> lval
%type <rv_expr> rval rval_expr ct_rval
%type <lval> avp_pvar
/* %type <intval> class_id */
%type <intval> assign_op
%type <select> select_id
%type <strval>	flag_name;
%type <strval>	route_name;
%type <intval> avpflag_oper
%type <intval> rve_un_op
%type <strval> cfg_var_id
/* %type <intval> rve_op */

/*%type <route_el> rules;
  %type <route_el> rule;
*/

%%


cfg:
	statements
	;
statements:
	statements statement {}
	| statement {}
	| statements error { yyerror(""); YYABORT;}
	;
statement:
	assign_stm
	| preprocess_stm
	| flags_decl
	| avpflags_decl
	| module_stm
	| {rt=REQUEST_ROUTE;} route_stm
	| {rt=FAILURE_ROUTE;} failure_route_stm
	| onreply_route_stm
	| {rt=BRANCH_ROUTE;} branch_route_stm
	| {rt=ONSEND_ROUTE;}   send_route_stm
	| {rt=EVENT_ROUTE;}   event_route_stm
	| SEMICOLON	/* null statement */
	| CR	/* null statement*/
	;
listen_id:
	ip {
		if ($1){
			tmp=ip_addr2a($1);
			if (tmp==0) {
				LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
						"address.\n");
				$$=0;
			} else {
				$$=pkg_malloc(strlen(tmp)+1);
				if ($$==0) {
					LOG(L_CRIT, "ERROR: cfg. parser: out of "
							"memory.\n");
				} else {
					strncpy($$, tmp, strlen(tmp)+1);
				}
			}
		}
	}
	| STRING {
		$$=pkg_malloc(strlen($1)+1);
		if ($$==0) {
				LOG(L_CRIT, "ERROR: cfg. parser: out of "
						"memory.\n");
		} else {
				strncpy($$, $1, strlen($1)+1);
		}
	}
	| host_or_if {
		if ($1){
			$$=pkg_malloc(strlen($1)+1);
			if ($$==0) {
					LOG(L_CRIT, "ERROR: cfg. parser: out of "
							"memory.\n");
			} else {
					strncpy($$, $1, strlen($1)+1);
			}
		}
	}
	;


listen_id_lst:
	listen_id	{ $$=mk_name_lst($1, SI_IS_MHOMED); }
	| listen_id COMMA listen_id_lst	{ $$=mk_name_lst($1, SI_IS_MHOMED); 
										if ($$) $$->next=$3;
									}
	;

listen_id2:
	LPAREN listen_id_lst RPAREN { $$=$2; }
	| listen_id	{ $$=mk_name_lst($1, 0); }
	;

proto:
	UDP	{ $$=PROTO_UDP; }
	| TCP	{ $$=PROTO_TCP; }
	| TLS	{ $$=PROTO_TLS; }
	| SCTP	{ $$=PROTO_SCTP; }
	| STAR	{ $$=0; }
	;
eqproto:
	UDP	{ $$=PROTO_UDP; }
	| TCP	{ $$=PROTO_TCP; }
	| TLS	{ $$=PROTO_TLS; }
	| SCTP	{ $$=PROTO_SCTP; }
	| WS	{ $$=PROTO_WS; }
	| WSS	{ $$=PROTO_WSS; }
	| STAR	{ $$=0; }
	;
port:
	NUMBER	{ $$=$1; }
	| STAR	{ $$=0; }
;
phostport:
	listen_id		{ $$=mk_listen_id($1, 0, 0); }
	| listen_id COLON port	{ $$=mk_listen_id($1, 0, $3); }
	| proto COLON listen_id	{ $$=mk_listen_id($3, $1, 0); }
	| proto COLON listen_id COLON port	{ $$=mk_listen_id($3, $1, $5);}
	| listen_id COLON error { $$=0; yyerror(" port number expected"); }
	;

listen_phostport:
	listen_id2		{ $$=mk_listen_id2($1, 0, 0); }
	| listen_id2 COLON port	{ $$=mk_listen_id2($1, 0, $3); }
	| proto COLON listen_id2	{ $$=mk_listen_id2($3, $1, 0); }
	| proto COLON listen_id2 COLON port	{ $$=mk_listen_id2($3, $1, $5);}
	| listen_id2 COLON error { $$=0; yyerror(" port number expected"); }
	;

id_lst:
	listen_phostport		{  $$=$1 ; }
	| listen_phostport id_lst	{ $$=$1;  if ($$) $$->next=$2; }
	;

intno: NUMBER
	|  MINUS NUMBER %prec UNARY { $$=-$2; }
	;

flags_decl:		FLAGS_DECL	flag_list
			|	FLAGS_DECL error { yyerror("flag list expected\n"); }
;
flag_list:		flag_spec
			|	flag_spec COMMA flag_list
;

flag_spec:		flag_name	{ if (register_flag($1,-1)<0)
								yyerror("register flag failed");
						}
			|	flag_name COLON NUMBER {
						if (register_flag($1, $3)<0)
								yyerror("register flag failed");
										}
;

flag_name:		STRING	{ $$=$1; }
			|	ID		{ $$=$1; }
;

avpflags_decl:
	AVPFLAGS_DECL avpflag_list
	| AVPFLAGS_DECL error { yyerror("avpflag list expected\n"); }
	;
avpflag_list:
	avpflag_spec
	| avpflag_spec COMMA avpflag_list
	;
avpflag_spec:
	flag_name {
		if (register_avpflag($1)==0)
			yyerror("cannot declare avpflag");
	}
	;
assign_stm:
	DEBUG_V EQUAL intno { default_core_cfg.debug=$3; }
	| DEBUG_V EQUAL error  { yyerror("number  expected"); }
	| FORK  EQUAL NUMBER { dont_fork= ! $3; }
	| FORK  EQUAL error  { yyerror("boolean value expected"); }
	| FORK_DELAY  EQUAL NUMBER { set_fork_delay($3); }
	| FORK_DELAY  EQUAL error  { yyerror("number expected"); }
	| MODINIT_DELAY  EQUAL NUMBER { set_modinit_delay($3); }
	| MODINIT_DELAY  EQUAL error  { yyerror("number expected"); }
	| LOGSTDERROR EQUAL NUMBER { if (!config_check)  /* if set from cmd line, don't overwrite from yyparse()*/ 
					if(log_stderr == 0) log_stderr=$3; 
				   }
	| LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
	| LOGFACILITY EQUAL ID {
		if ( (i_tmp=str2facility($3))==-1)
			yyerror("bad facility (see syslog(3) man page)");
		if (!config_check)
			default_core_cfg.log_facility=i_tmp;
	}
	| LOGFACILITY EQUAL error { yyerror("ID expected"); }
	| LOGNAME EQUAL STRING { log_name=$3; }
	| LOGNAME EQUAL error { yyerror("string value expected"); }
	| LOGCOLOR EQUAL NUMBER { log_color=$3; }
	| LOGCOLOR EQUAL error { yyerror("boolean value expected"); }
	| LOGPREFIX EQUAL STRING { log_prefix_fmt=$3; }
	| LOGPREFIX EQUAL error { yyerror("string value expected"); }
	| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
	| DNS EQUAL error { yyerror("boolean value expected"); }
	| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
	| REV_DNS EQUAL error { yyerror("boolean value expected"); }
	| DNS_TRY_IPV6 EQUAL NUMBER   { default_core_cfg.dns_try_ipv6=$3; }
	| DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
	| DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
	| DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
	| DNS_SRV_LB error { yyerror("boolean value expected"); }
	| DNS_UDP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
	| DNS_UDP_PREF error { yyerror("number expected"); }
	| DNS_TCP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
	| DNS_TCP_PREF error { yyerror("number expected"); }
	| DNS_TLS_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
	| DNS_TLS_PREF error { yyerror("number expected"); }
	| DNS_SCTP_PREF EQUAL intno { 
								IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
	| DNS_SCTP_PREF error { yyerror("number expected"); }
	| DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
	| DNS_RETR_TIME error { yyerror("number expected"); }
	| DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
	| DNS_RETR_NO error { yyerror("number expected"); }
	| DNS_SERVERS_NO EQUAL NUMBER   { default_core_cfg.dns_servers_no=$3; }
	| DNS_SERVERS_NO error { yyerror("number expected"); }
	| DNS_USE_SEARCH EQUAL NUMBER   { default_core_cfg.dns_search_list=$3; }
	| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
	| DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
	| DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
	| DNS_NAPTR_IGNORE_RFC EQUAL NUMBER   { default_core_cfg.dns_naptr_ignore_rfc=$3; }
	| DNS_NAPTR_IGNORE_RFC error { yyerror("boolean value expected"); }
	| DNS_CACHE_INIT EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_init=$3); }
	| DNS_CACHE_INIT error { yyerror("boolean value expected"); }
	| DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.use_dns_cache=$3); }
	| DNS_USE_CACHE error { yyerror("boolean value expected"); }
	| DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
	| DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
	| DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
	| DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
	| DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
	| DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
	| DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
	| DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
	| DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
	| DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
	| DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
	| DNS_CACHE_MEM error { yyerror("boolean value expected"); }
	| DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
	| DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
	| DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
	| AUTO_BIND_IPV6 EQUAL NUMBER {IF_AUTO_BIND_IPV6(auto_bind_ipv6 = $3);}
	| AUTO_BIND_IPV6 error { yyerror("boolean value expected"); }
	| DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
	| DST_BLST_INIT error { yyerror("boolean value expected"); }
	| USE_DST_BLST EQUAL NUMBER {
		IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3);
	}
	| USE_DST_BLST error { yyerror("boolean value expected"); }
	| DST_BLST_MEM EQUAL NUMBER {
		IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); 
	}
	| DST_BLST_MEM error { yyerror("boolean value expected"); }
	| DST_BLST_TTL EQUAL NUMBER {
		IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3);
	}
	| DST_BLST_TTL error { yyerror("boolean value expected"); }
	| DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
	| DST_BLST_GC_INT error { yyerror("boolean value expected"); }
	| DST_BLST_UDP_IMASK EQUAL NUMBER {
		IF_DST_BLACKLIST(default_core_cfg.blst_udp_imask=$3);
	}
	| DST_BLST_UDP_IMASK error { yyerror("number(flags) expected"); }
	| DST_BLST_TCP_IMASK EQUAL NUMBER {
		IF_DST_BLACKLIST(default_core_cfg.blst_tcp_imask=$3);
	}
	| DST_BLST_TCP_IMASK error { yyerror("number(flags) expected"); }
	| DST_BLST_TLS_IMASK EQUAL NUMBER {
		IF_DST_BLACKLIST(default_core_cfg.blst_tls_imask=$3);
	}
	| DST_BLST_TLS_IMASK error { yyerror("number(flags) expected"); }
	| DST_BLST_SCTP_IMASK EQUAL NUMBER {
		IF_DST_BLACKLIST(default_core_cfg.blst_sctp_imask=$3);
	}
	| DST_BLST_SCTP_IMASK error { yyerror("number(flags) expected"); }
	| PORT EQUAL NUMBER   { port_no=$3; }
	| STAT EQUAL STRING {
		#ifdef STATS
				stat_file=$3;
		#endif
	}
	| MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
	| MAXBUFFER EQUAL error { yyerror("number expected"); }
    | SQL_BUFFER_SIZE EQUAL NUMBER { sql_buffer_size=$3; }
	| SQL_BUFFER_SIZE EQUAL error { yyerror("number expected"); }
	| PORT EQUAL error    { yyerror("number expected"); }
	| CHILDREN EQUAL NUMBER { children_no=$3; }
	| CHILDREN EQUAL error { yyerror("number expected"); }
	| SOCKET_WORKERS EQUAL NUMBER { socket_workers=$3; }
	| SOCKET_WORKERS EQUAL error { yyerror("number expected"); }
	| ASYNC_WORKERS EQUAL NUMBER { async_task_set_workers($3); }
	| ASYNC_WORKERS EQUAL error { yyerror("number expected"); }
	| CHECK_VIA EQUAL NUMBER { check_via=$3; }
	| CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
	| PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
	| PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
	| MEMLOG EQUAL intno { default_core_cfg.memlog=$3; }
	| MEMLOG EQUAL error { yyerror("int value expected"); }
	| MEMDBG EQUAL intno { default_core_cfg.memdbg=$3; }
	| MEMDBG EQUAL error { yyerror("int value expected"); }
	| MEMSUM EQUAL intno { default_core_cfg.mem_summary=$3; }
	| MEMSUM EQUAL error { yyerror("int value expected"); }
	| MEMSAFETY EQUAL intno { default_core_cfg.mem_safety=$3; }
	| MEMSAFETY EQUAL error { yyerror("int value expected"); }
	| MEMJOIN EQUAL intno { default_core_cfg.mem_join=$3; }
	| MEMJOIN EQUAL error { yyerror("int value expected"); }
	| CORELOG EQUAL intno { default_core_cfg.corelog=$3; }
	| CORELOG EQUAL error { yyerror("int value expected"); }
	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
	| VERSION_TABLE_CFG EQUAL STRING { version_table.s=$3;
			version_table.len=strlen(version_table.s);
	}
	| VERSION_TABLE_CFG EQUAL error { yyerror("string value expected"); }
	| USER EQUAL STRING     {
		if (shm_initialized())
			yyerror("user must be before any modparam or the"
					" route blocks");
		else if (user==0)
			user=$3; 
	}
	| USER EQUAL ID         {
		if (shm_initialized())
			yyerror("user must be before any modparam or the"
					" route blocks");
		else if (user==0)
			user=$3;
	}
	| USER EQUAL error      { yyerror("string value expected"); }
	| GROUP EQUAL STRING     { group=$3; }
	| GROUP EQUAL ID         { group=$3; }
	| GROUP EQUAL error      { yyerror("string value expected"); }
	| CHROOT EQUAL STRING     { chroot_dir=$3; }
	| CHROOT EQUAL ID         { chroot_dir=$3; }
	| CHROOT EQUAL error      { yyerror("string value expected"); }
	| WDIR EQUAL STRING     { working_dir=$3; }
	| WDIR EQUAL ID         { working_dir=$3; }
	| WDIR EQUAL error      { yyerror("string value expected"); }
	| MHOMED EQUAL NUMBER { mhomed=$3; }
	| MHOMED EQUAL error { yyerror("boolean value expected"); }
	| DISABLE_TCP EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_disable=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
	| TCP_ACCEPT_ALIASES EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.accept_aliases=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
	| TCP_CHILDREN EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_cfg_children_no=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_CHILDREN EQUAL error { yyerror("number expected"); }
	| TCP_CONNECT_TIMEOUT EQUAL intno {
		#ifdef USE_TCP
			tcp_default_cfg.connect_timeout_s=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
	| TCP_SEND_TIMEOUT EQUAL intno {
		#ifdef USE_TCP
			tcp_default_cfg.send_timeout=S_TO_TICKS($3);
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
	| TCP_CON_LIFETIME EQUAL intno {
		#ifdef USE_TCP
			if ($3<0)
				tcp_default_cfg.con_lifetime=-1;
			else
				tcp_default_cfg.con_lifetime=S_TO_TICKS($3);
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
	| TCP_POLL_METHOD EQUAL ID {
		#ifdef USE_TCP
			tcp_poll_method=get_poll_type($3);
			if (tcp_poll_method==POLL_NONE) {
				LOG(L_CRIT, "bad poll method name:"
						" %s\n, try one of %s.\n",
						$3, poll_support);
				yyerror("bad tcp_poll_method "
						"value");
			}
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_POLL_METHOD EQUAL STRING {
		#ifdef USE_TCP
			tcp_poll_method=get_poll_type($3);
			if (tcp_poll_method==POLL_NONE) {
				LOG(L_CRIT, "bad poll method name:"
						" %s\n, try one of %s.\n",
						$3, poll_support);
				yyerror("bad tcp_poll_method "
						"value");
			}
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
	| TCP_MAX_CONNECTIONS EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_max_connections=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
	| TLS_MAX_CONNECTIONS EQUAL NUMBER {
		#ifdef USE_TLS
			tls_max_connections=$3;
		#else
			warn("tls support not compiled in");
		#endif
	}
	| TLS_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
	| TCP_NO_CONNECT EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.no_connect=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_NO_CONNECT EQUAL error { yyerror("boolean value expected"); }
	| TCP_SOURCE_IPV4 EQUAL ipv4 {
		#ifdef USE_TCP
			if (tcp_set_src_addr($3)<0)
				warn("tcp_source_ipv4 failed");
		#else
			warn("tcp support not compiled in");
		#endif
		pkg_free($3);
	}
	| TCP_SOURCE_IPV4 EQUAL error { yyerror("IPv4 address expected"); }
	| TCP_SOURCE_IPV6 EQUAL ipv6 {
		#ifdef USE_TCP
				if (tcp_set_src_addr($3)<0)
					warn("tcp_source_ipv6 failed");
		#else
			warn("tcp support not compiled in");
		#endif
		pkg_free($3);
	}
	| TCP_SOURCE_IPV6 EQUAL error { yyerror("IPv6 address expected"); }
	| TCP_OPT_FD_CACHE EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.fd_cache=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
	| TCP_OPT_BUF_WRITE EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.async=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_BUF_WRITE EQUAL error { yyerror("boolean value expected"); }
	| TCP_OPT_CONN_WQ_MAX EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.tcpconn_wq_max=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_CONN_WQ_MAX error { yyerror("boolean value expected"); }
	| TCP_OPT_WQ_MAX EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.tcp_wq_max=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_WQ_MAX error { yyerror("number expected"); }
	| TCP_OPT_RD_BUF EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.rd_buf_size=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_RD_BUF error { yyerror("number expected"); }
	| TCP_OPT_WQ_BLK EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.wq_blk_size=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_WQ_BLK error { yyerror("number expected"); }
	| TCP_OPT_DEFER_ACCEPT EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.defer_accept=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_DEFER_ACCEPT EQUAL error { yyerror("boolean value expected"); }
	| TCP_OPT_DELAYED_ACK EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.delayed_ack=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_DELAYED_ACK EQUAL error { yyerror("boolean value expected"); }
	| TCP_OPT_SYNCNT EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.syncnt=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_SYNCNT EQUAL error { yyerror("number expected"); }
	| TCP_OPT_LINGER2 EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.linger2=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_LINGER2 EQUAL error { yyerror("number expected"); }
	| TCP_OPT_KEEPALIVE EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.keepalive=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_KEEPALIVE EQUAL error { yyerror("boolean value expected");}
	| TCP_OPT_KEEPIDLE EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.keepidle=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_KEEPIDLE EQUAL error { yyerror("number expected"); }
	| TCP_OPT_KEEPINTVL EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.keepintvl=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_KEEPINTVL EQUAL error { yyerror("number expected"); }
	| TCP_OPT_KEEPCNT EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.keepcnt=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_KEEPCNT EQUAL error { yyerror("number expected"); }
	| TCP_OPT_CRLF_PING EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.crlf_ping=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_CRLF_PING EQUAL error { yyerror("boolean value expected"); }
	| TCP_OPT_ACCEPT_NO_CL EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_default_cfg.accept_no_cl=$3;
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
	| TCP_CLONE_RCVBUF EQUAL NUMBER {
		#ifdef USE_TCP
			tcp_set_clone_rcvbuf($3);
		#else
			warn("tcp support not compiled in");
		#endif
	}
	| TCP_CLONE_RCVBUF EQUAL error { yyerror("number expected"); }
	| DISABLE_TLS EQUAL NUMBER {
		#ifdef USE_TLS
			tls_disable=$3;
		#else
			warn("tls support not compiled in");
		#endif
	}
	| DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
	| ENABLE_TLS EQUAL NUMBER {
		#ifdef USE_TLS
			tls_disable=!($3);
		#else
			warn("tls support not compiled in");
		#endif
	}
	| ENABLE_TLS EQUAL error { yyerror("boolean value expected"); }
	| TLSLOG EQUAL NUMBER {
		#ifdef CORE_TLS
			tls_log=$3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLSLOG EQUAL error { yyerror("int value expected"); }
	| TLS_PORT_NO EQUAL NUMBER {
		#ifdef USE_TLS
			tls_port_no=$3;
		#else
			warn("tls support not compiled in");
		#endif
	}
	| TLS_PORT_NO EQUAL error { yyerror("number expected"); }
	| TLS_METHOD EQUAL SSLv23 {
		#ifdef CORE_TLS
			tls_method=TLS_USE_SSLv23;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_METHOD EQUAL SSLv2 {
		#ifdef CORE_TLS
			tls_method=TLS_USE_SSLv2;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_METHOD EQUAL SSLv3 {
		#ifdef CORE_TLS
			tls_method=TLS_USE_SSLv3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_METHOD EQUAL TLSv1 {
		#ifdef CORE_TLS
			tls_method=TLS_USE_TLSv1;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_METHOD EQUAL error {
		#ifdef CORE_TLS
			yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected");
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_VERIFY EQUAL NUMBER {
		#ifdef CORE_TLS
			tls_verify_cert=$3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_VERIFY EQUAL error { yyerror("boolean value expected"); }
	| TLS_REQUIRE_CERTIFICATE EQUAL NUMBER {
		#ifdef CORE_TLS
			tls_require_cert=$3;
		#else
			warn( "tls-in-core support not compiled in");
		#endif
	}
	| TLS_REQUIRE_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
	| TLS_CERTIFICATE EQUAL STRING {
		#ifdef CORE_TLS
			tls_cert_file=$3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
	| TLS_PRIVATE_KEY EQUAL STRING {
		#ifdef CORE_TLS
			tls_pkey_file=$3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
	| TLS_CA_LIST EQUAL STRING {
		#ifdef CORE_TLS
			tls_ca_file=$3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
	| TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
		#ifdef CORE_TLS
			tls_handshake_timeout=$3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
	| TLS_SEND_TIMEOUT EQUAL NUMBER {
		#ifdef CORE_TLS
			tls_send_timeout=$3;
		#else
			warn("tls-in-core support not compiled in");
		#endif
	}
	| TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
	| DISABLE_SCTP EQUAL NUMBER {
		#ifdef USE_SCTP
			sctp_disable=$3;
		#else
			warn("sctp support not compiled in");
		#endif
	}
	| DISABLE_SCTP EQUAL error { yyerror("boolean value expected"); }
	| ENABLE_SCTP EQUAL NUMBER {
		#ifdef USE_SCTP
			sctp_disable=($3<=1)?!$3:$3;
		#else
			warn("sctp support not compiled in");
		#endif
	}
	| ENABLE_SCTP EQUAL error { yyerror("boolean or number expected"); }
	| SCTP_CHILDREN EQUAL NUMBER {
		#ifdef USE_SCTP
			sctp_children_no=$3;
		#else
			warn("sctp support not compiled in");
		#endif
	}
	| SCTP_CHILDREN EQUAL error { yyerror("number expected"); }
	| SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
	| SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
	| SERVER_HEADER EQUAL STRING { server_hdr.s=$3;
			server_hdr.len=strlen(server_hdr.s);
	}
	| SERVER_HEADER EQUAL error { yyerror("string value expected"); }
	| USER_AGENT_HEADER EQUAL STRING { user_agent_hdr.s=$3;
			user_agent_hdr.len=strlen(user_agent_hdr.s);
	}
	| USER_AGENT_HEADER EQUAL error { yyerror("string value expected"); }
	| REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
	| REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
	| LISTEN EQUAL id_lst {
		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
			if (add_listen_iface(	lst_tmp->addr_lst->name,
									lst_tmp->addr_lst->next,
									lst_tmp->port, lst_tmp->proto,
									lst_tmp->flags)!=0) {
				LOG(L_CRIT,  "ERROR: cfg. parser: failed to add listen"
								" address\n");
				break;
			}
		}
		free_socket_id_lst($3);
	}
	| LISTEN EQUAL id_lst ADVERTISE listen_id COLON NUMBER {
		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
			if (add_listen_advertise_iface(	lst_tmp->addr_lst->name,
									lst_tmp->addr_lst->next,
									lst_tmp->port, lst_tmp->proto,
									$5, $7,
									lst_tmp->flags)!=0) {
				LOG(L_CRIT,  "ERROR: cfg. parser: failed to add listen"
								" address\n");
				break;
			}
		}
		free_socket_id_lst($3);
	}
	| LISTEN EQUAL  error { yyerror("ip address, interface name or"
									" hostname expected"); }
	| ALIAS EQUAL  id_lst {
		for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
			add_alias(	lst_tmp->addr_lst->name,
						strlen(lst_tmp->addr_lst->name),
						lst_tmp->port, lst_tmp->proto);
			for (nl_tmp=lst_tmp->addr_lst->next; nl_tmp; nl_tmp=nl_tmp->next)
				add_alias(nl_tmp->name, strlen(nl_tmp->name),
							lst_tmp->port, lst_tmp->proto);
		}
		free_socket_id_lst($3);
	}
	| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
	| SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
	| SR_AUTO_ALIASES EQUAL error  { yyerror("boolean value expected"); }
	| ADVERTISED_ADDRESS EQUAL listen_id {
		if ($3){
			default_global_address.s=$3;
			default_global_address.len=strlen($3);
		}
	}
	| ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
	| ADVERTISED_PORT EQUAL NUMBER {
		tmp=int2str($3, &i_tmp);
		if ((default_global_port.s=pkg_malloc(i_tmp))==0) {
			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
			default_global_port.len=0;
		} else {
			default_global_port.len=i_tmp;
			memcpy(default_global_port.s, tmp, default_global_port.len);
		};
	}
	|ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname expected"); }
	| DISABLE_CORE EQUAL NUMBER { disable_core_dump=$3; }
	| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
	| OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
	| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
	| SHM_MEM_SZ EQUAL NUMBER {
		if (shm_initialized())
			yyerror("shm/shm_mem_size must be before any modparam or the"
					" route blocks");
		else if (shm_mem_size == 0)
			shm_mem_size=$3 * 1024 * 1024;
	}
	| SHM_MEM_SZ EQUAL error { yyerror("number expected"); }
	| SHM_FORCE_ALLOC EQUAL NUMBER {
		if (shm_initialized())
			yyerror("shm_force_alloc must be before any modparam or the"
					" route blocks");
		else
			shm_force_alloc=$3;
	}
	| SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
	| MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
	| MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
	| REAL_TIME EQUAL NUMBER { real_time=$3; }
	| REAL_TIME EQUAL error { yyerror("boolean value expected"); }
	| RT_PRIO EQUAL NUMBER { rt_prio=$3; }
	| RT_PRIO EQUAL error { yyerror("boolean value expected"); }
	| RT_POLICY EQUAL NUMBER { rt_policy=$3; }
	| RT_POLICY EQUAL error { yyerror("boolean value expected"); }
	| RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
	| RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
	| RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
	| RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
	| RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
	| RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
	| RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
	| RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
	| MCAST_LOOPBACK EQUAL NUMBER {
		#ifdef USE_MCAST
			mcast_loopback=$3;
		#else
			warn("no multicast support compiled in");
		#endif
	}
	| MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
	| MCAST_TTL EQUAL NUMBER {
		#ifdef USE_MCAST
			mcast_ttl=$3;
		#else
			warn("no multicast support compiled in");
		#endif
	}
	| MCAST_TTL EQUAL error { yyerror("number expected"); }
	| TOS EQUAL NUMBER { tos=$3; }
	| TOS EQUAL ID { if (strcasecmp($3,"IPTOS_LOWDELAY")) {
			tos=IPTOS_LOWDELAY;
		} else if (strcasecmp($3,"IPTOS_THROUGHPUT")) {
			tos=IPTOS_THROUGHPUT;
		} else if (strcasecmp($3,"IPTOS_RELIABILITY")) {
			tos=IPTOS_RELIABILITY;
#if defined(IPTOS_MINCOST)
		} else if (strcasecmp($3,"IPTOS_MINCOST")) {
			tos=IPTOS_MINCOST;
#endif
#if defined(IPTOS_LOWCOST)
		} else if (strcasecmp($3,"IPTOS_LOWCOST")) {
			tos=IPTOS_LOWCOST;
#endif
		} else {
			yyerror("invalid tos value - allowed: "
				"IPTOS_LOWDELAY,IPTOS_THROUGHPUT,"
				"IPTOS_RELIABILITY"
#if defined(IPTOS_LOWCOST)
				",IPTOS_LOWCOST"
#endif
#if !defined(IPTOS_MINCOST)
				",IPTOS_MINCOST"
#endif
				"\n");
		}
	}
	| TOS EQUAL error { yyerror("number expected"); }
	| PMTU_DISCOVERY EQUAL NUMBER { pmtu_discovery=$3; }
	| PMTU_DISCOVERY error { yyerror("number expected"); }
	| KILL_TIMEOUT EQUAL NUMBER { ser_kill_timeout=$3; }
	| KILL_TIMEOUT EQUAL error { yyerror("number expected"); }
	| MAX_WLOOPS EQUAL NUMBER { default_core_cfg.max_while_loops=$3; }
	| MAX_WLOOPS EQUAL error { yyerror("number expected"); }
	| PVBUFSIZE EQUAL NUMBER { pv_set_buffer_size($3); }
	| PVBUFSIZE EQUAL error { yyerror("number expected"); }
	| PVBUFSLOTS EQUAL NUMBER { pv_set_buffer_slots($3); }
	| PVBUFSLOTS EQUAL error { yyerror("number expected"); }
	| HTTP_REPLY_PARSE EQUAL NUMBER { http_reply_parse=$3; }
	| HTTP_REPLY_PARSE EQUAL error { yyerror("boolean value expected"); }
    | SERVER_ID EQUAL NUMBER { server_id=$3; }
    | MAX_RECURSIVE_LEVEL EQUAL NUMBER { set_max_recursive_level($3); }
    | LATENCY_LOG EQUAL NUMBER { default_core_cfg.latency_log=$3; }
	| LATENCY_LOG EQUAL error  { yyerror("number  expected"); }
    | LATENCY_LIMIT_DB EQUAL NUMBER { default_core_cfg.latency_limit_db=$3; }
	| LATENCY_LIMIT_DB EQUAL error  { yyerror("number  expected"); }
    | LATENCY_LIMIT_ACTION EQUAL NUMBER { default_core_cfg.latency_limit_action=$3; }
	| LATENCY_LIMIT_ACTION EQUAL error  { yyerror("number  expected"); }
    | MSG_TIME EQUAL NUMBER { sr_msg_time=$3; }
	| MSG_TIME EQUAL error  { yyerror("number  expected"); }
	| ONSEND_RT_REPLY EQUAL NUMBER { onsend_route_reply=$3; }
	| ONSEND_RT_REPLY EQUAL error { yyerror("int value expected"); }
	| UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
	| UDP_MTU EQUAL error { yyerror("number expected"); }
	| FORCE_RPORT EQUAL NUMBER 
		{ default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
	| FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
	| UDP_MTU_TRY_PROTO EQUAL proto
		{ default_core_cfg.udp_mtu_try_proto=$3; fix_global_req_flags(0, 0); }
	| UDP_MTU_TRY_PROTO EQUAL error
		{ yyerror("TCP, TLS, SCTP or UDP expected"); }
	| UDP4_RAW EQUAL intno { IF_RAW_SOCKS(default_core_cfg.udp4_raw=$3); }
	| UDP4_RAW EQUAL error { yyerror("number expected"); }
	| UDP4_RAW_MTU EQUAL NUMBER {
		IF_RAW_SOCKS(default_core_cfg.udp4_raw_mtu=$3);
	}
	| UDP4_RAW_MTU EQUAL error { yyerror("number expected"); }
	| UDP4_RAW_TTL EQUAL NUMBER {
		IF_RAW_SOCKS(default_core_cfg.udp4_raw_ttl=$3);
	}
	| UDP4_RAW_TTL EQUAL error { yyerror("number expected"); }
	| cfg_var
	| error EQUAL { yyerror("unknown config variable"); }
	;
	
cfg_var_id: ID 
	| DEFAULT { $$="default" ; } /*needed to allow default as cfg var. name*/
	;
	
cfg_var:
	cfg_var_id DOT cfg_var_id EQUAL NUMBER {
		if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
			yyerror("variable cannot be declared");
		}
	}
	| cfg_var_id DOT cfg_var_id EQUAL STRING {
		if (cfg_declare_str($1, $3, $5, NULL)) {
			yyerror("variable cannot be declared");
		}
	}
	| cfg_var_id DOT cfg_var_id EQUAL NUMBER CFG_DESCRIPTION STRING {
		if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
			yyerror("variable cannot be declared");
		}
	}
	| cfg_var_id DOT cfg_var_id EQUAL STRING CFG_DESCRIPTION STRING {
		if (cfg_declare_str($1, $3, $5, $7)) {
			yyerror("variable cannot be declared");
		}
	}
	| cfg_var_id DOT cfg_var_id EQUAL error { 
		yyerror("number or string expected"); 
	}
	| cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL NUMBER {
		if (cfg_ginst_var_int($1, $3, $6, $8)) {
			yyerror("variable cannot be added to the group instance");
		}
	}
	| cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_id EQUAL STRING {
		if (cfg_ginst_var_string($1, $3, $6, $8)) {
			yyerror("variable cannot be added to the group instance");
		}
	}
	;

module_stm:
	LOADMODULE STRING {
		DBG("loading module %s\n", $2);
			if (load_module($2)!=0) {
				yyerror("failed to load module");
			}
	}
	| LOADMODULE error	{ yyerror("string expected"); }
	| LOADPATH STRING {
		if(mods_dir_cmd==0) {
			DBG("loading modules under %s\n", $2);
			printf("loading modules under config path: %s\n", $2);
			mods_dir = $2;
		} else {
			DBG("ignoring mod path given in config: %s\n", $2);
			printf("loading modules under command line path: %s\n", mods_dir);
		}
	}
	| LOADPATH error	{ yyerror("string expected"); }
	| LOADPATH EQUAL STRING {
		if(mods_dir_cmd==0) {
			DBG("loading modules under %s\n", $3);
			printf("loading modules under config path: %s\n", $3);
			mods_dir = $3;
		} else {
			DBG("ignoring mod path given in config: %s\n", $3);
			printf("loading modules under command line path: %s\n", mods_dir);
		}
	}
	| LOADPATH EQUAL error	{ yyerror("string expected"); }
	| MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
			 yyerror("Can't set module parameter");
		}
	}
	| MODPARAM LPAREN STRING COMMA STRING COMMA intno RPAREN {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
			 yyerror("Can't set module parameter");
		}
	}
	| MODPARAM error { yyerror("Invalid arguments"); }
	;
ip:
	ipv4  { $$=$1; }
	| ipv6  { $$=$1; }
	;
ipv4:
	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
		$$=pkg_malloc(sizeof(struct ip_addr));
		if ($$==0) {
			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
		} else {
			memset($$, 0, sizeof(struct ip_addr));
			$$->af=AF_INET;
			$$->len=4;
			if (($1>255) || ($1<0) ||
				($3>255) || ($3<0) ||
				($5>255) || ($5<0) ||
				($7>255) || ($7<0)) {
				yyerror("invalid ipv4 address");
				$$->u.addr32[0]=0;
				/* $$=0; */
			} else {
				$$->u.addr[0]=$1;
				$$->u.addr[1]=$3;
				$$->u.addr[2]=$5;
				$$->u.addr[3]=$7;
				/*
				$$=htonl( ($1<<24)|
				($3<<16)| ($5<<8)|$7 );
				*/
			}
		}
	}
	;
ipv6addr:
	IPV6ADDR {
		$$=pkg_malloc(sizeof(struct ip_addr));
		if ($$==0) {
			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
		} else {
			memset($$, 0, sizeof(struct ip_addr));
			$$->af=AF_INET6;
			$$->len=16;
			if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
				yyerror("bad ipv6 address");
			}
		}
	}
	;
ipv6:
	ipv6addr { $$=$1; }
	| LBRACK ipv6addr RBRACK {$$=$2; }
;


route_name:		NUMBER	{
					tmp=int2str($1, &i_tmp);
					if (($$=pkg_malloc(i_tmp+1))==0) {
						yyerror("out of  memory");
						YYABORT;
					} else {
						memcpy($$, tmp, i_tmp);
						$$[i_tmp]=0;
					}
					routename = tmp;
						}
			|	ID		{ routename = $1; $$=$1; }
			|	STRING	{ routename = $1; $$=$1; }
;


route_main:	ROUTE { ; }
		  | ROUTE_REQUEST { ; }
;

route_stm:
	route_main LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		push($3, &main_rt.rlist[DEFAULT_RT]);
	}
	| ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		i_tmp=route_get(&main_rt, $3);
		if (i_tmp==-1){
			yyerror("internal error");
			YYABORT;
		}
		if (main_rt.rlist[i_tmp]){
			yyerror("duplicate route");
			YYABORT;
		}
		push($6, &main_rt.rlist[i_tmp]);
	}
	| ROUTE error { yyerror("invalid  route  statement"); }
	| ROUTE_REQUEST error { yyerror("invalid  request_route  statement"); }
	;
failure_route_stm:
	ROUTE_FAILURE LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		push($3, &failure_rt.rlist[DEFAULT_RT]);
	}
	| ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		i_tmp=route_get(&failure_rt, $3);
		if (i_tmp==-1){
			yyerror("internal error");
			YYABORT;
		}
		if (failure_rt.rlist[i_tmp]){
			yyerror("duplicate route");
			YYABORT;
		}
		push($6, &failure_rt.rlist[i_tmp]);
	}
	| ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
	;


route_reply_main:	ROUTE_ONREPLY { ; }
		  | ROUTE_REPLY { ; }
;


onreply_route_stm:
	route_reply_main LBRACE {rt=CORE_ONREPLY_ROUTE;} actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		push($4, &onreply_rt.rlist[DEFAULT_RT]);
	}
	| ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
	| ROUTE_REPLY error { yyerror("invalid onreply_route statement"); }
	| ROUTE_ONREPLY LBRACK route_name RBRACK 
		{rt=(*$3=='0' && $3[1]==0)?CORE_ONREPLY_ROUTE:TM_ONREPLY_ROUTE;}
		LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		if (*$3=='0' && $3[1]==0){
			/* onreply_route[0] {} is equivalent with onreply_route {}*/
			push($7, &onreply_rt.rlist[DEFAULT_RT]);
		}else{
			i_tmp=route_get(&onreply_rt, $3);
			if (i_tmp==-1){
				yyerror("internal error");
				YYABORT;
			}
			if (onreply_rt.rlist[i_tmp]){
				yyerror("duplicate route");
				YYABORT;
			}
			push($7, &onreply_rt.rlist[i_tmp]);
		}
	}
	| ROUTE_ONREPLY LBRACK route_name RBRACK error {
		yyerror("invalid onreply_route statement");
	}
	;
branch_route_stm:
	ROUTE_BRANCH LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		push($3, &branch_rt.rlist[DEFAULT_RT]);
	}
	| ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		i_tmp=route_get(&branch_rt, $3);
		if (i_tmp==-1){
			yyerror("internal error");
			YYABORT;
		}
		if (branch_rt.rlist[i_tmp]){
			yyerror("duplicate route");
			YYABORT;
		}
		push($6, &branch_rt.rlist[i_tmp]);
	}
	| ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
	;
send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		push($3, &onsend_rt.rlist[DEFAULT_RT]);
	}
	| ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		i_tmp=route_get(&onsend_rt, $3);
		if (i_tmp==-1){
			yyerror("internal error");
			YYABORT;
		}
		if (onsend_rt.rlist[i_tmp]){
			yyerror("duplicate route");
			YYABORT;
		}
		push($6, &onsend_rt.rlist[i_tmp]);
	}
	| ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
	;
event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
	#ifdef SHM_MEM
		if (!shm_initialized() && init_shm()<0) {
			yyerror("Can't initialize shared memory");
			YYABORT;
		}
	#endif /* SHM_MEM */
		i_tmp=route_get(&event_rt, $3);
		if (i_tmp==-1){
			yyerror("internal error");
			YYABORT;
		}
		if (event_rt.rlist[i_tmp]){
			yyerror("duplicate route");
			YYABORT;
		}
		push($6, &event_rt.rlist[i_tmp]);
	}

	| ROUTE_EVENT error { yyerror("invalid event_route statement"); }
	;
preprocess_stm:
	SUBST STRING { if(pp_subst_add($2)<0) YYERROR; }
	| SUBST error { yyerror("invalid subst preprocess statement"); }
	| SUBSTDEF STRING { if(pp_substdef_add($2, 0)<0) YYERROR; }
	| SUBSTDEF error { yyerror("invalid substdef preprocess statement"); }
	| SUBSTDEFS STRING { if(pp_substdef_add($2, 1)<0) YYERROR; }
	| SUBSTDEFS error { yyerror("invalid substdefs preprocess statement"); }
	;

/*exp:	rval_expr
		{
			if ($1==0){
				yyerror("invalid expression");
				$$=0;
			}else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
				yyerror("invalid expression");
				$$=0;
			}else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
				yyerror("invalid expression type, int expected\n");
				$$=0;
			}else
				$$=mk_elem(NO_OP, RVEXP_O, $1, 0, 0);
		}
	;
*/

/* exp elem operators */
equalop:
	EQUAL_T {$$=EQUAL_OP; }
	| DIFF	{$$=DIFF_OP; }
	| STREQ	{$$=EQUAL_OP; }  /* for expr. elems equiv. to EQUAL_T*/
	| STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
	;
cmpop:
	  GT	{$$=GT_OP; }
	| LT	{$$=LT_OP; }
	| GTE	{$$=GTE_OP; }
	| LTE	{$$=LTE_OP; }
	;
strop:
	equalop	{$$=$1; }
	| MATCH	{$$=MATCH_OP; }
	;


/* rve expr. operators */
rve_equalop:
	EQUAL_T {$$=RVE_EQ_OP; }
	| DIFF	{$$=RVE_DIFF_OP; }
	| INTEQ	{$$=RVE_IEQ_OP; }
	| INTDIFF {$$=RVE_IDIFF_OP; }
	| STREQ	{$$=RVE_STREQ_OP; }
	| STRDIFF {$$=RVE_STRDIFF_OP; }
	| MATCH	{$$=RVE_MATCH_OP; }
	;
rve_cmpop:
	  GT	{$$=RVE_GT_OP; }
	| LT	{$$=RVE_LT_OP; }
	| GTE	{$$=RVE_GTE_OP; }
	| LTE	{$$=RVE_LTE_OP; }
	;



/* boolean expression uri operands */
uri_type:
	URI		{$$=URI_O;}
	| FROM_URI	{$$=FROM_URI_O;}
	| TO_URI	{$$=TO_URI_O;}
	;


/* boolean expression integer operands, available only in the
  onsend route */
eint_op_onsend:
			SNDPORT		{ $$=SNDPORT_O; }
		|	TOPORT		{ $$=TOPORT_O; }
		|	SNDAF		{ $$=SNDAF_O; }
		;

/* boolean expression integer operands */
eint_op:	SRCPORT		{ $$=SRCPORT_O; }
		|	DSTPORT		{ $$=DSTPORT_O; }
		|	AF			{ $$=AF_O; }
		|	MSGLEN		{ $$=MSGLEN_O; }
		| eint_op_onsend
	;

/* boolean expression ip/ipnet operands */
eip_op_onsend:
			SNDIP		{ onsend_check("snd_ip"); $$=SNDIP_O; }
		|	TOIP		{ onsend_check("to_ip");  $$=TOIP_O; }
		;

eip_op:		SRCIP		{ $$=SRCIP_O; }
		|	DSTIP		{ $$=DSTIP_O; }
		| eip_op_onsend
		;



exp_elem:
	METHOD strop rval_expr %prec EQUAL_T
		{$$= mk_elem($2, METHOD_O, 0, RVE_ST, $3);}
	| METHOD strop ID %prec EQUAL_T
		{$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
	| METHOD strop error { $$=0; yyerror("string expected"); }
	| METHOD error	
		{ $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
	| uri_type strop rval_expr %prec EQUAL_T
		{$$ = mk_elem($2, $1, 0, RVE_ST, $3); }
	| uri_type strop MYSELF %prec EQUAL_T
		{$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
	| uri_type strop error %prec EQUAL_T
		{ $$=0; yyerror("string or MYSELF expected"); }
	| uri_type error
		{ $$=0; yyerror("invalid operator, == , != or =~ expected"); }
	| eint_op cmpop rval_expr %prec GT { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
	| eint_op equalop rval_expr %prec EQUAL_T
		{ $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
	| eint_op cmpop error   { $$=0; yyerror("number expected"); }
	| eint_op equalop error { $$=0; yyerror("number expected"); }
	| eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
	| PROTO equalop eqproto %prec EQUAL_T
		{ $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
	| PROTO equalop rval_expr %prec EQUAL_T
		{ $$=mk_elem($2, PROTO_O, 0, RVE_ST, $3 ); }
	| PROTO equalop error
		{ $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, ws, or wss)"); }
	| SNDPROTO equalop eqproto %prec EQUAL_T
		{ $$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 ); }
	| SNDPROTO equalop rval_expr %prec EQUAL_T
		{ $$=mk_elem($2, SNDPROTO_O, 0, RVE_ST, $3 ); }
	| SNDPROTO equalop error
		{ $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, ws, or wss)"); }
	| eip_op strop ipnet %prec EQUAL_T { $$=mk_elem($2, $1, 0, NET_ST, $3); }
	| eip_op strop rval_expr %prec EQUAL_T {
			s_tmp.s=0;
			$$=0;
			if (rve_is_constant($3)){
				i_tmp=rve_guess_type($3);
				if (i_tmp==RV_INT)
					yyerror("string expected");
				else if (i_tmp==RV_STR){
					if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
								(rval_get_str(0, 0, &s_tmp, rval_tmp, 0)<0)){
						rval_destroy(rval_tmp);
						yyerror("bad rvalue expression");
					}else{
						rval_destroy(rval_tmp);
					}
				}else{
					yyerror("BUG: unexpected dynamic type");
				}
			}else{
					/* warn("non constant rvalue in ip comparison") */;
			}
			if (s_tmp.s){
				ip_tmp=str2ip(&s_tmp);
				if (ip_tmp==0)
					ip_tmp=str2ip6(&s_tmp);
				pkg_free(s_tmp.s);
				if (ip_tmp) {
					$$=mk_elem($2, $1, 0, NET_ST, 
								mk_new_net_bitlen(ip_tmp, ip_tmp->len*8) );
				} else {
					$$=mk_elem($2, $1, 0, RVE_ST, $3);
				}
			}else{
				$$=mk_elem($2, $1, 0, RVE_ST, $3);
			}
		}
	| eip_op strop host %prec EQUAL_T
		{ $$=mk_elem($2, $1, 0, STRING_ST, $3); }
	| eip_op strop MYSELF %prec EQUAL_T
		{ $$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
	| eip_op strop error %prec EQUAL_T
		{ $$=0; yyerror( "ip address or hostname expected" ); }
	| eip_op error
		{ $$=0; yyerror("invalid operator, ==, != or =~ expected");}
	
	| MYSELF equalop uri_type %prec EQUAL_T
		{ $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
	| MYSELF equalop eip_op %prec EQUAL_T
		{ $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
	| MYSELF equalop error %prec EQUAL_T
		{ $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
	| MYSELF error	{ $$=0; yyerror ("invalid operator, == or != expected"); }
	;
/*
exp_elem2:
	rval_expr cmpop rval_expr %prec GT
		{ $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
	|
	rval_expr equalop rval_expr %prec EQUAL_T
		{ $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
	| rval_expr LOG_AND rval_expr
		{ $$=mk_exp_rve(LOGAND_OP, $1, $3);}
	| rval_expr LOG_OR rval_expr
		{ $$=mk_exp_rve(LOGOR_OP, $1, $3);}
;
*/

ipnet:
	ip SLASH ip	{ $$=mk_new_net($1, $3); }
	| ip SLASH NUMBER {
		if (($3<0) || ($3>$1->len*8)) {
			yyerror("invalid bit number in netmask");
			$$=0;
		} else {
			$$=mk_new_net_bitlen($1, $3);
		/*
			$$=mk_new_net($1, htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
		*/
		}
	}
	| ip	{ $$=mk_new_net_bitlen($1, $1->len*8); }
	| ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
	;

host:
	ID { $$=$1; }
	| host DOT ID {
		if ($1){
			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
			if ($$==0) {
				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
							" failure while parsing host\n");
			} else {
				memcpy($$, $1, strlen($1));
				$$[strlen($1)]='.';
				memcpy($$+strlen($1)+1, $3, strlen($3));
				$$[strlen($1)+1+strlen($3)]=0;
			}
			pkg_free($1);
		}
		if ($3) pkg_free($3);
	}
	| host MINUS ID {
		if ($1){
			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
			if ($$==0) {
				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
							" failure while parsing host\n");
			} else {
				memcpy($$, $1, strlen($1));
				$$[strlen($1)]='-';
				memcpy($$+strlen($1)+1, $3, strlen($3));
				$$[strlen($1)+1+strlen($3)]=0;
			}
			pkg_free($1);
		}
		if ($3) pkg_free($3);
	}
	| host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
	| host MINUS error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
	;

host_if_id: ID
		| NUM_ID
		| NUMBER {
			/* get string version */
			$$=pkg_malloc(strlen(yy_number_str)+1);
			if ($$)
				strcpy($$, yy_number_str);
		}
		;

host_or_if:
	host_if_id { $$=$1; }
	| host_or_if DOT host_if_id {
		if ($1){
			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
			if ($$==0) {
				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
							" failure while parsing host/interface name\n");
			} else {
				memcpy($$, $1, strlen($1));
				$$[strlen($1)]='.';
				memcpy($$+strlen($1)+1, $3, strlen($3));
				$$[strlen($1)+1+strlen($3)]=0;
			}
			pkg_free($1);
		}
		if ($3) pkg_free($3);
	}
	| host_or_if MINUS host_if_id {
		if ($1){
			$$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
			if ($$==0) {
				LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
							" failure while parsing host/interface name\n");
			} else {
				memcpy($$, $1, strlen($1));
				$$[strlen($1)]='-';
				memcpy($$+strlen($1)+1, $3, strlen($3));
				$$[strlen($1)+1+strlen($3)]=0;
			}
			pkg_free($1);
		}
		if ($3) pkg_free($3);
	}
	| host_or_if DOT error { $$=0; pkg_free($1);
								yyerror("invalid host or interface name"); }
	| host_or_if MINUS error { $$=0; pkg_free($1);
								yyerror("invalid host or interface name"); }
	;


/* filtered cmd */
fcmd:
	cmd {
		/* check if allowed */
		if ($1 && rt==ONSEND_ROUTE) {
			switch($1->type) {
				case DROP_T:
				case LOG_T:
				case SETFLAG_T:
				case RESETFLAG_T:
				case ISFLAGSET_T:
				case IF_T:
				case MODULE0_T:
				case MODULE1_T:
				case MODULE2_T:
				case MODULE3_T:
				case MODULE4_T:
				case MODULE5_T:
				case MODULE6_T:
				case MODULEX_T:
				case SET_FWD_NO_CONNECT_T:
				case SET_RPL_NO_CONNECT_T:
				case SET_FWD_CLOSE_T:
				case SET_RPL_CLOSE_T:
					$$=$1;
					break;
				default:
					$$=0;
					yyerror("command not allowed in onsend_route\n");
			}
		} else {
			$$=$1;
		}
	}
	;
/*
exp_stm:
	fcmd	{ $$=$1; }
	| if_cmd	{ $$=$1; }
	| assign_action { $$ = $1; }
	| LBRACE actions RBRACE	{ $$=$2; }
	;
*/
stm:
	action	{ $$=$1; }
	| LBRACE actions RBRACE	{ $$=$2; }
	;
actions:
	actions action	{$$=append_action($1, $2); }
	| action	{$$=$1;}
	| actions error { $$=0; yyerror("bad command"); }
	;
action:
	fcmd SEMICOLON {$$=$1;}
	| if_cmd {$$=$1;}
	| switch_cmd {$$=$1;}
	| while_cmd { $$=$1; }
	| ret_cmd SEMICOLON { $$=$1; }
	| assign_action SEMICOLON {$$=$1;}
	| SEMICOLON /* null action */ {$$=0;}
	| fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
	;
if_cmd:
	IF rval_expr stm	{
		if ($2 && rval_expr_int_check($2)>=0){
			warn_ct_rve($2, "if");
			$$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0);
			set_cfg_pos($$);
		}else
			YYERROR;
	}
	| IF rval_expr stm ELSE stm	{ 
		if ($2 && rval_expr_int_check($2)>=0){
			warn_ct_rve($2, "if");
			$$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5);
			set_cfg_pos($$);
		}else
			YYERROR;
	}
	;

ct_rval: rval_expr {
			$$=0;
			if ($1 && !rve_is_constant($1)){
				yyerror("constant expected");
				YYERROR;
			/*
			} else if ($1 &&
						!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
				yyerror("invalid expression (bad type)");
			}else if ($1 && i_tmp!=RV_INT){
				yyerror("invalid expression type, int expected\n");
			*/
			}else
				$$=$1;
		}
;
single_case:
	CASE ct_rval COLON actions {
		$$=0;
		if ($2==0) { yyerror ("bad case label"); YYERROR; }
		else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
				YYABORT;
		}
	}
| CASE SLASH ct_rval COLON actions {
		$$=0;
		if ($3==0) { yyerror ("bad case label"); YYERROR; }
		else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
				YYABORT;
		}
	}
	| CASE ct_rval COLON {
		$$=0;
		if ($2==0) { yyerror ("bad case label"); YYERROR; }
		else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
				YYABORT;
		}
	}
	| CASE SLASH ct_rval COLON {
		$$=0;
		if ($3==0) { yyerror ("bad regex case label"); YYERROR; }
		else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
				YYABORT;
		}
	}
	| DEFAULT COLON actions {
		if ((($$=mk_case_stm(0, 0, $3, &i_tmp))==0) && (i_tmp=-10)){
				YYABORT;
		}
	}
	| DEFAULT COLON {
		if ((($$=mk_case_stm(0, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
				YYABORT;
		}
	}
	| CASE error COLON actions { $$=0; yyerror("bad case label"); }
	| CASE SLASH error COLON actions { $$=0; yyerror("bad case regex label"); }
	| CASE error COLON { $$=0; yyerror("bad case label"); }
	| CASE SLASH error COLON { $$=0; yyerror("bad case regex label"); }
	| CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
;
case_stms:
	case_stms single_case {
		$$=$1;
		if ($2==0) yyerror ("bad case");
		if ($$){
			*($$->append)=$2;
			if (*($$->append)!=0)
				$$->append=&((*($$->append))->next);
		}
	}
	| single_case {
		$$=$1;
		if ($1==0) yyerror ("bad case");
		else $$->append=&($$->next);
	}
;
switch_cmd:
	  SWITCH rval_expr LBRACE case_stms RBRACE { 
		$$=0;
		if ($2==0){
			yyerror("bad expression in switch(...)");
			YYERROR;
		}else if ($4==0){
			yyerror ("bad switch body");
			YYERROR;
		}else if (case_check_default($4)!=0){
			yyerror_at(&$2->fpos, "bad switch(): too many "
							"\"default:\" labels\n");
			YYERROR;
		}else if (case_check_type($4)!=0){
			yyerror_at(&$2->fpos, "bad switch(): mixed integer and"
							" string/RE cases not allowed\n");
			YYERROR;
		}else{
			$$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, $4);
			if ($$==0) {
				yyerror("internal error");
				YYABORT;
			}
			set_cfg_pos($$);
		}
	}
	| SWITCH rval_expr LBRACE RBRACE {
		$$=0;
		warn("empty switch()");
		if ($2==0){
			yyerror("bad expression in switch(...)");
			YYERROR;
		}else{
			/* it might have sideffects, so leave it for the optimizer */
			$$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
			if ($$==0) {
				yyerror("internal error");
				YYABORT;
			}
			set_cfg_pos($$);
		}
	}
	| SWITCH error { $$=0; yyerror ("bad expression in switch(...)"); }
	| SWITCH rval_expr LBRACE error RBRACE 
		{$$=0; yyerror ("bad switch body"); }
;

while_cmd:
	WHILE rval_expr stm {
		if ($2 && rval_expr_int_check($2)>=0){
			warn_ct_rve($2, "while");
			$$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
			set_cfg_pos($$);
		}else{
			yyerror_at(&$2->fpos, "bad while(...) expression");
			YYERROR;
		}
	}
;

/* class_id:
	LBRACK ATTR_USER RBRACK { $$ = AVP_CLASS_USER; }
	| LBRACK ATTR_DOMAIN RBRACK { $$ = AVP_CLASS_DOMAIN; }
	| LBRACK ATTR_GLOBAL RBRACK { $$ = AVP_CLASS_GLOBAL; }
	;
*/
select_param:
	ID {
		if (sel.n >= MAX_SELECT_PARAMS-1) {
			yyerror("Select identifier too long\n");
		}
		sel.params[sel.n].type = SEL_PARAM_STR;
		sel.params[sel.n].v.s.s = $1;
		sel.params[sel.n].v.s.len = strlen($1);
		sel.n++;
	}
	| ID LBRACK intno RBRACK {
		if (sel.n >= MAX_SELECT_PARAMS-2) {
			yyerror("Select identifier too long\n");
		}
		sel.params[sel.n].type = SEL_PARAM_STR;
		sel.params[sel.n].v.s.s = $1;
		sel.params[sel.n].v.s.len = strlen($1);
		sel.n++;
		sel.params[sel.n].type = SEL_PARAM_INT;
		sel.params[sel.n].v.i = $3;
		sel.n++;
	}
	| ID LBRACK STRING RBRACK {
		if (sel.n >= MAX_SELECT_PARAMS-2) {
			yyerror("Select identifier too long\n");
		}
		sel.params[sel.n].type = SEL_PARAM_STR;
		sel.params[sel.n].v.s.s = $1;
		sel.params[sel.n].v.s.len = strlen($1);
		sel.n++;
		sel.params[sel.n].type = SEL_PARAM_STR;
		sel.params[sel.n].v.s.s = $3;
		sel.params[sel.n].v.s.len = strlen($3);
		sel.n++;
	}
	;
select_params:
	select_params DOT select_param
	| select_param
	;
select_id:
	SELECT_MARK { sel.n = 0; sel.f[0] = 0; } select_params {
		sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
		if (!sel_ptr) {
			yyerror("No memory left to allocate select structure\n");
		}
		memcpy(sel_ptr, &sel, sizeof(select_t));
		$$ = sel_ptr;
	}
	;
attr_class_spec:
	ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
	| ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
        | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
        | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
	| ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
	| ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
	| ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
	| ATTR_TODOMAIN { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_DOMAIN; }
	| ATTR_GLOBAL { s_attr->type |= AVP_TRACK_ALL | AVP_CLASS_GLOBAL; }
	;
attr_name_spec:
	ID { s_attr->type |= AVP_NAME_STR; s_attr->name.s.s = $1; s_attr->name.s.len = strlen ($1); }
	;
attr_spec:
	attr_name_spec
	| attr_class_spec DOT attr_name_spec
	;
attr_mark:
	ATTR_MARK {
		s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
		if (!s_attr) { yyerror("No memory left"); YYABORT; }
		else s_attr->type = 0;
	}
	;
attr_id:
	attr_mark attr_spec { $$ = s_attr; }
	;
attr_id_num_idx:
	attr_mark attr_spec LBRACK intno RBRACK {
		s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
		s_attr->index = ($4<0?-$4:$4);
		$$ = s_attr;
	}
	;
attr_id_no_idx:
	attr_mark attr_spec LBRACK RBRACK {
		s_attr->type|= AVP_INDEX_ALL;
		$$ = s_attr;
	}
	;
attr_id_ass:
	attr_id
	| attr_id_no_idx
	;
/*
attr_id_val:
	attr_id
	| attr_id_num_idx
	;
*/
attr_id_any:
	attr_id
	| attr_id_no_idx
	| attr_id_num_idx
;
attr_id_any_str:
	attr_id
	| avp_pvar {
		if ($1->type==LV_AVP){
			s_attr = pkg_malloc(sizeof(struct avp_spec));
			if (!s_attr) { yyerror("No memory left"); YYABORT; }
			else{
				*s_attr=$1->lv.avps;
			}
			$$=s_attr;
		}else
			$$=0; /* not an avp, a pvar */
		pkg_free($1);
	}
	| STRING {
		avp_spec_t *avp_spec;
		str s;
		int type, idx;
		avp_spec = pkg_malloc(sizeof(*avp_spec));
		if (!avp_spec) {
			yyerror("Not enough memory");
			YYABORT;
		}
		s.s = $1;
		if (s.s[0] == '$')
			s.s++;
		s.len = strlen(s.s);
		if (parse_avp_name(&s, &type, &avp_spec->name, &idx)) {
			yyerror("error when parsing AVP");
			pkg_free(avp_spec);
			YYABORT;
		}
		avp_spec->type = type;
		avp_spec->index = idx;
		$$ = avp_spec;
	}
	;

pvar:	PVAR {
			s_tmp.s=$1; s_tmp.len=strlen($1);
			pv_spec=pv_cache_get(&s_tmp);
			if (!pv_spec) {
				yyerror("Can't get from cache: %s", $1);
				YYABORT;
			}
			$$=pv_spec;
		}
	;

avp_pvar:	AVP_OR_PVAR {
				lval_tmp=pkg_malloc(sizeof(*lval_tmp));
				if (!lval_tmp) {
					yyerror("Not enough memory");
					YYABORT;
				}
				memset(lval_tmp, 0, sizeof(*lval_tmp));
				s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
				lval_tmp->lv.pvs = pv_cache_get(&s_tmp);
				if (lval_tmp->lv.pvs==NULL){
					lval_tmp->lv.avps.type|= AVP_NAME_STR;
					lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
					lval_tmp->lv.avps.name.s.len = s_tmp.len-1;
					lval_tmp->type=LV_AVP;
				}else{
					lval_tmp->type=LV_PVAR;
				}
				$$ = lval_tmp;
				DBG("parsed ambigous avp/pvar \"%.*s\" to %d\n",
							s_tmp.len, s_tmp.s, lval_tmp->type);
			}
	;


/*
assign_op:
	ADDEQ { $$ = ADD_T; }
	| EQUAL { $$ = ASSIGN_T; }
	;
*/
assign_op:
	EQUAL { $$ = ASSIGN_T; }
	;


lval: attr_id_ass {
					lval_tmp=pkg_malloc(sizeof(*lval_tmp));
					if (!lval_tmp) {
						yyerror("Not enough memory");
						YYABORT;
					}
					lval_tmp->type=LV_AVP; lval_tmp->lv.avps=*$1;
					pkg_free($1); /* free the avp spec we just copied */
					$$=lval_tmp;
				}
	| pvar        {
					if (!pv_is_w($1))
						yyerror("read only pvar in assignment left side");
					if ($1->trans!=0)
						yyerror("pvar with transformations in assignment"
								" left side");
					lval_tmp=pkg_malloc(sizeof(*lval_tmp));
					if (!lval_tmp) {
						yyerror("Not enough memory");
						YYABORT;
					}
					lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=$1;
					$$=lval_tmp;
				}
	| avp_pvar    {
					if (($1)->type==LV_PVAR){
						if (!pv_is_w($1->lv.pvs))
							yyerror("read only pvar in assignment left side");
						if ($1->lv.pvs->trans!=0)
							yyerror("pvar with transformations in assignment"
									" left side");
					}
					$$=$1;
				}
	;

rval: intno			{$$=mk_rve_rval(RV_INT, (void*)$1); }
	| STRING			{	s_tmp.s=$1; s_tmp.len=strlen($1);
							$$=mk_rve_rval(RV_STR, &s_tmp); }
	| attr_id_any		{$$=mk_rve_rval(RV_AVP, $1); pkg_free($1); }
	| pvar				{$$=mk_rve_rval(RV_PVAR, $1); }
	| avp_pvar			{
							switch($1->type){
								case LV_AVP:
									$$=mk_rve_rval(RV_AVP, &$1->lv.avps);
									break;
								case LV_PVAR:
									$$=mk_rve_rval(RV_PVAR, $1->lv.pvs);
									break;
								default:
									yyerror("BUG: invalid lvalue type ");
									YYABORT;
							}
							pkg_free($1); /* not needed anymore */
						}
	| select_id			{$$=mk_rve_rval(RV_SEL, $1); pkg_free($1); }
	| fcmd				{$$=mk_rve_rval(RV_ACTION_ST, $1); }
	| exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
	| LBRACE actions RBRACE	{$$=mk_rve_rval(RV_ACTION_ST, $2); }
	| LBRACE error RBRACE	{ $$=0; yyerror("bad command block"); }
	| LPAREN assign_action RPAREN	{$$=mk_rve_rval(RV_ACTION_ST, $2); }
	| LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
	;


rve_un_op: NOT	{ $$=RVE_LNOT_OP; }
		|  BIN_NOT 	{ $$=RVE_BNOT_OP; }
		|  MINUS %prec UNARY	{ $$=RVE_UMINUS_OP; }
		/* TODO: RVE_BOOL_OP, RVE_NOT_OP? */
	;

/*
rve_op:		PLUS		{ $$=RVE_PLUS_OP; }
		|	MINUS		{ $$=RVE_MINUS_OP; }
		|	STAR		{ $$=RVE_MUL_OP; }
		|	SLASH		{ $$=RVE_DIV_OP; }
		|	MODULO		{ $$=RVE_MOD_OP; }
	;
*/

rval_expr: rval						{ $$=$1;
										if ($$==0){
											/*yyerror("out of memory\n");*/
											YYERROR;
										}
									}
		| rve_un_op rval_expr %prec UNARY	{$$=mk_rve1($1, $2); }
		| INTCAST rval_expr				{$$=mk_rve1(RVE_INT_OP, $2); }
		| STRCAST rval_expr				{$$=mk_rve1(RVE_STR_OP, $2); }
		| rval_expr PLUS rval_expr		{$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
		| rval_expr MINUS rval_expr		{$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
		| rval_expr STAR rval_expr		{$$=mk_rve2(RVE_MUL_OP, $1, $3); }
		| rval_expr SLASH rval_expr		{$$=mk_rve2(RVE_DIV_OP, $1, $3); }
		| rval_expr MODULO rval_expr	{$$=mk_rve2(RVE_MOD_OP, $1, $3); }
		| rval_expr BIN_OR rval_expr	{$$=mk_rve2(RVE_BOR_OP, $1,  $3); }
		| rval_expr BIN_AND rval_expr	{$$=mk_rve2(RVE_BAND_OP, $1,  $3);}
		| rval_expr BIN_XOR rval_expr	{$$=mk_rve2(RVE_BXOR_OP, $1,  $3);}
		| rval_expr BIN_LSHIFT rval_expr {$$=mk_rve2(RVE_BLSHIFT_OP, $1,  $3);}
		| rval_expr BIN_RSHIFT rval_expr {$$=mk_rve2(RVE_BRSHIFT_OP, $1,  $3);}
		| rval_expr rve_cmpop rval_expr %prec GT { $$=mk_rve2( $2, $1, $3);}
		| rval_expr rve_equalop rval_expr %prec EQUAL_T {
			/* comparing with $null => treat as defined or !defined */
			if($3->op==RVE_RVAL_OP && $3->left.rval.type==RV_PVAR
					&& $3->left.rval.v.pvs.type==PVT_NULL) {
				if($2==RVE_DIFF_OP || $2==RVE_IDIFF_OP
						|| $2==RVE_STRDIFF_OP) {
					DBG("comparison with $null switched to notdefined operator\n");
					$$=mk_rve1(RVE_DEFINED_OP, $1);
				} else {
					DBG("comparison with $null switched to defined operator\n");
					$$=mk_rve1(RVE_NOTDEFINED_OP, $1);
				}
				/* free rve struct for $null */
				rve_destroy($3);
			} else {
				$$=mk_rve2($2, $1, $3);
			}
		}
		| rval_expr LOG_AND rval_expr	{ $$=mk_rve2(RVE_LAND_OP, $1, $3);}
		| rval_expr LOG_OR rval_expr	{ $$=mk_rve2(RVE_LOR_OP, $1, $3);}
		| LPAREN rval_expr RPAREN		{ $$=$2;}
		| STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
		| STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
		| DEFINED rval_expr				{ $$=mk_rve1(RVE_DEFINED_OP, $2);}
		| rve_un_op error %prec UNARY 		{ $$=0; yyerror("bad expression"); }
		| INTCAST error					{ $$=0; yyerror("bad expression"); }
		| STRCAST error					{ $$=0; yyerror("bad expression"); }
		| rval_expr PLUS error			{ $$=0; yyerror("bad expression"); }
		| rval_expr MINUS error			{ $$=0; yyerror("bad expression"); }
		| rval_expr STAR error			{ $$=0; yyerror("bad expression"); }
		| rval_expr SLASH error			{ $$=0; yyerror("bad expression"); }
		| rval_expr MODULO error			{ $$=0; yyerror("bad expression"); }
		| rval_expr BIN_OR error		{ $$=0; yyerror("bad expression"); }
		| rval_expr BIN_AND error		{ $$=0; yyerror("bad expression"); }
		| rval_expr rve_cmpop error %prec GT
			{ $$=0; yyerror("bad expression"); }
		| rval_expr rve_equalop error %prec EQUAL_T
			{ $$=0; yyerror("bad expression"); }
		| rval_expr LOG_AND error		{ $$=0; yyerror("bad expression"); }
		| rval_expr LOG_OR error		{ $$=0; yyerror("bad expression"); }
		| STRLEN LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
		| STREMPTY LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
		| DEFINED error					{ $$=0; yyerror("bad expression"); }
		;

assign_action: lval assign_op  rval_expr	{ $$=mk_action($2, 2, LVAL_ST, $1, 
														 	  RVE_ST, $3);
											set_cfg_pos($$);
										}
	;

/*
assign_action:
	attr_id_ass assign_op STRING  { $$=mk_action($2, 2, AVP_ST, $1, STRING_ST, $3); }
	| attr_id_ass assign_op NUMBER  { $$=mk_action($2, 2, AVP_ST, $1, NUMBER_ST, (void*)$3); }
	| attr_id_ass assign_op fcmd    { $$=mk_action($2, 2, AVP_ST, $1, ACTION_ST, $3); }
	| attr_id_ass assign_op attr_id_any { $$=mk_action($2, 2, AVP_ST, $1, AVP_ST, $3); }
	| attr_id_ass assign_op select_id { $$=mk_action($2, 2, AVP_ST, (void*)$1, SELECT_ST, (void*)$3); }
	| attr_id_ass assign_op LPAREN exp RPAREN { $$ = mk_action($2, 2, AVP_ST, $1, EXPR_ST, $4); }
	;
*/

avpflag_oper:
	SETAVPFLAG { $$ = 1; }
	| RESETAVPFLAG { $$ = 0; }
	| ISAVPFLAGSET { $$ = -1; }
	;
cmd:
	FORWARD LPAREN RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
	| FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD LPAREN STRING RPAREN	{ $$=mk_action(	FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD LPAREN ip RPAREN	{ $$=mk_action(	FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD LPAREN URIHOST COMMA URIPORT RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
	| FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
	| FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward argument"); }
	| FORWARD_UDP LPAREN host RPAREN	{ $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN STRING RPAREN	{ $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN ip RPAREN	{ $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_UDP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
	| FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp argument"); }
	| FORWARD_TCP LPAREN host RPAREN	{ $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN STRING RPAREN	{ $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN ip RPAREN	{ $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
	| FORWARD_TCP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
	| FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
	| FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp argument"); }
	| FORWARD_TLS LPAREN host RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS LPAREN STRING RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS LPAREN ip RPAREN	{
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS LPAREN host COMMA NUMBER RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
					}
	| FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS LPAREN URIHOST RPAREN {
		#ifdef USE_TLS
			$$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
	| FORWARD_TLS LPAREN error RPAREN { $$=0; 
									yyerror("bad forward_tls argument"); }
	| FORWARD_SCTP LPAREN host RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
	}
	| FORWARD_SCTP LPAREN STRING RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
	}
	| FORWARD_SCTP LPAREN ip RPAREN	{
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
	}
	| FORWARD_SCTP LPAREN host COMMA NUMBER RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
							(void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
	}
	| FORWARD_SCTP LPAREN STRING COMMA NUMBER RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
							(void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
	}
	| FORWARD_SCTP LPAREN ip COMMA NUMBER RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 
							(void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
					}
	| FORWARD_SCTP LPAREN URIHOST COMMA URIPORT RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
	}
	| FORWARD_SCTP LPAREN URIHOST COMMA NUMBER RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST,
							(void*)$5); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("sctp support not compiled in");
		#endif
	}
	| FORWARD_SCTP LPAREN URIHOST RPAREN {
		#ifdef USE_SCTP
			$$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$);
		#else
			$$=0;
			yyerror("tls support not compiled in");
		#endif
	}
	| FORWARD_SCTP error { $$=0; yyerror("missing '(' or ')' ?"); }
	| FORWARD_SCTP LPAREN error RPAREN { $$=0; 
									yyerror("bad forward_sctp argument"); }
	| LOG_TOK LPAREN STRING RPAREN	{$$=mk_action(LOG_T, 2, NUMBER_ST,
										(void*)(L_DBG+1), STRING_ST, $3);
									set_cfg_pos($$); }
	| LOG_TOK LPAREN NUMBER COMMA STRING RPAREN	{$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)$3, STRING_ST, $5); set_cfg_pos($$); }
	| LOG_TOK error 		{ $$=0; yyerror("missing '(' or ')' ?"); }
	| LOG_TOK LPAREN error RPAREN	{ $$=0; yyerror("bad log argument"); }
	| SETFLAG LPAREN NUMBER RPAREN	{
							if (check_flag($3)==-1)
								yyerror("bad flag value");
							$$=mk_action(SETFLAG_T, 1, NUMBER_ST,
													(void*)$3);
							set_cfg_pos($$);
									}
	| SETFLAG LPAREN flag_name RPAREN	{
							i_tmp=get_flag_no($3, strlen($3));
							if (i_tmp<0) yyerror("flag not declared");
							$$=mk_action(SETFLAG_T, 1, NUMBER_ST,
										(void*)(long)i_tmp);
							set_cfg_pos($$);
									}
	| SETFLAG error			{ $$=0; yyerror("missing '(' or ')'?"); }
	| RESETFLAG LPAREN NUMBER RPAREN {
							if (check_flag($3)==-1)
								yyerror("bad flag value");
							$$=mk_action(RESETFLAG_T, 1, NUMBER_ST, (void*)$3);
							set_cfg_pos($$);
									}
	| RESETFLAG LPAREN flag_name RPAREN	{
							i_tmp=get_flag_no($3, strlen($3));
							if (i_tmp<0) yyerror("flag not declared");
							$$=mk_action(RESETFLAG_T, 1, NUMBER_ST,
										(void*)(long)i_tmp);
							set_cfg_pos($$);
									}
	| RESETFLAG error		{ $$=0; yyerror("missing '(' or ')'?"); }
	| ISFLAGSET LPAREN NUMBER RPAREN {
							if (check_flag($3)==-1)
								yyerror("bad flag value");
							$$=mk_action(ISFLAGSET_T, 1, NUMBER_ST, (void*)$3);
							set_cfg_pos($$);
									}
	| ISFLAGSET LPAREN flag_name RPAREN	{
							i_tmp=get_flag_no($3, strlen($3));
							if (i_tmp<0) yyerror("flag not declared");
							$$=mk_action(ISFLAGSET_T, 1, NUMBER_ST,
										(void*)(long)i_tmp);
							set_cfg_pos($$);
									}
	| ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
	| avpflag_oper LPAREN attr_id_any_str COMMA flag_name RPAREN {
		i_tmp=get_avpflag_no($5);
		if (i_tmp==0) yyerror("avpflag not declared");
		$$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
		set_cfg_pos($$);
	}
	| avpflag_oper LPAREN attr_id_any_str COMMA error RPAREN {
		$$=0; yyerror("error parsing flag name");
	}
	| avpflag_oper LPAREN error COMMA flag_name RPAREN {
		$$=0; yyerror("error parsing first parameter (avp or string)");
	}
	| avpflag_oper LPAREN error RPAREN { $$=0; yyerror("bad parameters"); }
	| avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
	| ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5);
			set_cfg_pos($$);
	}
	| ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
	| ERROR LPAREN error RPAREN { $$=0; yyerror("bad error argument"); }
	| ROUTE LPAREN rval_expr RPAREN	{
		if ($3) {
			$$ = mk_action(ROUTE_T, 1, RVE_ST, (void*)$3);
			set_cfg_pos($$);
		} else {
			$$ = 0;
			YYERROR;
		}
	}
	| ROUTE LPAREN ID RPAREN	{
		if ($3) {
			$$ = mk_action(ROUTE_T, 1, STRING_ST, (void*)$3);
			set_cfg_pos($$);
		} else {
			$$ = 0;
			YYERROR;
		}
	}
	| ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
	| ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route argument"); }
	| EXEC LPAREN STRING RPAREN	{ $$=mk_action(EXEC_T, 1, STRING_ST, $3); set_cfg_pos($$); }
	| SET_HOST LPAREN STRING RPAREN { $$=mk_action(SET_HOST_T, 1, STRING_ST, $3); set_cfg_pos($$); }
	| SET_HOST error { $$=0; yyerror("missing '(' or ')' ?"); }
	| SET_HOST LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| PREFIX LPAREN STRING RPAREN { $$=mk_action(PREFIX_T, 1, STRING_ST,  $3); set_cfg_pos($$); }
	| PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
	| PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| STRIP_TAIL LPAREN NUMBER RPAREN { $$=mk_action(STRIP_TAIL_T, 1, NUMBER_ST, (void*)$3); set_cfg_pos($$); }
	| STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
	| STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
	| STRIP LPAREN NUMBER RPAREN { $$=mk_action(STRIP_T, 1, NUMBER_ST, (void*) $3); set_cfg_pos($$); }
	| STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
	| STRIP LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
	| SET_USERPHONE LPAREN RPAREN { $$=mk_action(SET_USERPHONE_T, 0); set_cfg_pos($$); }
	| SET_USERPHONE error { $$=0; yyerror("missing '(' or ')' ?"); }
	| REMOVE_BRANCH LPAREN intno RPAREN {
			$$=mk_action(REMOVE_BRANCH_T, 1, NUMBER_ST, (void*)$3);
			set_cfg_pos($$);
	}
	| REMOVE_BRANCH LPAREN RPAREN {
			$$=mk_action(REMOVE_BRANCH_T, 0);
			set_cfg_pos($$);
	}
	| REMOVE_BRANCH error { $$=0; yyerror("missing '(' or ')' ?"); }
	| REMOVE_BRANCH LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
	| CLEAR_BRANCHES LPAREN RPAREN { $$=mk_action(CLEAR_BRANCHES_T, 0); set_cfg_pos($$); }
	| SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORT_T, 1, STRING_ST, $3); set_cfg_pos($$); }
	| SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
	| SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| SET_HOSTPORTTRANS LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORTTRANS_T, 1, STRING_ST, $3); set_cfg_pos($$); }
	| SET_HOSTPORTTRANS error { $$=0; yyerror("missing '(' or ')' ?"); }
	| SET_HOSTPORTTRANS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| SET_PORT LPAREN STRING RPAREN { $$=mk_action(SET_PORT_T, 1, STRING_ST, $3); set_cfg_pos($$); }
	| SET_PORT error { $$=0; yyerror("missing '(' or ')' ?"); }
	| SET_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| SET_USER LPAREN STRING RPAREN { $$=mk_action(SET_USER_T, 1, STRING_ST, $3); set_cfg_pos($$); }
	| SET_USER error { $$=0; yyerror("missing '(' or ')' ?"); }
	| SET_USER LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| SET_USERPASS LPAREN STRING RPAREN { $$=mk_action(SET_USERPASS_T, 1, STRING_ST, $3); set_cfg_pos($$); }
	| SET_USERPASS error { $$=0; yyerror("missing '(' or ')' ?"); }
	| SET_USERPASS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| SET_URI LPAREN STRING RPAREN { $$=mk_action(SET_URI_T, 1, STRING_ST,$3); set_cfg_pos($$); }
	| SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
	| SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| REVERT_URI LPAREN RPAREN { $$=mk_action(REVERT_URI_T, 0); set_cfg_pos($$); }
	| REVERT_URI { $$=mk_action(REVERT_URI_T, 0); set_cfg_pos($$); }
	| FORCE_RPORT LPAREN RPAREN	{ $$=mk_action(FORCE_RPORT_T, 0); set_cfg_pos($$); }
	| FORCE_RPORT	{$$=mk_action(FORCE_RPORT_T, 0); set_cfg_pos($$); }
	| ADD_LOCAL_RPORT LPAREN RPAREN	{ $$=mk_action(ADD_LOCAL_RPORT_T, 0); set_cfg_pos($$); }
	| ADD_LOCAL_RPORT	{$$=mk_action(ADD_LOCAL_RPORT_T, 0); set_cfg_pos($$); }
	| FORCE_TCP_ALIAS LPAREN NUMBER RPAREN	{
		#ifdef USE_TCP
			$$=mk_action(FORCE_TCP_ALIAS_T, 1, NUMBER_ST, (void*)$3);
			set_cfg_pos($$);
		#else
			yyerror("tcp support not compiled in");
		#endif
	}
	| FORCE_TCP_ALIAS LPAREN RPAREN	{
		#ifdef USE_TCP
			$$=mk_action(FORCE_TCP_ALIAS_T, 0);
			set_cfg_pos($$);
		#else
			yyerror("tcp support not compiled in");
		#endif
	}
	| FORCE_TCP_ALIAS				{
		#ifdef USE_TCP
			$$=mk_action(FORCE_TCP_ALIAS_T, 0);
			set_cfg_pos($$);
		#else
			yyerror("tcp support not compiled in");
		#endif
	}
	| FORCE_TCP_ALIAS LPAREN error RPAREN	{$$=0; yyerror("bad argument, number expected"); }
	| UDP_MTU_TRY_PROTO LPAREN proto RPAREN
		{ $$=mk_action(UDP_MTU_TRY_PROTO_T, 1, NUMBER_ST, $3); set_cfg_pos($$); }
	| UDP_MTU_TRY_PROTO LPAREN error RPAREN
		{ $$=0; yyerror("bad argument, UDP, TCP, TLS or SCTP expected"); }
	| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
		$$=0;
		if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
		} else {
			str_tmp->s=$3;
			str_tmp->len=$3?strlen($3):0;
			$$=mk_action(SET_ADV_ADDR_T, 1, STR_ST, str_tmp);
			set_cfg_pos($$);
		}
	}
	| SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
	| SET_ADV_PORT LPAREN NUMBER RPAREN {
		$$=0;
		tmp=int2str($3, &i_tmp);
		if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
		} else {
			if ((str_tmp->s=pkg_malloc(i_tmp))==0) {
				LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
			} else {
				memcpy(str_tmp->s, tmp, i_tmp);
				str_tmp->len=i_tmp;
				$$=mk_action(SET_ADV_PORT_T, 1, STR_ST, str_tmp);
				set_cfg_pos($$);
			}
		}
	}
	| SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
	| SET_ADV_PORT  error {$$=0; yyerror("missing '(' or ')' ?"); }
	| FORCE_SEND_SOCKET LPAREN phostport RPAREN { 
		$$=mk_action(FORCE_SEND_SOCKET_T, 1, SOCKID_ST, $3);
		set_cfg_pos($$);
	}
	| FORCE_SEND_SOCKET LPAREN error RPAREN {
		$$=0; yyerror("bad argument, [proto:]host[:port] expected");
	}
	| FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
	| SET_FWD_NO_CONNECT LPAREN RPAREN	{
		$$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$);
	}
	| SET_FWD_NO_CONNECT	{
		$$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$);
	}
	| SET_RPL_NO_CONNECT LPAREN RPAREN	{
		$$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$);
	}
	| SET_RPL_NO_CONNECT	{
		$$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$);
	}
	| SET_FWD_CLOSE LPAREN RPAREN	{
		$$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$);
	}
	| SET_FWD_CLOSE	{
		$$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$);
	}
	| SET_RPL_CLOSE LPAREN RPAREN	{
		$$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$);
	}
	| SET_RPL_CLOSE	{
		$$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$);
	}
	| CFG_SELECT LPAREN STRING COMMA NUMBER RPAREN {
		$$=mk_action(CFG_SELECT_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
	}
	| CFG_SELECT LPAREN STRING COMMA rval_expr RPAREN {
		$$=mk_action(CFG_SELECT_T, 2, STRING_ST, $3, RVE_ST, $5); set_cfg_pos($$);
	}
	| CFG_SELECT error { $$=0; yyerror("missing '(' or ')' ?"); }
	| CFG_SELECT LPAREN error RPAREN { $$=0; yyerror("bad arguments, string and number expected"); }
	| CFG_RESET LPAREN STRING RPAREN {
		$$=mk_action(CFG_RESET_T, 1, STRING_ST, $3); set_cfg_pos($$);
	}
	| CFG_RESET error { $$=0; yyerror("missing '(' or ')' ?"); }
	| CFG_RESET LPAREN error RPAREN { $$=0; yyerror("bad arguments, string expected"); }
	| ID {mod_func_action = mk_action(MODULE0_T, 2, MODEXP_ST, NULL, NUMBER_ST,
			0); } LPAREN func_params RPAREN	{
		mod_func_action->val[0].u.data =
			find_export_record($1, mod_func_action->val[1].u.number, rt,
								&u_tmp);
		if (mod_func_action->val[0].u.data == 0) {
			if (find_export_record($1, mod_func_action->val[1].u.number, 0,
									&u_tmp) ) {
					LOG(L_ERR, "misused command %s\n", $1);
					yyerror("Command cannot be used in the block\n");
			} else {
				LOG(L_ERR, "cfg. parser: failed to find command %s (params %ld)\n",
						$1, mod_func_action->val[1].u.number);
				yyerror("unknown command, missing loadmodule?\n");
			}
			free_mod_func_action(mod_func_action);
			mod_func_action=0;
		}else{
			if (mod_func_action && mod_f_params_pre_fixup(mod_func_action)<0) {
				/* error messages are printed inside the function */
				free_mod_func_action(mod_func_action);
				mod_func_action = 0;
				YYERROR;
			}
		}
		$$ = mod_func_action;
		set_cfg_pos($$);
	}
	| ID error					{ yyerror("'('')' expected (function call)");}
	;
func_params:
	/* empty */
	| func_params COMMA func_param { }
	| func_param {}
	;
func_param:
	rval_expr {
		if ($1 && mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
			mod_func_action->val[mod_func_action->val[1].u.number+2].type =
				RVE_ST;
			mod_func_action->val[mod_func_action->val[1].u.number+2].u.data =
				$1;
			mod_func_action->val[1].u.number++;
		} else if ($1) {
			yyerror("Too many arguments\n");
			YYERROR;
		} else {
			YYERROR;
		}
	}
	;

ret_cmd:
	DROP LPAREN RPAREN		{
		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST,
						(void*)(DROP_R_F|EXIT_R_F)); set_cfg_pos($$);
	}
	| DROP rval_expr	{
		$$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST,
						(void*)(DROP_R_F|EXIT_R_F)); set_cfg_pos($$);
	}
	| DROP				{
		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, 
						(void*)(DROP_R_F|EXIT_R_F)); set_cfg_pos($$);
	}
	| EXIT LPAREN RPAREN		{
		$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
						(void*)EXIT_R_F);
		set_cfg_pos($$);
	}
	| EXIT rval_expr	{
		$$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)EXIT_R_F);
		set_cfg_pos($$);
	}
	| EXIT				{
		$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
						(void*)EXIT_R_F);
		set_cfg_pos($$);
	}
	| RETURN			{
		$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
						(void*)RETURN_R_F); set_cfg_pos($$);
	}
	| RETURN  LPAREN RPAREN		{
		$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
						(void*)RETURN_R_F); set_cfg_pos($$);
	}
	| RETURN rval_expr	{
		$$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)RETURN_R_F);
		set_cfg_pos($$);
	}
	| BREAK				{
		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)BREAK_R_F);
		set_cfg_pos($$);
	}
	;

%%

static void get_cpos(struct cfg_pos* pos)
{
	pos->s_line=startline;
	pos->e_line=line;
	pos->s_col=startcolumn;
	pos->e_col=column-1;
	if(finame==0)
		finame = (cfg_file!=0)?cfg_file:"default";
	pos->fname=finame;
	pos->rname=(routename!=0)?routename:default_routename;
}


static void warn_at(struct cfg_pos* p, char* format, ...)
{
	va_list ap;
	char s[256];
	
	va_start(ap, format);
	vsnprintf(s, sizeof(s), format, ap);
	va_end(ap);
	if (p->e_line!=p->s_line)
		LOG(L_WARN, "warning in config file %s, from line %d, column %d to"
					" line %d, column %d: %s\n",
					p->fname, p->s_line, p->s_col, p->e_line, p->e_col, s);
	else if (p->s_col!=p->e_col)
		LOG(L_WARN, "warning in config file %s, line %d, column %d-%d: %s\n",
					p->fname, p->s_line, p->s_col, p->e_col, s);
	else
		LOG(L_WARN, "warning in config file %s, line %d, column %d: %s\n",
				p->fname, p->s_line, p->s_col, s);
	cfg_warnings++;
}



static void yyerror_at(struct cfg_pos* p, char* format, ...)
{
	va_list ap;
	char s[256];
	
	va_start(ap, format);
	vsnprintf(s, sizeof(s), format, ap);
	va_end(ap);
	if (p->e_line!=p->s_line)
		LOG(L_CRIT, "parse error in config file %s, from line %d, column %d"
					" to line %d, column %d: %s\n",
					p->fname, p->s_line, p->s_col, p->e_line, p->e_col, s);
	else if (p->s_col!=p->e_col)
		LOG(L_CRIT,"parse error in config file %s, line %d, column %d-%d: %s\n",
					p->fname, p->s_line, p->s_col, p->e_col, s);
	else
		LOG(L_CRIT, "parse error in config file %s, line %d, column %d: %s\n",
					p->fname, p->s_line, p->s_col, s);
	cfg_errors++;
}



static void warn(char* format, ...)
{
	va_list ap;
	char s[256];
	struct cfg_pos pos;
	
	get_cpos(&pos);
	va_start(ap, format);
	vsnprintf(s, sizeof(s), format, ap);
	va_end(ap);
	warn_at(&pos, s);
}



static void yyerror(char* format, ...)
{
	va_list ap;
	char s[256];
	struct cfg_pos pos;
	
	get_cpos(&pos);
	va_start(ap, format);
	vsnprintf(s, sizeof(s), format, ap);
	va_end(ap);
	yyerror_at(&pos, s);
}



/** mk_rval_expr_v wrapper.
 *  checks mk_rval_expr_v return value and sets the cfg. pos
 *  (line and column numbers)
 *  @return rval_expr* on success, 0 on error (@see mk_rval_expr_v)
 */
static struct rval_expr* mk_rve_rval(enum rval_type type, void* v)
{
	struct rval_expr* ret;
	struct cfg_pos pos;

	get_cpos(&pos);
	ret=mk_rval_expr_v(type, v, &pos);
	if (ret==0){
		yyerror("internal error: failed to create rval expr");
		/* YYABORT; */
	}
	return ret;
}


/** mk_rval_expr1 wrapper.
 *  checks mk_rval_expr1 return value (!=0 and type checking)
 *  @return rval_expr* on success, 0 on error (@see mk_rval_expr1)
 */
static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1)
{
	struct rval_expr* ret;
	struct rval_expr* bad_rve;
	enum rval_type type, bad_t, exp_t;
	
	if (rve1==0)
		return 0;
	ret=mk_rval_expr1(op, rve1, &rve1->fpos);
	if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
		yyerror_at(&rve1->fpos, "bad expression: type mismatch"
					" (%s instead of %s)", rval_type_name(bad_t),
					rval_type_name(exp_t));
		rve_destroy(ret);
		ret=0;
	}
	return ret;
}


/** mk_rval_expr2 wrapper.
 *  checks mk_rval_expr2 return value (!=0 and type checking)
 *  @return rval_expr* on success, 0 on error (@see mk_rval_expr2)
 */
static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
									struct rval_expr* rve2)
{
	struct rval_expr* ret;
	struct rval_expr* bad_rve;
	enum rval_type type, bad_t, exp_t;
	struct cfg_pos pos;
	
	if ((rve1==0) || (rve2==0))
		return 0;
	bad_rve=0;
	bad_t=0;
	exp_t=0;
	cfg_pos_join(&pos, &rve1->fpos, &rve2->fpos);
	ret=mk_rval_expr2(op, rve1, rve2, &pos);
	if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
		if (bad_rve)
			yyerror_at(&pos, "bad expression: type mismatch:"
						" %s instead of %s at (%d,%d)",
						rval_type_name(bad_t), rval_type_name(exp_t),
						bad_rve->fpos.s_line, bad_rve->fpos.s_col);
		else
			yyerror("BUG: unexpected null \"bad\" expression\n");
		rve_destroy(ret);
		ret=0;
	}
	return ret;
}


/** check if the expression is an int.
 * if the expression does not evaluate to an int return -1 and
 * log an error.
 * @return 0 success, no warnings; 1 success but warnings; -1 on error */
static int rval_expr_int_check(struct rval_expr *rve)
{
	struct rval_expr* bad_rve;
	enum rval_type type, bad_t, exp_t;
	
	if (rve==0){
		yyerror("invalid expression");
		return -1;
	}else if (!rve_check_type(&type, rve, &bad_rve, &bad_t ,&exp_t)){
		if (bad_rve)
			yyerror_at(&rve->fpos, "bad expression: type mismatch:"
						" %s instead of %s at (%d,%d)",
						rval_type_name(bad_t), rval_type_name(exp_t),
						bad_rve->fpos.s_line, bad_rve->fpos.s_col);
		else
			yyerror("BUG: unexpected null \"bad\" expression\n");
		return -1;
	}else if (type!=RV_INT && type!=RV_NONE){
		warn_at(&rve->fpos, "non-int expression (you might want to use"
				" casts)\n");
		return 1;
	}
	return 0;
}


/** warn if the expression is constant.
 * @return 0 on success (no warning), 1 when warning */
static int warn_ct_rve(struct rval_expr *rve, char* name)
{
	if (rve && rve_is_constant(rve)){
		warn_at(&rve->fpos, "constant value in %s%s",
				name?name:"expression", name?"(...)":"");
		return 1;
	}
	return 0;
}


static struct name_lst* mk_name_lst(char* host, int flags)
{
	struct name_lst* l;
	if (host==0) return 0;
	l=pkg_malloc(sizeof(struct name_lst));
	if (l==0) {
		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
	} else {
		l->name=host;
		l->flags=flags;
		l->next=0;
	}
	return l;
}


static struct socket_id* mk_listen_id(char* host, int proto, int port)
{
	struct socket_id* l;
	if (host==0) return 0;
	l=pkg_malloc(sizeof(struct socket_id));
	if (l==0) {
		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
	} else {
		l->addr_lst=mk_name_lst(host, 0);
		if (l->addr_lst==0){
			pkg_free(l);
			return 0;
		}
		l->flags=0;
		l->port=port;
		l->proto=proto;
		l->next=0;
	}
	return l;
}


static void free_name_lst(struct name_lst* lst)
{
	struct name_lst* tmp;
	
	while(lst){
		tmp=lst;
		lst=lst->next;
		pkg_free(tmp);
	}
}


static struct socket_id* mk_listen_id2(struct name_lst* addr_l, int proto,
										int port)
{
	struct socket_id* l;
	if (addr_l==0) return 0;
	l=pkg_malloc(sizeof(struct socket_id));
	if (l==0) {
		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
	} else {
		l->flags=addr_l->flags;
		l->port=port;
		l->proto=proto;
		l->addr_lst=addr_l;
		l->next=0;
	}
	return l;
}


static void free_socket_id(struct socket_id* i)
{
	free_name_lst(i->addr_lst);
	pkg_free(i);
}


static void free_socket_id_lst(struct socket_id* lst)
{
	struct socket_id* tmp;
	
	while(lst){
		tmp=lst;
		lst=lst->next;
		free_socket_id(tmp);
	}
}


/** create a temporary case statmenet structure.
 *  *err will be filled in case of error (return == 0):
 *   -1 - non constant expression
 *   -2 - expression error (bad type)
 *   -10 - memory allocation error
 */
static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re,
											struct action* a, int* err)
{
	struct case_stms* s;
	struct rval_expr* bad_rve;
	enum rval_type type, bad_t, exp_t;
	enum match_str_type t;
	
	t=MATCH_UNKNOWN;
	if (ct){
		/* if ct!=0 => case, else if ct==0 is a default */
		if (!rve_is_constant(ct)){
			yyerror_at(&ct->fpos, "non constant expression in case");
			*err=-1;
			return 0;
		}
		if (rve_check_type(&type, ct, &bad_rve, &bad_t, &exp_t)!=1){
			yyerror_at(&ct->fpos, "bad expression: type mismatch:"
							" %s instead of %s at (%d,%d)",
							rval_type_name(bad_t), rval_type_name(exp_t),
							bad_rve->fpos.s_line, bad_rve->fpos.s_col);
			*err=-2;
			return 0;
		}
		if (is_re)
			t=MATCH_RE;
		else if (type==RV_STR)
			t=MATCH_STR;
		else
			t=MATCH_INT;
	}

	s=pkg_malloc(sizeof(*s));
	if (s==0) {
		yyerror("internal error: memory allocation failure");
		*err=-10;
	} else {
		memset(s, 0, sizeof(*s));
		s->ct_rve=ct;
		s->type=t;
		s->actions=a;
		s->next=0;
		s->append=0;
	}
	return s;
}


/*
 * @return 0 on success, -1 on error.
 */
static int case_check_type(struct case_stms* stms)
{
	struct case_stms* c;
	struct case_stms* s;
	
	for(c=stms; c ; c=c->next){
		if (!c->ct_rve) continue;
		for (s=c->next; s; s=s->next){
			if (!s->ct_rve) continue;
			if ((s->type!=c->type) &&
				!(	(c->type==MATCH_STR || c->type==MATCH_RE) &&
					(s->type==MATCH_STR || s->type==MATCH_RE) ) ){
					yyerror_at(&s->ct_rve->fpos, "type mismatch in case");
					return -1;
			}
		}
	}
	return 0;
}


/*
 * @return 0 on success, -1 on error.
 */
static int case_check_default(struct case_stms* stms)
{
	struct case_stms* c;
	int default_no;
	
	default_no=0;
	for(c=stms; c ; c=c->next)
		if (c->ct_rve==0) default_no++;
	return (default_no<=1)?0:-1;
}



/** fixes the parameters and the type of a module function call.
 * It is done here instead of fix action, to have quicker feedback
 * on error cases (e.g. passing a non constant to a function with a 
 * declared fixup) 
 * The rest of the fixup is done inside do_action().
 * @param a - filled module function call (MODULE*_T) action structure
 *            complete with parameters, starting at val[2] and parameter
 *            number at val[1].
 * @return 0 on success, -1 on error (it will also print the error msg.).
 *
 */
static int mod_f_params_pre_fixup(struct action* a)
{
	sr31_cmd_export_t* cmd_exp;
	action_u_t* params;
	int param_no;
	struct rval_expr* rve;
	struct rvalue* rv;
	int r;
	str s;
	
	cmd_exp = a->val[0].u.data;
	param_no = a->val[1].u.number;
	params = &a->val[2];
	
	switch(cmd_exp->param_no) {
		case 0:
			a->type = MODULE0_T;
			break;
		case 1:
			a->type = MODULE1_T;
			break;
		case 2:
			a->type = MODULE2_T;
			break;
		case 3:
			a->type = MODULE3_T;
			break;
		case 4:
			a->type = MODULE4_T;
			break;
		case 5:
			a->type = MODULE5_T;
			break;
		case 6:
			a->type = MODULE6_T;
			break;
		case VAR_PARAM_NO:
			a->type = MODULEX_T;
			break;
		default:
			yyerror("function %s: bad definition"
					" (invalid number of parameters)", cmd_exp->name);
			return -1;
	}
	
	if ( cmd_exp->fixup) {
		if (is_fparam_rve_fixup(cmd_exp->fixup))
			/* mark known fparam rve safe fixups */
			cmd_exp->fixup_flags  |= FIXUP_F_FPARAM_RVE;
		else if (!(cmd_exp->fixup_flags & FIXUP_F_FPARAM_RVE) &&
				 cmd_exp->free_fixup == 0) {
			/* v0 or v1 functions that have fixups and no coresp. fixup_free
			   functions, need constant, string params.*/
			for (r=0; r < param_no; r++) {
				rve=params[r].u.data;
				if (!rve_is_constant(rve)) {
					yyerror_at(&rve->fpos, "function %s: parameter %d is not"
								" constant\n", cmd_exp->name, r+1);
					return -1;
				}
				if ((rv = rval_expr_eval(0, 0, rve)) == 0 ||
						rval_get_str(0, 0, &s, rv, 0) < 0 ) {
					/* out of mem or bug ? */
					rval_destroy(rv);
					yyerror_at(&rve->fpos, "function %s: bad parameter %d"
									" expression\n", cmd_exp->name, r+1);
					return -1;
				}
				rval_destroy(rv);
				rve_destroy(rve);
				params[r].type = STRING_ST; /* asciiz */
				params[r].u.string = s.s;
				params[r].u.str.len = s.len; /* not used right now */
			}
		}
	}/* else
		if no fixups are present, the RVEs can be transformed
		into strings at runtime, allowing seamless var. use
		even with old functions.
		Further optimizations -> in fix_actions()
		*/
	return 0;
}



/** frees a filled module function call action structure.
 * @param a - filled module function call action structure
 *            complete with parameters, starting at val[2] and parameter
 *            number at val[1].
 */
static void free_mod_func_action(struct action* a)
{
	action_u_t* params;
	int param_no;
	int r;
	
	param_no = a->val[1].u.number;
	params = &a->val[2];
	
	for (r=0; r < param_no; r++)
		if (params[r].u.data)
			rve_destroy(params[r].u.data);
	pkg_free(a);
}



/*
int main(int argc, char ** argv)
{
	if (yyparse()!=0)
		fprintf(stderr, "parsing error\n");
}
*/