[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146]
[0147]
[0148]
[0149]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164]
[0165]
[0166]
[0167]
[0168]
[0169]
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184]
[0185]
[0186]
[0187]
[0188]
[0189]
[0190]
[0191]
[0192]
[0193]
[0194]
[0195]
[0196]
[0197]
[0198]
[0199]
[0200]
[0201]
[0202]
[0203]
[0204]
[0205]
[0206]
[0207]
[0208]
[0209]
[0210]
[0211]
[0212]
[0213]
[0214]
[0215]
[0216]
[0217]
[0218]
[0219]
[0220]
[0221]
[0222]
[0223]
[0224]
[0225]
[0226]
[0227]
[0228]
[0229]
[0230]
[0231]
[0232]
[0233]
[0234]
[0235]
[0236]
[0237]
[0238]
[0239]
[0240]
[0241]
[0242]
[0243]
[0244]
[0245]
[0246]
[0247]
[0248]
[0249]
[0250]
[0251]
[0252]
[0253]
[0254]
[0255]
[0256]
[0257]
[0258]
[0259]
[0260]
[0261]
[0262]
[0263]
[0264]
[0265]
[0266]
[0267]
[0268]
[0269]
[0270]
[0271]
[0272]
[0273]
[0274]
[0275]
[0276]
[0277]
[0278]
[0279]
[0280]
[0281]
[0282]
[0283]
[0284]
[0285]
[0286]
[0287]
[0288]
[0289]
[0290]
[0291]
[0292]
[0293]
[0294]
[0295]
[0296]
[0297]
[0298]
[0299]
[0300]
[0301]
[0302]
[0303]
[0304]
[0305]
[0306]
[0307]
[0308]
[0309]
[0310]
[0311]
[0312]
[0313]
[0314]
[0315]
[0316]
[0317]
[0318]
[0319]
[0320]
[0321]
[0322]
[0323]
[0324]
[0325]
[0326]
[0327]
[0328]
[0329]
[0330]
[0331]
[0332]
[0333]
[0334]
[0335]
[0336]
[0337]
[0338]
[0339]
[0340]
[0341]
[0342]
[0343]
[0344]
[0345]
[0346]
[0347]
[0348]
[0349]
[0350]
[0351]
[0352]
[0353]
[0354]
[0355]
[0356]
[0357]
[0358]
[0359]
[0360]
[0361]
[0362]
[0363]
[0364]
[0365]
[0366]
[0367]
[0368]
[0369]
[0370]
[0371]
[0372]
[0373]
[0374]
[0375]
[0376]
[0377]
[0378]
[0379]
[0380]
[0381]
[0382]
[0383]
[0384]
[0385]
[0386]
[0387]
[0388]
[0389]
[0390]
[0391]
[0392]
[0393]
[0394]
[0395]
[0396]
[0397]
[0398]
[0399]
[0400]
[0401]
[0402]
[0403]
[0404]
[0405]
[0406]
[0407]
[0408]
[0409]
[0410]
[0411]
[0412]
[0413]
[0414]
[0415]
[0416]
[0417]
[0418]
[0419]
[0420]
[0421]
[0422]
[0423]
[0424]
[0425]
[0426]
[0427]
[0428]
[0429]
[0430]
[0431]
[0432]
[0433]
[0434]
[0435]
[0436]
[0437]
[0438]
[0439]
[0440]
[0441]
[0442]
[0443]
[0444]
[0445]
[0446]
[0447]
[0448]
[0449]
[0450]
[0451]
[0452]
[0453]
[0454]
[0455]
[0456]
[0457]
[0458]
[0459]
[0460]
[0461]
[0462]
[0463]
[0464]
[0465]
[0466]
[0467]
[0468]
[0469]
[0470]
[0471]
[0472]
[0473]
[0474]
[0475]
[0476]
[0477]
[0478]
[0479]
[0480]
[0481]
[0482]
[0483]
[0484]
[0485]
[0486]
[0487]
[0488]
[0489]
[0490]
[0491]
[0492]
[0493]
[0494]
[0495]
[0496]
[0497]
[0498]
[0499]
[0500]
[0501]
[0502]
[0503]
[0504]
[0505]
[0506]
[0507]
[0508]
[0509]
[0510]
[0511]
[0512]
[0513]
[0514]
[0515]
[0516]
[0517]
[0518]
[0519]
[0520]
[0521]
[0522]
[0523]
[0524]
[0525]
[0526]
[0527]
[0528]
[0529]
[0530]
[0531]
[0532]
[0533]
[0534]
[0535]
[0536]
[0537]
[0538]
[0539]
[0540]
[0541]
[0542]
[0543]
[0544]
[0545]
[0546]
[0547]
[0548]
[0549]
[0550]
[0551]
[0552]
[0553]
[0554]
[0555]
[0556]
[0557]
[0558]
[0559]
[0560]
[0561]
[0562]
[0563]
[0564]
[0565]
[0566]
[0567]
[0568]
[0569]
[0570]
[0571]
[0572]
[0573]
[0574]
[0575]
[0576]
[0577]
[0578]
[0579]
[0580]
[0581]
[0582]
[0583]
[0584]
[0585]
[0586]
[0587]
[0588]
[0589]
[0590]
[0591]
[0592]
[0593]
[0594]
[0595]
[0596]
[0597]
[0598]
[0599]
[0600]
[0601]
[0602]
[0603]
[0604]
[0605]
[0606]
[0607]
[0608]
[0609]
[0610]
[0611]
[0612]
[0613]
[0614]
[0615]
[0616]
[0617]
[0618]
[0619]
[0620]
[0621]
[0622]
[0623]
[0624]
[0625]
[0626]
[0627]
[0628]
[0629]
[0630]
[0631]
[0632]
[0633]
[0634]
[0635]
[0636]
[0637]
[0638]
[0639]
[0640]
[0641]
[0642]
[0643]
[0644]
[0645]
[0646]
[0647]
[0648]
[0649]
[0650]
[0651]
[0652]
[0653]
[0654]
[0655]
[0656]
[0657]
[0658]
[0659]
[0660]
[0661]
[0662]
[0663]
[0664]
[0665]
[0666]
[0667]
[0668]
[0669]
[0670]
[0671]
[0672]
[0673]
[0674]
[0675]
[0676]
[0677]
[0678]
[0679]
[0680]
[0681]
[0682]
[0683]
[0684]
[0685]
[0686]
[0687]
[0688]
[0689]
[0690]
[0691]
[0692]
[0693]
[0694]
[0695]
[0696]
[0697]
[0698]
[0699]
[0700]
[0701]
[0702]
[0703]
[0704]
[0705]
[0706]
[0707]
[0708]
[0709]
[0710]
[0711]
[0712]
[0713]
[0714]
[0715]
[0716]
[0717]
[0718]
[0719]
[0720]
[0721]
[0722]
[0723]
[0724]
[0725]
[0726]
[0727]
[0728]
[0729]
[0730]
[0731]
[0732]
[0733]
[0734]
[0735]
[0736]
[0737]
[0738]
[0739]
[0740]
[0741]
[0742]
[0743]
[0744]
[0745]
[0746]
[0747]
[0748]
[0749]
[0750]
[0751]
[0752]
[0753]
[0754]
[0755]
[0756]
[0757]
[0758]
[0759]
[0760]
[0761]
[0762]
[0763]
[0764]
[0765]
[0766]
[0767]
[0768]
[0769]
[0770]
[0771]
[0772]
[0773]
[0774]
[0775]
[0776]
[0777]
[0778]
[0779]
[0780]
[0781]
[0782]
[0783]
[0784]
[0785]
[0786]
[0787]
[0788]
[0789]
[0790]
[0791]
[0792]
[0793]
[0794]
[0795]
[0796]
[0797]
[0798]
[0799]
[0800]
[0801]
[0802]
[0803]
[0804]
[0805]
[0806]
[0807]
[0808]
[0809]
[0810]
[0811]
[0812]
[0813]
[0814]
[0815]
[0816]
[0817]
[0818]
[0819]
[0820]
[0821]
[0822]
[0823]
[0824]
[0825]
[0826]
[0827]
[0828]
[0829]
[0830]
[0831]
[0832]
[0833]
[0834]
[0835]
[0836]
[0837]
[0838]
[0839]
[0840]
[0841]
[0842]
[0843]
[0844]
[0845]
[0846]
[0847]
[0848]
[0849]
[0850]
[0851]
[0852]
[0853]
[0854]
[0855]
[0856]
[0857]
[0858]
[0859]
[0860]
[0861]
[0862]
[0863]
[0864]
[0865]
[0866]
[0867]
[0868]
[0869]
[0870]
[0871]
[0872]
[0873]
[0874]
[0875]
[0876]
[0877]
[0878]
[0879]
[0880]
[0881]
[0882]
[0883]
[0884]
[0885]
[0886]
[0887]
[0888]
[0889]
[0890]
[0891]
[0892]
[0893]
[0894]
[0895]
[0896]
[0897]
[0898]
[0899]
[0900]
[0901]
[0902]
[0903]
[0904]
[0905]
[0906]
[0907]
[0908]
[0909]
[0910]
[0911]
[0912]
[0913]
[0914]
[0915]
[0916]
[0917]
[0918]
[0919]
[0920]
[0921]
[0922]
[0923]
[0924]
[0925]
[0926]
[0927]
[0928]
[0929]
[0930]
[0931]
[0932]
[0933]
[0934]
[0935]
[0936]
[0937]
[0938]
[0939]
[0940]
[0941]
[0942]
[0943]
[0944]
[0945]
[0946]
[0947]
[0948]
[0949]
[0950]
[0951]
[0952]
[0953]
[0954]
[0955]
[0956]
[0957]
[0958]
[0959]
[0960]
[0961]
[0962]
[0963]
[0964]
[0965]
[0966]
[0967]
[0968]
[0969]
[0970]
[0971]
[0972]
[0973]
[0974]
[0975]
[0976]
[0977]
[0978]
[0979]
[0980]
[0981]
[0982]
[0983]
[0984]
[0985]
[0986]
[0987]
[0988]
[0989]
[0990]
[0991]
[0992]
[0993]
[0994]
[0995]
[0996]
[0997]
[0998]
[0999]
[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]
[3904]
[3905]
[3906]
[3907]
[3908]
[3909]
[3910]
[3911]
[3912]
[3913]
[3914]
[3915]
[3916]
[3917]
[3918]
[3919]
[3920]
[3921]
[3922]
[3923]
[3924]
[3925]
[3926]
[3927]
[3928]
[3929]
[3930]
[3931]
[3932]
[3933]
[3934]
[3935]
[3936]
[3937]
[3938]
[3939]
[3940]
[3941]
[3942]
[3943]
[3944]
[3945]
[3946]
[3947]
[3948]
[3949]
[3950]
[3951]
[3952]
[3953]
[3954]
[3955]
[3956]
[3957]
[3958]
[3959]
[3960]
[3961]
[3962]
[3963]
[3964]
[3965]
[3966]
[3967]
[3968]
[3969]
[3970]
[3971]
[3972]
[3973]
[3974]
[3975]
[3976]
[3977]
[3978]
[3979]
[3980]
[3981]
[3982]
[3983]
[3984]
[3985]
[3986]
[3987]
[3988]
[3989]
[3990]
[3991]
[3992]
[3993]
[3994]
[3995]
[3996]
[3997]
[3998]
[3999]
[4000]
[4001]
[4002]
[4003]
[4004]
[4005]
[4006]
[4007]
[4008]
[4009]
[4010]
[4011]
[4012]
[4013]
[4014]
[4015]
[4016]
[4017]
[4018]
[4019]
[4020]
[4021]
[4022]
[4023]
[4024]
[4025]
[4026]
[4027]
[4028]
[4029]
[4030]
[4031]
[4032]
[4033]
[4034]
[4035]
[4036]
[4037]
[4038]
[4039]
[4040]
[4041]
[4042]
[4043]
[4044]
[4045]
[4046]
[4047]
[4048]
[4049]
[4050]
[4051]
[4052]
[4053]
[4054]
[4055]
[4056]
[4057]
[4058]
[4059]
[4060]
[4061]
[4062]
[4063]
[4064]
[4065]
[4066]
[4067]
[4068]
[4069]
[4070]
[4071]
[4072]
[4073]
[4074]
[4075]
[4076]
[4077]
[4078]
[4079]
[4080]
[4081]
[4082]
[4083]
[4084]
[4085]
[4086]
[4087]
[4088]
[4089]
[4090]
[4091]
[4092]
[4093]
[4094]
[4095]
[4096]
[4097]
[4098]
[4099]
[4100]
[4101]
[4102]
[4103]
[4104]
[4105]
[4106]
[4107]
[4108]
[4109]
[4110]
[4111]
[4112]
[4113]
[4114]
[4115]
[4116]
[4117]
[4118]
[4119]
[4120]
[4121]
[4122]
[4123]
[4124]
[4125]
[4126]
[4127]
[4128]
[4129]
[4130]
[4131]
[4132]
[4133]
[4134]
[4135]
[4136]
[4137]
[4138]
[4139]
[4140]
[4141]
[4142]
[4143]
[4144]
[4145]
[4146]
[4147]
[4148]
[4149]
[4150]
[4151]
[4152]
[4153]
[4154]
[4155]
[4156]
[4157]
[4158]
[4159]
[4160]
[4161]
[4162]
[4163]
[4164]
[4165]
[4166]
[4167]
[4168]
[4169]
[4170]
[4171]
[4172]
[4173]
[4174]
[4175]
[4176]
[4177]
[4178]
[4179]
[4180]
[4181]
[4182]
[4183]
[4184]
[4185]
[4186]
[4187]
[4188]
[4189]
[4190]
[4191]
[4192]
[4193]
[4194]
[4195]
[4196]
[4197]
[4198]
[4199]
[4200]
[4201]
[4202]
[4203]
[4204]
[4205]
[4206]
[4207]
[4208]
[4209]
[4210]
[4211]
[4212]
[4213]
[4214]
[4215]
[4216]
[4217]
[4218]
[4219]
[4220]
[4221]
[4222]
[4223]
[4224]
[4225]
[4226]
[4227]
[4228]
[4229]
[4230]
[4231]
[4232]
[4233]
[4234]
[4235]
[4236]
[4237]
[4238]
[4239]
[4240]
[4241]
[4242]
[4243]
[4244]
[4245]
[4246]
[4247]
[4248]
[4249]
[4250]
[4251]
[4252]
[4253]
[4254]
[4255]
[4256]
[4257]
[4258]
[4259]
[4260]
[4261]
[4262]
[4263]
[4264]
[4265]
[4266]
[4267]
[4268]
[4269]
[4270]
[4271]
[4272]
[4273]
[4274]
[4275]
[4276]
[4277]
[4278]
[4279]
[4280]
[4281]
[4282]
[4283]
[4284]
[4285]
[4286]
[4287]
[4288]
[4289]
[4290]
[4291]
[4292]
[4293]
[4294]
[4295]
[4296]
[4297]
[4298]
[4299]
[4300]
[4301]
[4302]
[4303]
[4304]
[4305]
[4306]
[4307]
[4308]
[4309]
[4310]
[4311]
[4312]
[4313]
[4314]
[4315]
[4316]
[4317]
[4318]
[4319]
[4320]
[4321]
[4322]
[4323]
[4324]
[4325]
[4326]
[4327]
[4328]
[4329]
[4330]
[4331]
[4332]
[4333]
[4334]
[4335]
[4336]
[4337]
[4338]
[4339]
[4340]
[4341]
[4342]
[4343]
[4344]
[4345]
[4346]
[4347]
[4348]
[4349]
[4350]
[4351]
[4352]
[4353]
[4354]
[4355]
[4356]
[4357]
[4358]
[4359]
[4360]
[4361]
[4362]
[4363]
[4364]
[4365]
[4366]
[4367]
[4368]
[4369]
[4370]
[4371]
[4372]
[4373]
[4374]
[4375]
[4376]
[4377]
[4378]
[4379]
[4380]
[4381]
[4382]
[4383]
[4384]
[4385]
[4386]
[4387]
[4388]
[4389]
[4390]
[4391]
[4392]
[4393]
[4394]
[4395]
[4396]
[4397]
[4398]
[4399]
[4400]
[4401]
[4402]
[4403]
[4404]
[4405]
[4406]
[4407]
[4408]
[4409]
[4410]
[4411]
[4412]
[4413]
[4414]
[4415]
[4416]
[4417]
[4418]
[4419]
[4420]
[4421]
[4422]
[4423]
[4424]
[4425]
[4426]
[4427]
[4428]
[4429]
[4430]
[4431]
[4432]
[4433]
[4434]
[4435]
[4436]
[4437]
[4438]
[4439]
[4440]
[4441]
[4442]
[4443]
[4444]
[4445]
[4446]
[4447]
[4448]
[4449]
[4450]
[4451]
[4452]
[4453]
[4454]
[4455]
[4456]
[4457]
[4458]
[4459]
[4460]
[4461]
[4462]
[4463]
[4464]
[4465]
[4466]
[4467]
[4468]
[4469]
[4470]
[4471]
[4472]
[4473]
[4474]
[4475]
[4476]
[4477]
[4478]
[4479]
[4480]
[4481]
[4482]
[4483]
[4484]
[4485]
[4486]
[4487]
[4488]
[4489]
[4490]
[4491]
[4492]
[4493]
[4494]
[4495]
[4496]
[4497]
[4498]
[4499]
[4500]
[4501]
[4502]
[4503]
[4504]
[4505]
[4506]
[4507]
[4508]
[4509]
[4510]
[4511]
[4512]
[4513]
[4514]
[4515]
[4516]
[4517]
[4518]
[4519]
[4520]
[4521]
[4522]
[4523]
[4524]
[4525]
[4526]
[4527]
[4528]
[4529]
[4530]
[4531]
[4532]
[4533]
[4534]
[4535]
[4536]
[4537]
[4538]
[4539]
[4540]
[4541]
[4542]
[4543]
[4544]
[4545]
[4546]
[4547]
[4548]
[4549]
[4550]
[4551]
[4552]
[4553]
[4554]
[4555]
[4556]
[4557]
[4558]
[4559]
[4560]
[4561]
[4562]
[4563]
[4564]
[4565]
[4566]
[4567]
[4568]
[4569]
[4570]
[4571]
[4572]
[4573]
[4574]
[4575]
[4576]
[4577]
[4578]
[4579]
[4580]
[4581]
[4582]
[4583]
[4584]
[4585]
[4586]
[4587]
[4588]
[4589]
[4590]
[4591]
[4592]
[4593]
[4594]
[4595]
[4596]
[4597]
[4598]
[4599]
[4600]
[4601]
[4602]
[4603]
[4604]
[4605]
[4606]
[4607]
[4608]
[4609]
[4610]
[4611]
[4612]
[4613]
[4614]
[4615]
[4616]
[4617]
[4618]
[4619]
[4620]
[4621]
[4622]
[4623]
[4624]
[4625]
[4626]
[4627]
[4628]
[4629]
[4630]
[4631]
[4632]
[4633]
[4634]
[4635]
[4636]
[4637]
[4638]
[4639]
[4640]
[4641]
[4642]
[4643]
[4644]
[4645]
[4646]
[4647]
[4648]
[4649]
[4650]
[4651]
[4652]
[4653]
[4654]
[4655]
[4656]
[4657]
[4658]
[4659]
[4660]
[4661]
[4662]
[4663]
[4664]
[4665]
[4666]
[4667]
[4668]
[4669]
[4670]
[4671]
[4672]
[4673]
[4674]
[4675]
[4676]
[4677]
[4678]
[4679]
[4680]
[4681]
[4682]
[4683]
[4684]
[4685]
[4686]
[4687]
[4688]
[4689]
[4690]
[4691]
[4692]
[4693]
[4694]
[4695]
[4696]
[4697]
[4698]
[4699]
[4700]
[4701]
[4702]
[4703]
[4704]
[4705]
[4706]
[4707]
[4708]
[4709]
[4710]
[4711]
[4712]
[4713]
[4714]
[4715]
[4716]
[4717]
[4718]
[4719]
[4720]
[4721]
[4722]
[4723]
[4724]
[4725]
[4726]
[4727]
[4728]
[4729]
[4730]
[4731]
[4732]
[4733]
[4734]
[4735]
[4736]
[4737]
[4738]
[4739]
[4740]
[4741]
[4742]
[4743]
[4744]
[4745]
[4746]
[4747]
[4748]
[4749]
[4750]
[4751]
[4752]
[4753]
[4754]
[4755]
[4756]
[4757]
[4758]
[4759]
[4760]
[4761]
[4762]
[4763]
[4764]
[4765]
[4766]
[4767]
[4768]
[4769]
[4770]
[4771]
[4772]
[4773]
[4774]
[4775]
[4776]
[4777]
[4778]
[4779]
[4780]
[4781]
[4782]
[4783]
[4784]
[4785]
[4786]
[4787]
[4788]
[4789]
[4790]
[4791]
[4792]
[4793]
[4794]
[4795]
[4796]
[4797]
[4798]
[4799]
[4800]
[4801]
[4802]
[4803]
[4804]
[4805]
[4806]
[4807]
[4808]
[4809]
[4810]
[4811]
[4812]
[4813]
[4814]
[4815]
[4816]
[4817]
[4818]
[4819]
[4820]
[4821]
[4822]
[4823]
[4824]
[4825]
[4826]
[4827]
[4828]
[4829]
[4830]
[4831]
[4832]
[4833]
[4834]
[4835]
[4836]
[4837]
[4838]
[4839]
[4840]
[4841]
[4842]
[4843]
[4844]
[4845]
[4846]
[4847]
[4848]
[4849]
[4850]
[4851]
[4852]
[4853]
[4854]
[4855]
[4856]
[4857]
[4858]
[4859]
[4860]
[4861]
[4862]
[4863]
[4864]
[4865]
[4866]
[4867]
[4868]
[4869]
[4870]
[4871]
[4872]
[4873]
[4874]
[4875]
[4876]
[4877]
[4878]
[4879]
[4880]
[4881]
[4882]
[4883]
[4884]
[4885]
[4886]
[4887]
[4888]
[4889]
[4890]
[4891]
[4892]
[4893]
[4894]
[4895]
[4896]
[4897]
[4898]
[4899]
[4900]
[4901]
[4902]
[4903]
[4904]
[4905]
[4906]
[4907]
[4908]
[4909]
[4910]
[4911]
[4912]
[4913]
[4914]
[4915]
[4916]
[4917]
[4918]
[4919]
[4920]
[4921]
[4922]
[4923]
[4924]
[4925]
[4926]
[4927]
[4928]
[4929]
[4930]
[4931]
[4932]
[4933]
[4934]
[4935]
[4936]
[4937]
[4938]
[4939]
[4940]
[4941]
[4942]
[4943]
[4944]
[4945]
[4946]
[4947]
[4948]
[4949]
[4950]
[4951]
[4952]
[4953]
[4954]
[4955]
[4956]
[4957]
[4958]
[4959]
[4960]
[4961]
[4962]
[4963]
[4964]
[4965]
[4966]
[4967]
[4968]
[4969]
[4970]
[4971]
[4972]
[4973]
[4974]
[4975]
[4976]
[4977]
[4978]
[4979]
[4980]
[4981]
[4982]
[4983]
[4984]
[4985]
[4986]
[4987]
[4988]
[4989]
[4990]
[4991]
[4992]
[4993]
[4994]
[4995]
[4996]
[4997]
[4998]
[4999]
[5000]
[5001]
[5002]
[5003]
[5004]
[5005]
[5006]
[5007]
[5008]
[5009]
[5010]
[5011]
[5012]
[5013]
[5014]
[5015]
[5016]
[5017]
[5018]
[5019]
[5020]
[5021]
[5022]
[5023]
[5024]
[5025]
[5026]
[5027]
[5028]
[5029]
[5030]
[5031]
[5032]
[5033]
[5034]
[5035]
[5036]
[5037]
[5038]
[5039]
[5040]
[5041]
[5042]
[5043]
[5044]
[5045]
[5046]
[5047]
[5048]
[5049]
[5050]
[5051]
[5052]
[5053]
[5054]
[5055]
[5056]
[5057]
[5058]
[5059]
[5060]
[5061]
[5062]
[5063]
[5064]
[5065]
[5066]
[5067]
[5068]
[5069]
[5070]
[5071]
[5072]
[5073]
[5074]
[5075]
[5076]
[5077]
[5078]
[5079]
[5080]
[5081]
[5082]
[5083]
[5084]
[5085]
[5086]
[5087]
[5088]
[5089]
[5090]
[5091]
[5092]
[5093]
[5094]
[5095]
[5096]
[5097]
[5098]
[5099]
[5100]
[5101]
[5102]
[5103]
[5104]
[5105]
[5106]
[5107]
[5108]
[5109]
[5110]
[5111]
[5112]
[5113]
[5114]
[5115]
[5116]
[5117]
[5118]
[5119]
[5120]
[5121]
[5122]
[5123]
[5124]
[5125]
[5126]
[5127]
[5128]
[5129]
[5130]
[5131]
[5132]
[5133]
[5134]
[5135]
[5136]
[5137]
[5138]
[5139]
[5140]
[5141]
[5142]
[5143]
[5144]
[5145]
[5146]
[5147]
[5148]
[5149]
[5150]
[5151]
[5152]
[5153]
[5154]
[5155]
[5156]
[5157]
[5158]
[5159]
[5160]
[5161]
[5162]
[5163]
[5164]
[5165]
[5166]
[5167]
[5168]
[5169]
[5170]
[5171]
[5172]
[5173]
[5174]
[5175]
[5176]
[5177]
[5178]
[5179]
[5180]
[5181]
[5182]
[5183]
[5184]
[5185]
[5186]
[5187]
[5188]
[5189]
[5190]
[5191]
[5192]
[5193]
[5194]
[5195]
[5196]
[5197]
[5198]
[5199]
[5200]
[5201]
[5202]
[5203]
[5204]
[5205]
[5206]
[5207]
[5208]
[5209]
[5210]
[5211]
[5212]
[5213]
[5214]
[5215]
[5216]
[5217]
[5218]
[5219]
[5220]
[5221]
[5222]
[5223]
[5224]
[5225]
[5226]
[5227]
[5228]
[5229]
[5230]
[5231]
[5232]
[5233]
[5234]
[5235]
[5236]
[5237]
[5238]
[5239]
[5240]
[5241]
[5242]
[5243]
[5244]
[5245]
[5246]
[5247]
[5248]
[5249]
[5250]
[5251]
[5252]
[5253]
[5254]
[5255]
[5256]
[5257]
[5258]
[5259]
[5260]
[5261]
[5262]
[5263]
[5264]
[5265]
[5266]
[5267]
[5268]
[5269]
[5270]
[5271]
[5272]
[5273]
[5274]
[5275]
[5276]
[5277]
[5278]
[5279]
[5280]
[5281]
[5282]
[5283]
[5284]
[5285]
[5286]
[5287]
[5288]
[5289]
[5290]
[5291]
[5292]
[5293]
[5294]
[5295]
[5296]
[5297]
[5298]
[5299]
[5300]
[5301]
[5302]
[5303]
[5304]
[5305]
[5306]
[5307]
[5308]
[5309]
[5310]
[5311]
[5312]
[5313]
[5314]
[5315]
[5316]
[5317]
[5318]
[5319]
[5320]
[5321]
[5322]
[5323]
[5324]
[5325]
[5326]
[5327]
[5328]
[5329]
[5330]
[5331]
[5332]
[5333]
[5334]
[5335]
[5336]
[5337]
[5338]
[5339]
[5340]
[5341]
[5342]
[5343]
[5344]
[5345]
[5346]
[5347]
[5348]
[5349]
[5350]
[5351]
[5352]
[5353]
[5354]
[5355]
[5356]
[5357]
[5358]
[5359]
[5360]
[5361]
[5362]
[5363]
[5364]
[5365]
[5366]
[5367]
[5368]
[5369]
[5370]
[5371]
[5372]
[5373]
[5374]
[5375]
[5376]
[5377]
[5378]
[5379]
[5380]
[5381]
[5382]
[5383]
[5384]
[5385]
[5386]
[5387]
[5388]
[5389]
[5390]
[5391]
[5392]
[5393]
[5394]
[5395]
[5396]
[5397]
[5398]
[5399]
[5400]
[5401]
[5402]
[5403]
[5404]
[5405]
[5406]
[5407]
[5408]
[5409]
[5410]
[5411]
[5412]
[5413]
[5414]
[5415]
[5416]
[5417]
[5418]
[5419]
[5420]
[5421]
[5422]
[5423]
[5424]
[5425]
[5426]
[5427]
[5428]
[5429]
[5430]
[5431]
[5432]
[5433]
[5434]
[5435]
[5436]
[5437]
[5438]
[5439]
[5440]
[5441]
[5442]
[5443]
[5444]
[5445]
[5446]
[5447]
[5448]
[5449]
[5450]
[5451]
[5452]
[5453]
[5454]
[5455]
[5456]
[5457]
[5458]
[5459]
[5460]
[5461]
[5462]
[5463]
[5464]
[5465]
[5466]
[5467]
[5468]
[5469]
[5470]
[5471]
[5472]
[5473]
[5474]
[5475]
[5476]
[5477]
[5478]
[5479]
[5480]
[5481]
[5482]
[5483]
[5484]
[5485]
[5486]
[5487]
[5488]
[5489]
[5490]
[5491]
[5492]
[5493]
[5494]
[5495]
[5496]
[5497]
[5498]
[5499]
[5500]
[5501]
[5502]
[5503]
[5504]
[5505]
[5506]
[5507]
[5508]
[5509]
[5510]
[5511]
[5512]
[5513]
[5514]
[5515]
[5516]
[5517]
[5518]
[5519]
[5520]
[5521]
[5522]
[5523]
[5524]
[5525]
[5526]
[5527]
[5528]
[5529]
[5530]
[5531]
[5532]
[5533]
[5534]
[5535]
[5536]
[5537]
[5538]
[5539]
[5540]
[5541]
[5542]
[5543]
[5544]
[5545]
[5546]
[5547]
[5548]
[5549]
[5550]
[5551]
[5552]
[5553]
[5554]
[5555]
[5556]
[5557]
[5558]
[5559]
[5560]
[5561]
[5562]
[5563]
[5564]
[5565]
[5566]
[5567]
[5568]
[5569]
[5570]
[5571]
[5572]
[5573]
[5574]
[5575]
[5576]
[5577]
[5578]
[5579]
[5580]
[5581]
[5582]
[5583]
[5584]
[5585]
[5586]
[5587]
[5588]
[5589]
[5590]
[5591]
[5592]
[5593]
[5594]
[5595]
[5596]
[5597]
[5598]
[5599]
[5600]
[5601]
[5602]
[5603]
[5604]
[5605]
[5606]
[5607]
[5608]
[5609]
[5610]
[5611]
[5612]
[5613]
[5614]
[5615]
[5616]
[5617]
[5618]
[5619]
[5620]
[5621]
[5622]
[5623]
[5624]
[5625]
[5626]
[5627]
[5628]
[5629]
[5630]
[5631]
[5632]
[5633]
[5634]
[5635]
[5636]
[5637]
[5638]
[5639]
[5640]
[5641]
[5642]
[5643]
[5644]
[5645]
[5646]
[5647]
[5648]
[5649]
[5650]
[5651]
[5652]
[5653]
[5654]
[5655]
[5656]
[5657]
[5658]
[5659]
[5660]
[5661]
[5662]
[5663]
[5664]
[5665]
[5666]
[5667]
[5668]
[5669]
[5670]
[5671]
[5672]
[5673]
[5674]
[5675]
[5676]
[5677]
[5678]
[5679]
[5680]
[5681]
[5682]
[5683]
[5684]
[5685]
[5686]
[5687]
[5688]
[5689]
[5690]
[5691]
[5692]
[5693]
[5694]
[5695]
[5696]
[5697]
[5698]
[5699]
[5700]
[5701]
[5702]
[5703]
[5704]
[5705]
[5706]
[5707]
[5708]
[5709]
[5710]
[5711]
[5712]
[5713]
[5714]
[5715]
[5716]
[5717]
[5718]
[5719]
[5720]
[5721]
[5722]
[5723]
[5724]
[5725]
[5726]
[5727]
[5728]
[5729]
[5730]
[5731]
[5732]
[5733]
[5734]
[5735]
[5736]
[5737]
[5738]
[5739]
[5740]
[5741]
[5742]
[5743]
[5744]
[5745]
[5746]
[5747]
[5748]
[5749]
[5750]
[5751]
[5752]
[5753]
[5754]
[5755]
[5756]
[5757]
[5758]
[5759]
[5760]
[5761]
[5762]
[5763]
[5764]
[5765]
[5766]
[5767]
[5768]
[5769]
[5770]
[5771]
[5772]
[5773]
[5774]
[5775]
[5776]
[5777]
[5778]
[5779]
[5780]
[5781]
[5782]
[5783]
[5784]
[5785]
[5786]
[5787]
[5788]
[5789]
[5790]
[5791]
[5792]
[5793]
[5794]
[5795]
[5796]
[5797]
[5798]
[5799]
[5800]
[5801]
[5802]
[5803]
[5804]
[5805]
[5806]
[5807]
[5808]
[5809]
[5810]
[5811]
[5812]
[5813]
[5814]
[5815]
[5816]
[5817]
[5818]
[5819]
[5820]
[5821]
[5822]
[5823]
[5824]
[5825]
[5826]
[5827]
[5828]
[5829]
[5830]
[5831]
[5832]
[5833]
[5834]
[5835]
[5836]
[5837]
[5838]
[5839]
[5840]
[5841]
[5842]
[5843]
[5844]
[5845]
[5846]
[5847]
[5848]
[5849]
[5850]
[5851]
[5852]
[5853]
[5854]
[5855]
[5856]
[5857]
[5858]
[5859]
[5860]
[5861]
[5862]
[5863]
[5864]
[5865]
[5866]
[5867]
[5868]
[5869]
[5870]
[5871]
[5872]
[5873]
[5874]
[5875]
[5876]
[5877]
[5878]
[5879]
[5880]
[5881]
[5882]
[5883]
[5884]
[5885]
[5886]
[5887]
[5888]
[5889]
[5890]
[5891]
[5892]
[5893]
[5894]
[5895]
[5896]
[5897]
[5898]
[5899]
[5900]
[5901]
[5902]
[5903]
[5904]
[5905]
[5906]
[5907]
[5908]
[5909]
[5910]
[5911]
[5912]
[5913]
[5914]
[5915]
[5916]
[5917]
[5918]
[5919]
[5920]
[5921]
[5922]
[5923]
[5924]
[5925]
[5926]
[5927]
[5928]
[5929]
[5930]
[5931]
[5932]
[5933]
[5934]
[5935]
[5936]
[5937]
[5938]
[5939]
[5940]
[5941]
[5942]
[5943]
[5944]
[5945]
[5946]
[5947]
[5948]
[5949]
[5950]
[5951]
[5952]
[5953]
[5954]
[5955]
[5956]
[5957]
[5958]
[5959]
[5960]
[5961]
[5962]
[5963]
[5964]
[5965]
[5966]
[5967]
[5968]
[5969]
[5970]
[5971]
[5972]
[5973]
[5974]
[5975]
[5976]
[5977]
[5978]
[5979]
[5980]
[5981]
[5982]
[5983]
[5984]
[5985]
[5986]
[5987]
[5988]
[5989]
[5990]
[5991]
[5992]
[5993]
[5994]
[5995]
[5996]
[5997]
[5998]
[5999]
[6000]
[6001]
[6002]
[6003]
[6004]
[6005]
[6006]
[6007]
[6008]
[6009]
[6010]
[6011]
[6012]
[6013]
[6014]
[6015]
[6016]
[6017]
[6018]
[6019]
[6020]
[6021]
[6022]
[6023]
[6024]
[6025]
[6026]
[6027]
[6028]
[6029]
[6030]
[6031]
[6032]
[6033]
[6034]
[6035]
[6036]
[6037]
[6038]
[6039]
[6040]
[6041]
[6042]
[6043]
[6044]
[6045]
[6046]
[6047]
[6048]
[6049]
[6050]
[6051]
[6052]
[6053]
[6054]
[6055]
[6056]
[6057]
[6058]
[6059]
[6060]
[6061]
[6062]
[6063]
[6064]
[6065]
[6066]
[6067]
[6068]
[6069]
[6070]
[6071]
[6072]
[6073]
[6074]
[6075]
[6076]
[6077]
[6078]
[6079]
[6080]
[6081]
[6082]
[6083]
[6084]
[6085]
[6086]
[6087]
[6088]
[6089]
[6090]
[6091]
[6092]
[6093]
[6094]
[6095]
[6096]
[6097]
[6098]
[6099]
[6100]
[6101]
[6102]
[6103]
[6104]
[6105]
[6106]
[6107]
[6108]
[6109]
[6110]
[6111]
[6112]
[6113]
[6114]
[6115]
[6116]
[6117]
[6118]
[6119]
[6120]
[6121]
[6122]
[6123]
[6124]
[6125]
[6126]
[6127]
[6128]
[6129]
[6130]
[6131]
[6132]
[6133]
[6134]
[6135]
[6136]
[6137]
[6138]
[6139]
[6140]
[6141]
[6142]
[6143]
[6144]
[6145]
[6146]
[6147]
[6148]
[6149]
[6150]
[6151]
[6152]
[6153]
[6154]
[6155]
[6156]
[6157]
[6158]
[6159]
[6160]
[6161]
[6162]
[6163]
[6164]
[6165]
[6166]
[6167]
[6168]
[6169]
[6170]
[6171]
[6172]
[6173]
[6174]
[6175]
[6176]
[6177]
[6178]
[6179]
[6180]
[6181]
[6182]
[6183]
[6184]
[6185]
[6186]
[6187]
[6188]
[6189]
[6190]
[6191]
[6192]
[6193]
[6194]
[6195]
[6196]
[6197]
[6198]
[6199]
[6200]
[6201]
[6202]
[6203]
[6204]
[6205]
[6206]
[6207]
[6208]
[6209]
[6210]
[6211]
[6212]
[6213]
[6214]
[6215]
[6216]
[6217]
[6218]
[6219]
[6220]
[6221]
[6222]
[6223]
[6224]
[6225]
[6226]
[6227]
[6228]
[6229]
[6230]
[6231]
[6232]
[6233]
[6234]
[6235]
[6236]
[6237]
[6238]
[6239]
[6240]
[6241]
[6242]
[6243]
[6244]
[6245]
[6246]
[6247]
[6248]
[6249]
[6250]
[6251]
[6252]
[6253]
[6254]
[6255]
[6256]
[6257]
[6258]
[6259]
[6260]
[6261]
[6262]
[6263]
[6264]
[6265]
[6266]
[6267]
[6268]
[6269]
[6270]
[6271]
[6272]
[6273]
[6274]
[6275]
[6276]
[6277]
[6278]
[6279]
[6280]
[6281]
[6282]
[6283]
[6284]
[6285]
[6286]
[6287]
[6288]
[6289]
[6290]
[6291]
[6292]
[6293]
[6294]
[6295]
[6296]
[6297]
[6298]
[6299]
[6300]
[6301]
[6302]
[6303]
[6304]
[6305]
[6306]
[6307]
[6308]
[6309]
[6310]
[6311]
[6312]
[6313]
[6314]
[6315]
[6316]
[6317]
[6318]
[6319]
[6320]
[6321]
[6322]
[6323]
[6324]
[6325]
[6326]
[6327]
[6328]
[6329]
[6330]
[6331]
[6332]
[6333]
[6334]
[6335]
[6336]
[6337]
[6338]
[6339]
[6340]
[6341]
[6342]
[6343]
[6344]
[6345]
[6346]
[6347]
[6348]
[6349]
[6350]
[6351]
[6352]
[6353]
[6354]
[6355]
[6356]
[6357]
[6358]
[6359]
[6360]
[6361]
[6362]
[6363]
[6364]
[6365]
[6366]
[6367]
[6368]
[6369]
[6370]
[6371]
[6372]
[6373]
[6374]
[6375]
[6376]
[6377]
[6378]
[6379]
[6380]
[6381]
[6382]
[6383]
[6384]
[6385]
[6386]
[6387]
[6388]
[6389]
[6390]
[6391]
[6392]
[6393]
[6394]
[6395]
[6396]
[6397]
[6398]
[6399]
[6400]
[6401]
[6402]
[6403]
[6404]
[6405]
[6406]
[6407]
[6408]
[6409]
[6410]
[6411]
[6412]
[6413]
[6414]
[6415]
[6416]
[6417]
[6418]
[6419]
[6420]
[6421]
[6422]
[6423]
[6424]
[6425]
[6426]
[6427]
[6428]
[6429]
[6430]
[6431]
[6432]
[6433]
[6434]
[6435]
[6436]
[6437]
[6438]
[6439]
[6440]
[6441]
[6442]
[6443]
[6444]
[6445]
[6446]
[6447]
[6448]
[6449]
[6450]
[6451]
[6452]
[6453]
[6454]
[6455]
[6456]
[6457]
[6458]
[6459]
[6460]
[6461]
[6462]
[6463]
[6464]
[6465]
[6466]
[6467]
[6468]
[6469]
[6470]
[6471]
[6472]
[6473]
[6474]
[6475]
[6476]
[6477]
[6478]
[6479]
[6480]
[6481]
[6482]
[6483]
[6484]
[6485]
[6486]
[6487]
[6488]
[6489]
[6490]
[6491]
[6492]
[6493]
[6494]
[6495]
[6496]
[6497]
[6498]
[6499]
[6500]
[6501]
[6502]
[6503]
[6504]
[6505]
[6506]
[6507]
[6508]
[6509]
[6510]
[6511]
[6512]
[6513]
[6514]
[6515]
[6516]
[6517]
[6518]
[6519]
[6520]
[6521]
[6522]
[6523]
[6524]
[6525]
[6526]
[6527]
[6528]
[6529]
[6530]
[6531]
[6532]
[6533]
[6534]
[6535]
[6536]
[6537]
[6538]
[6539]
[6540]
[6541]
[6542]
[6543]
[6544]
[6545]
[6546]
[6547]
[6548]
[6549]
[6550]
[6551]
[6552]
[6553]
[6554]
[6555]
[6556]
[6557]
[6558]
[6559]
[6560]
[6561]
[6562]
[6563]
[6564]
[6565]
[6566]
[6567]
[6568]
[6569]
[6570]
[6571]
[6572]
[6573]
[6574]
[6575]
[6576]
[6577]
[6578]
[6579]
[6580]
[6581]
[6582]
[6583]
[6584]
[6585]
[6586]
[6587]
[6588]
[6589]
[6590]
[6591]
[6592]
[6593]
[6594]
[6595]
[6596]
[6597]
[6598]
[6599]
[6600]
[6601]
[6602]
[6603]
[6604]
[6605]
[6606]
[6607]
[6608]
[6609]
[6610]
[6611]
[6612]
[6613]
[6614]
[6615]
[6616]
[6617]
[6618]
[6619]
[6620]
[6621]
[6622]
[6623]
[6624]
[6625]
[6626]
[6627]
[6628]
[6629]
[6630]
[6631]
[6632]
[6633]
[6634]
[6635]
[6636]
[6637]
[6638]
[6639]
[6640]
[6641]
[6642]
[6643]
[6644]
[6645]
[6646]
[6647]
[6648]
[6649]
[6650]
[6651]
[6652]
[6653]
[6654]
[6655]
[6656]
[6657]
[6658]
[6659]
[6660]
[6661]
[6662]
[6663]
[6664]
[6665]
[6666]
[6667]
[6668]
[6669]
[6670]
[6671]
[6672]
[6673]
[6674]
[6675]
[6676]
[6677]
[6678]
[6679]
[6680]
[6681]
[6682]
[6683]
[6684]
[6685]
[6686]
[6687]
[6688]
[6689]
[6690]
[6691]
[6692]
[6693]
[6694]
[6695]
[6696]
[6697]
[6698]
[6699]
[6700]
[6701]
[6702]
[6703]
[6704]
[6705]
[6706]
[6707]
[6708]
[6709]
[6710]
[6711]
[6712]
[6713]
[6714]
[6715]
[6716]
[6717]
[6718]
[6719]
[6720]
[6721]
[6722]
[6723]
[6724]
[6725]
[6726]
[6727]
[6728]
[6729]
[6730]
[6731]
[6732]
[6733]
[6734]
[6735]
[6736]
[6737]
[6738]
[6739]
[6740]
[6741]
[6742]
[6743]
[6744]
[6745]
[6746]
[6747]
[6748]
[6749]
[6750]
[6751]
[6752]
[6753]
[6754]
[6755]
[6756]
[6757]
[6758]
[6759]
[6760]
[6761]
[6762]
[6763]
[6764]
[6765]
[6766]
[6767]
[6768]
[6769]
[6770]
[6771]
[6772]
[6773]
[6774]
[6775]
[6776]
[6777]
[6778]
[6779]
[6780]
[6781]
[6782]
[6783]
[6784]
[6785]
[6786]
[6787]
[6788]
[6789]
[6790]
[6791]
[6792]
[6793]
[6794]
[6795]
[6796]
[6797]
[6798]
[6799]
[6800]
[6801]
[6802]
[6803]
[6804]
[6805]
[6806]
[6807]
[6808]
[6809]
[6810]
[6811]
[6812]
[6813]
[6814]
[6815]
[6816]
[6817]
[6818]
[6819]
[6820]
[6821]
[6822]
[6823]
[6824]
[6825]
[6826]
[6827]
[6828]
[6829]
[6830]
[6831]
[6832]
[6833]
[6834]
[6835]
[6836]
[6837]
[6838]
[6839]
[6840]
[6841]
[6842]
[6843]
[6844]
[6845]
[6846]
[6847]
[6848]
[6849]
[6850]
[6851]
[6852]
[6853]
[6854]
[6855]
[6856]
[6857]
[6858]
[6859]
[6860]
[6861]
[6862]
[6863]
[6864]
[6865]
[6866]
[6867]
[6868]
[6869]
[6870]
[6871]
[6872]
[6873]
[6874]
[6875]
[6876]
[6877]
[6878]
[6879]
[6880]
[6881]
[6882]
[6883]
[6884]
[6885]
[6886]
[6887]
[6888]
[6889]
[6890]
[6891]
[6892]
[6893]
[6894]
[6895]
[6896]
[6897]
[6898]
[6899]
[6900]
[6901]
[6902]
[6903]
[6904]
[6905]
[6906]
[6907]
[6908]
[6909]
[6910]
[6911]
[6912]
[6913]
[6914]
[6915]
[6916]
[6917]
[6918]
[6919]
[6920]
[6921]
[6922]
[6923]
[6924]
[6925]
[6926]
[6927]
[6928]
[6929]
[6930]
[6931]
[6932]
[6933]
[6934]
[6935]
[6936]
[6937]
[6938]
[6939]
[6940]
[6941]
[6942]
[6943]
[6944]
[6945]
[6946]
[6947]
[6948]
[6949]
[6950]
[6951]
[6952]
[6953]
[6954]
[6955]
[6956]
[6957]
[6958]
[6959]
[6960]
[6961]
[6962]
[6963]
[6964]
[6965]
[6966]
[6967]
[6968]
[6969]
[6970]
[6971]
[6972]
[6973]
[6974]
[6975]
[6976]
[6977]
[6978]
[6979]
[6980]
[6981]
[6982]
[6983]
[6984]
[6985]
[6986]
[6987]
[6988]
[6989]
[6990]
[6991]
[6992]
[6993]
[6994]
[6995]
[6996]
[6997]
[6998]
[6999]
[7000]
[7001]
[7002]
[7003]
[7004]
[7005]
[7006]
[7007]
[7008]
[7009]
[7010]
[7011]
[7012]
[7013]
[7014]
[7015]
[7016]
[7017]
[7018]
[7019]
[7020]
[7021]
[7022]
[7023]
[7024]
[7025]
[7026]
[7027]
[7028]
[7029]
[7030]
[7031]
[7032]
[7033]
[7034]
[7035]
[7036]
[7037]
[7038]
[7039]
[7040]
[7041]
[7042]
[7043]
[7044]
[7045]
[7046]
[7047]
[7048]
[7049]
[7050]
[7051]
[7052]
[7053]
[7054]
[7055]
[7056]
[7057]
[7058]
[7059]
[7060]
[7061]
[7062]
[7063]
[7064]
[7065]
[7066]
[7067]
[7068]
[7069]
[7070]
[7071]
[7072]
[7073]
[7074]
[7075]
[7076]
[7077]
[7078]
[7079]
[7080]
[7081]
[7082]
[7083]
[7084]
[7085]
[7086]
[7087]
[7088]
[7089]
[7090]
[7091]
[7092]
[7093]
[7094]
[7095]
[7096]
[7097]
[7098]
[7099]
[7100]
[7101]
[7102]
[7103]
[7104]
[7105]
[7106]
[7107]
[7108]
[7109]
[7110]
[7111]
[7112]
[7113]
[7114]
[7115]
[7116]
[7117]
[7118]
[7119]
[7120]
[7121]
[7122]
[7123]
[7124]
[7125]
[7126]
[7127]
[7128]
[7129]
[7130]
[7131]
[7132]
[7133]
[7134]
[7135]
[7136]
[7137]
[7138]
[7139]
[7140]
[7141]
[7142]
[7143]
[7144]
[7145]
[7146]
[7147]
[7148]
[7149]
[7150]
[7151]
[7152]
[7153]
[7154]
[7155]
[7156]
[7157]
[7158]
[7159]
[7160]
[7161]
[7162]
[7163]
[7164]
[7165]
[7166]
[7167]
[7168]
[7169]
[7170]
[7171]
[7172]
[7173]
[7174]
[7175]
[7176]
[7177]
[7178]
[7179]
[7180]
[7181]
[7182]
[7183]
[7184]
[7185]
[7186]
[7187]
[7188]
[7189]
[7190]
[7191]
[7192]
[7193]
[7194]
[7195]
[7196]
[7197]
[7198]
[7199]
[7200]
[7201]
[7202]
[7203]
[7204]
[7205]
[7206]
[7207]
[7208]
[7209]
[7210]
[7211]
[7212]
[7213]
[7214]
[7215]
[7216]
[7217]
[7218]
[7219]
[7220]
[7221]
[7222]
[7223]
[7224]
[7225]
[7226]
[7227]
[7228]
[7229]
[7230]
[7231]
[7232]
[7233]
[7234]
[7235]
[7236]
[7237]
[7238]
[7239]
[7240]
[7241]
[7242]
[7243]
[7244]
[7245]
[7246]
[7247]
[7248]
[7249]
[7250]
[7251]
[7252]
[7253]
[7254]
[7255]
[7256]
[7257]
[7258]
[7259]
[7260]
[7261]
[7262]
[7263]
[7264]
[7265]
[7266]
[7267]
[7268]
[7269]
[7270]
[7271]
[7272]
[7273]
[7274]
[7275]
[7276]
[7277]
[7278]
[7279]
[7280]
[7281]
[7282]
[7283]
[7284]
[7285]
[7286]
[7287]
[7288]
[7289]
[7290]
[7291]
[7292]
[7293]
[7294]
[7295]
[7296]
[7297]
[7298]
[7299]
[7300]
[7301]
[7302]
[7303]
[7304]
[7305]
[7306]
[7307]
[7308]
[7309]
[7310]
[7311]
[7312]
[7313]
[7314]
[7315]
[7316]
[7317]
[7318]
[7319]
[7320]
[7321]
[7322]
[7323]
[7324]
[7325]
[7326]
[7327]
[7328]
[7329]
[7330]
[7331]
[7332]
[7333]
[7334]
[7335]
[7336]
[7337]
[7338]
[7339]
[7340]
[7341]
[7342]
[7343]
[7344]
[7345]
[7346]
[7347]
[7348]
[7349]
[7350]
[7351]
[7352]
[7353]
[7354]
[7355]
[7356]
[7357]
[7358]
[7359]
[7360]
[7361]
[7362]
[7363]
[7364]
[7365]
[7366]
[7367]
[7368]
[7369]
[7370]
[7371]
[7372]
[7373]
[7374]
[7375]
[7376]
[7377]
[7378]
[7379]
[7380]
[7381]
[7382]
[7383]
[7384]
[7385]
[7386]
[7387]
[7388]
[7389]
[7390]
[7391]
[7392]
[7393]
[7394]
[7395]
[7396]
[7397]
[7398]
[7399]
[7400]
[7401]
[7402]
[7403]
[7404]
[7405]
[7406]
[7407]
[7408]
[7409]
[7410]
[7411]
[7412]
[7413]
[7414]
[7415]
[7416]
[7417]
[7418]
[7419]
[7420]
[7421]
[7422]
[7423]
[7424]
[7425]
[7426]
[7427]
[7428]
[7429]
[7430]
[7431]
[7432]
[7433]
[7434]
[7435]
[7436]
[7437]
[7438]
[7439]
[7440]
[7441]
[7442]
[7443]
[7444]
[7445]
[7446]
[7447]
[7448]
[7449]
[7450]
[7451]
[7452]
[7453]
[7454]
[7455]
[7456]
[7457]
[7458]
[7459]
[7460]
[7461]
[7462]
[7463]
[7464]
[7465]
[7466]
[7467]
[7468]
[7469]
[7470]
[7471]
[7472]
[7473]
[7474]
[7475]
[7476]
[7477]
[7478]
[7479]
[7480]
[7481]
[7482]
[7483]
[7484]
[7485]
[7486]
[7487]
[7488]
[7489]
[7490]
[7491]
[7492]
[7493]
[7494]
[7495]
[7496]
[7497]
[7498]
[7499]
[7500]
[7501]
[7502]
[7503]
[7504]
[7505]
[7506]
[7507]
[7508]
[7509]
[7510]
[7511]
[7512]
[7513]
[7514]
[7515]
[7516]
[7517]
[7518]
[7519]
[7520]
[7521]
[7522]
[7523]
[7524]
[7525]
[7526]
[7527]
[7528]
[7529]
[7530]
[7531]
[7532]
[7533]
[7534]
[7535]
[7536]
[7537]
[7538]
[7539]
[7540]
[7541]
[7542]
[7543]
[7544]
[7545]
[7546]
[7547]
[7548]
[7549]
[7550]
[7551]
[7552]
[7553]
[7554]
[7555]
[7556]
[7557]
[7558]
[7559]
[7560]
[7561]
[7562]
[7563]
[7564]
[7565]
[7566]
[7567]
[7568]
[7569]
[7570]
[7571]
[7572]
[7573]
[7574]
[7575]
[7576]
[7577]
[7578]
[7579]
[7580]
[7581]
[7582]
[7583]
[7584]
[7585]
[7586]
[7587]
[7588]
[7589]
[7590]
[7591]
[7592]
[7593]
[7594]
[7595]
[7596]
[7597]
[7598]
[7599]
[7600]
[7601]
[7602]
[7603]
[7604]
[7605]
[7606]
[7607]
[7608]
[7609]
[7610]
[7611]
[7612]
[7613]
[7614]
[7615]
[7616]
[7617]
[7618]
[7619]
[7620]
[7621]
[7622]
[7623]
[7624]
[7625]
[7626]
[7627]
[7628]
[7629]
[7630]
[7631]
[7632]
[7633]
[7634]
[7635]
[7636]
[7637]
[7638]
[7639]
[7640]
[7641]
[7642]
[7643]
[7644]
[7645]
[7646]
[7647]
[7648]
[7649]
[7650]
[7651]
[7652]
[7653]
[7654]
[7655]
[7656]
[7657]
[7658]
[7659]
[7660]
[7661]
[7662]
[7663]
[7664]
[7665]
[7666]
[7667]
[7668]
[7669]
[7670]
[7671]
[7672]
[7673]
[7674]
[7675]
[7676]
[7677]
[7678]
[7679]
[7680]
[7681]
[7682]
[7683]
[7684]
[7685]
[7686]
[7687]
[7688]
[7689]
[7690]
[7691]
[7692]
[7693]
[7694]
[7695]
[7696]
[7697]
[7698]
[7699]
[7700]
[7701]
[7702]
[7703]
[7704]
[7705]
[7706]
[7707]
[7708]
[7709]
[7710]
[7711]
[7712]
[7713]
[7714]
[7715]
[7716]
[7717]
[7718]
[7719]
[7720]
[7721]
[7722]
[7723]
[7724]
[7725]
[7726]
[7727]
[7728]
[7729]
[7730]
[7731]
[7732]
[7733]
[7734]
[7735]
[7736]
[7737]
[7738]
[7739]
[7740]
[7741]
[7742]
[7743]
[7744]
[7745]
[7746]
[7747]
[7748]
[7749]
[7750]
[7751]
[7752]
[7753]
[7754]
[7755]
[7756]
[7757]
[7758]
[7759]
[7760]
[7761]
[7762]
[7763]
[7764]
[7765]
[7766]
[7767]
[7768]
[7769]
[7770]
[7771]
[7772]
[7773]
[7774]
[7775]
[7776]
[7777]
[7778]
[7779]
[7780]
[7781]
[7782]
[7783]
[7784]
[7785]
[7786]
[7787]
[7788]
[7789]
[7790]
[7791]
[7792]
[7793]
[7794]
[7795]
[7796]
[7797]
[7798]
[7799]
[7800]
[7801]
[7802]
[7803]
[7804]
[7805]
[7806]
[7807]
[7808]
[7809]
[7810]
[7811]
[7812]
[7813]
[7814]
[7815]
[7816]
[7817]
[7818]
[7819]
[7820]
[7821]
[7822]
[7823]
[7824]
[7825]
[7826]
[7827]
[7828]
[7829]
[7830]
[7831]
[7832]
[7833]
[7834]
[7835]
[7836]
[7837]
[7838]
[7839]
[7840]
[7841]
[7842]
[7843]
[7844]
[7845]
[7846]
[7847]
[7848]
[7849]
[7850]
[7851]
[7852]
[7853]
[7854]
[7855]
[7856]
[7857]
[7858]
[7859]
[7860]
[7861]
[7862]
[7863]
[7864]
[7865]
[7866]
[7867]
[7868]
[7869]
[7870]
[7871]
[7872]
[7873]
[7874]
[7875]
[7876]
[7877]
[7878]
[7879]
[7880]
[7881]
[7882]
[7883]
[7884]
[7885]
[7886]
[7887]
[7888]
[7889]
[7890]
[7891]
[7892]
[7893]
[7894]
[7895]
[7896]
[7897]
[7898]
[7899]
[7900]
[7901]
[7902]
[7903]
[7904]
[7905]
[7906]
[7907]
[7908]
[7909]
[7910]
[7911]
[7912]
[7913]
[7914]
[7915]
[7916]
[7917]
[7918]
[7919]
[7920]
[7921]
[7922]
[7923]
[7924]
[7925]
[7926]
[7927]
[7928]
[7929]
[7930]
[7931]
[7932]
[7933]
[7934]
[7935]
[7936]
[7937]
[7938]
[7939]
[7940]
[7941]
[7942]
[7943]
[7944]
[7945]
[7946]
[7947]
[7948]
[7949]
[7950]
[7951]
[7952]
[7953]
[7954]
[7955]
[7956]
[7957]
[7958]
[7959]
[7960]
[7961]
[7962]
[7963]
[7964]
[7965]
[7966]
[7967]
[7968]
[7969]
[7970]
[7971]
[7972]
[7973]
[7974]
[7975]
[7976]
[7977]
[7978]
[7979]
[7980]
[7981]
[7982]
[7983]
[7984]
[7985]
[7986]
[7987]
[7988]
[7989]
[7990]
[7991]
[7992]
[7993]
[7994]
[7995]
[7996]
[7997]
[7998]
[7999]
[8000]
[8001]
[8002]
[8003]
[8004]
[8005]
[8006]
[8007]
[8008]
[8009]
[8010]
[8011]
[8012]
[8013]
[8014]
[8015]
[8016]
[8017]
[8018]
[8019]
[8020]
[8021]
[8022]
[8023]
[8024]
[8025]
[8026]
[8027]
[8028]
[8029]
[8030]
[8031]
[8032]
[8033]
[8034]
[8035]
[8036]
[8037]
[8038]
[8039]
[8040]
[8041]
[8042]
[8043]
[8044]
[8045]
[8046]
[8047]
[8048]
[8049]
[8050]
[8051]
[8052]
[8053]
[8054]
[8055]
[8056]
[8057]
[8058]
[8059]
[8060]
[8061]
[8062]
[8063]
[8064]
[8065]
[8066]
[8067]
[8068]
[8069]
[8070]
[8071]
[8072]
[8073]
[8074]
[8075]
[8076]
[8077]
[8078]
[8079]
[8080]
[8081]
[8082]
[8083]
[8084]
[8085]
[8086]
[8087]
[8088]
[8089]
[8090]
[8091]
[8092]
[8093]
[8094]
[8095]
[8096]
[8097]
[8098]
[8099]
[8100]
[8101]
[8102]
[8103]
[8104]
[8105]
[8106]
[8107]
[8108]
[8109]
[8110]
[8111]
[8112]
[8113]
[8114]
[8115]
[8116]
[8117]
[8118]
[8119]
[8120]
[8121]
[8122]
[8123]
[8124]
[8125]
[8126]
[8127]
[8128]
[8129]
[8130]
[8131]
[8132]
[8133]
[8134]
[8135]
[8136]
[8137]
[8138]
[8139]
[8140]
[8141]
[8142]
[8143]
[8144]
[8145]
[8146]
[8147]
[8148]
[8149]
[8150]
[8151]
[8152]
[8153]
[8154]
[8155]
[8156]
[8157]
[8158]
[8159]
[8160]
[8161]
[8162]
[8163]
[8164]
[8165]
[8166]
[8167]
[8168]
[8169]
[8170]
[8171]
[8172]
[8173]
[8174]
[8175]
[8176]
[8177]
[8178]
[8179]
[8180]
[8181]
[8182]
[8183]
[8184]
[8185]
[8186]
[8187]
[8188]
[8189]
[8190]
[8191]
[8192]
[8193]
[8194]
[8195]
[8196]
[8197]
[8198]
[8199]
[8200]
[8201]
[8202]
[8203]
[8204]
[8205]
[8206]
[8207]
[8208]
[8209]
[8210]
[8211]
[8212]
[8213]
[8214]
[8215]
[8216]
[8217]
[8218]
[8219]
[8220]
[8221]
[8222]
[8223]
[8224]
[8225]
[8226]
[8227]
[8228]
[8229]
[8230]
[8231]
[8232]
[8233]
[8234]
[8235]
[8236]
[8237]
[8238]
[8239]
[8240]
[8241]
[8242]
[8243]
[8244]
[8245]
[8246]
[8247]
[8248]
[8249]
[8250]
[8251]
[8252]
[8253]
[8254]
[8255]
[8256]
[8257]
[8258]
[8259]
[8260]
[8261]
[8262]
[8263]
[8264]
[8265]
[8266]
[8267]
[8268]
[8269]
[8270]
[8271]
[8272]
[8273]
[8274]
[8275]
[8276]
[8277]
[8278]
[8279]
[8280]
[8281]
[8282]
[8283]
[8284]
[8285]
[8286]
[8287]
[8288]
[8289]
[8290]
[8291]
[8292]
[8293]
[8294]
[8295]
[8296]
[8297]
[8298]
[8299]
[8300]
[8301]
[8302]
[8303]
[8304]
[8305]
[8306]
[8307]
[8308]
[8309]
[8310]
[8311]
[8312]
[8313]
[8314]
[8315]
[8316]
[8317]
[8318]
[8319]
[8320]
[8321]
[8322]
[8323]
[8324]
[8325]
[8326]
[8327]
[8328]
[8329]
[8330]
[8331]
[8332]
[8333]
[8334]
[8335]
[8336]
[8337]
[8338]
[8339]
[8340]
[8341]
[8342]
[8343]
[8344]
[8345]
[8346]
[8347]
[8348]
[8349]
[8350]
[8351]
[8352]
[8353]
[8354]
[8355]
[8356]
[8357]
[8358]
[8359]
[8360]
[8361]
[8362]
[8363]
[8364]
[8365]
[8366]
[8367]
[8368]
[8369]
[8370]
[8371]
[8372]
[8373]
[8374]
[8375]
[8376]
[8377]
[8378]
[8379]
[8380]
[8381]
[8382]
[8383]
[8384]
[8385]
[8386]
[8387]
[8388]
[8389]
[8390]
[8391]
[8392]
[8393]
[8394]
[8395]
[8396]
[8397]
[8398]
[8399]
[8400]
[8401]
[8402]
[8403]
[8404]
[8405]
[8406]
[8407]
[8408]
[8409]
[8410]
[8411]
[8412]
[8413]
[8414]
[8415]
[8416]
[8417]
[8418]
[8419]
[8420]
[8421]
[8422]
[8423]
[8424]
[8425]
[8426]
[8427]
[8428]
[8429]
[8430]
[8431]
[8432]
[8433]
[8434]
[8435]
[8436]
[8437]
[8438]
[8439]
[8440]
[8441]
[8442]
[8443]
[8444]
[8445]
[8446]
[8447]
[8448]
[8449]
[8450]
[8451]
[8452]
[8453]
[8454]
[8455]
[8456]
[8457]
[8458]
[8459]
[8460]
[8461]
[8462]
[8463]
[8464]
[8465]
[8466]
[8467]
[8468]
[8469]
[8470]
[8471]
[8472]
[8473]
[8474]
[8475]
[8476]
[8477]
[8478]
[8479]
[8480]
[8481]
[8482]
[8483]
[8484]
[8485]
[8486]
[8487]
[8488]
[8489]
[8490]
[8491]
[8492]
[8493]
[8494]
[8495]
[8496]
[8497]
[8498]
[8499]
[8500]
[8501]
[8502]
[8503]
[8504]
[8505]
[8506]
[8507]
[8508]
[8509]
[8510]
[8511]
[8512]
[8513]
[8514]
[8515]
[8516]
[8517]
[8518]
[8519]
[8520]
[8521]
[8522]
[8523]
[8524]
[8525]
[8526]
[8527]
[8528]
[8529]
[8530]
[8531]
[8532]
[8533]
[8534]
[8535]
[8536]
[8537]
[8538]
[8539]
[8540]
[8541]
[8542]
[8543]
[8544]
[8545]
[8546]
[8547]
[8548]
[8549]
[8550]
[8551]
[8552]
[8553]
[8554]
[8555]
[8556]
[8557]
[8558]
[8559]
[8560]
[8561]
[8562]
[8563]
[8564]
[8565]
[8566]
[8567]
[8568]
[8569]
[8570]
[8571]
[8572]
[8573]
[8574]
[8575]
[8576]
[8577]
[8578]
[8579]
[8580]
[8581]
[8582]
[8583]
[8584]
[8585]
[8586]
[8587]
[8588]
[8589]
[8590]
[8591]
[8592]
[8593]
[8594]
[8595]
[8596]
[8597]
[8598]
[8599]
[8600]
[8601]
[8602]
[8603]
[8604]
[8605]
[8606]
[8607]
[8608]
[8609]
[8610]
[8611]
[8612]
[8613]
[8614]
[8615]
[8616]
[8617]
[8618]
[8619]
[8620]
[8621]
[8622]
[8623]
[8624]
[8625]
[8626]
[8627]
[8628]
[8629]
[8630]
[8631]
[8632]
[8633]
[8634]
[8635]
[8636]
[8637]
[8638]
[8639]
[8640]
[8641]
[8642]
[8643]
[8644]
[8645]
[8646]
[8647]
[8648]
[8649]
[8650]
[8651]
[8652]
[8653]
[8654]
[8655]
[8656]
[8657]
[8658]
[8659]
[8660]
[8661]
[8662]
[8663]
[8664]
[8665]
[8666]
[8667]
[8668]
[8669]
[8670]
[8671]
[8672]
[8673]
[8674]
[8675]
[8676]
[8677]
[8678]
[8679]
[8680]
[8681]
[8682]
[8683]
[8684]
[8685]
[8686]
[8687]
[8688]
[8689]
[8690]
[8691]
[8692]
[8693]
[8694]
[8695]
[8696]
[8697]
[8698]
[8699]
[8700]
[8701]
[8702]
[8703]
[8704]
[8705]
[8706]
[8707]
[8708]
[8709]
[8710]
[8711]
[8712]
[8713]
[8714]
[8715]
[8716]
[8717]
[8718]
[8719]
[8720]
[8721]
[8722]
[8723]
[8724]
[8725]
[8726]
[8727]
[8728]
[8729]
[8730]
[8731]
[8732]
[8733]
[8734]
[8735]
[8736]
[8737]
[8738]
[8739]
[8740]
[8741]
[8742]
[8743]
[8744]
[8745]
[8746]
[8747]
[8748]
[8749]
[8750]
[8751]
[8752]
[8753]
[8754]
[8755]
[8756]
[8757]
[8758]
[8759]
[8760]
[8761]
[8762]
[8763]
[8764]
[8765]
[8766]
[8767]
[8768]
[8769]
[8770]
[8771]
[8772]
[8773]
[8774]
[8775]
[8776]
[8777]
[8778]
[8779]
[8780]
[8781]
[8782]
[8783]
[8784]
[8785]
[8786]
[8787]
[8788]
[8789]
[8790]
[8791]
[8792]
[8793]
[8794]
[8795]
[8796]
[8797]
[8798]
[8799]
[8800]
[8801]
[8802]
[8803]
[8804]
[8805]
[8806]
[8807]
[8808]
[8809]
[8810]
[8811]
[8812]
[8813]
[8814]
[8815]
[8816]
[8817]
[8818]
[8819]
[8820]
[8821]
[8822]
[8823]
[8824]
[8825]
[8826]
[8827]
[8828]
[8829]
[8830]
[8831]
[8832]
[8833]
[8834]
[8835]
[8836]
[8837]
[8838]
[8839]
[8840]
[8841]
[8842]
[8843]
[8844]
[8845]
[8846]
[8847]
[8848]
[8849]
[8850]
[8851]
[8852]
[8853]
[8854]
[8855]
[8856]
[8857]
[8858]
[8859]
[8860]
[8861]
[8862]
[8863]
[8864]
[8865]
[8866]
[8867]
[8868]
[8869]
[8870]
[8871]
[8872]
[8873]
[8874]
[8875]
[8876]
[8877]
[8878]
[8879]
[8880]
[8881]
[8882]
[8883]
[8884]
[8885]
[8886]
[8887]
[8888]
[8889]
[8890]
[8891]
[8892]
[8893]
[8894]
[8895]
[8896]
[8897]
[8898]
[8899]
[8900]
[8901]
[8902]
[8903]
[8904]
[8905]
[8906]
[8907]
[8908]
[8909]
[8910]
[8911]
[8912]
[8913]
[8914]
[8915]
[8916]
[8917]
[8918]
[8919]
[8920]
[8921]
[8922]
[8923]
[8924]
[8925]
[8926]
[8927]
[8928]
[8929]
[8930]
[8931]
[8932]
[8933]
[8934]
[8935]
[8936]
[8937]
[8938]
[8939]
[8940]
[8941]
[8942]
[8943]
[8944]
[8945]
[8946]
[8947]
[8948]
[8949]
[8950]
[8951]
[8952]
[8953]
[8954]
[8955]
[8956]
[8957]
[8958]
[8959]
[8960]
[8961]
[8962]
[8963]
[8964]
[8965]
[8966]
[8967]
[8968]
[8969]
[8970]
[8971]
[8972]
[8973]
[8974]
[8975]
[8976]
[8977]
[8978]
[8979]
[8980]
[8981]
[8982]
[8983]
[8984]
[8985]
[8986]
[8987]
[8988]
[8989]
[8990]
[8991]
[8992]
[8993]
[8994]
[8995]
[8996]
[8997]
[8998]
[8999]
[9000]
[9001]
[9002]
[9003]
[9004]
[9005]
[9006]
[9007]
[9008]
[9009]
[9010]
[9011]
[9012]
[9013]
[9014]
[9015]
[9016]
[9017]
[9018]
[9019]
[9020]
[9021]
[9022]
[9023]
[9024]
[9025]
[9026]
[9027]
[9028]
[9029]
[9030]
[9031]
[9032]
[9033]
[9034]
[9035]
[9036]
[9037]
[9038]
[9039]
[9040]
[9041]
[9042]
[9043]
[9044]
[9045]
[9046]
[9047]
[9048]
[9049]
[9050]
[9051]
[9052]
[9053]
[9054]
[9055]
[9056]
[9057]
[9058]
[9059]
[9060]
[9061]
[9062]
[9063]
[9064]
[9065]
[9066]
[9067]
[9068]
[9069]
[9070]
[9071]
[9072]
[9073]
[9074]
[9075]
[9076]
[9077]
[9078]
[9079]
[9080]
[9081]
[9082]
[9083]
[9084]
[9085]
[9086]
[9087]
[9088]
[9089]
[9090]
[9091]
[9092]
[9093]
[9094]
[9095]
[9096]
[9097]
[9098]
[9099]
[9100]
[9101]
[9102]
[9103]
[9104]
[9105]
[9106]
[9107]
[9108]
[9109]
[9110]
[9111]
[9112]
[9113]
[9114]
[9115]
[9116]
[9117]
[9118]
[9119]
[9120]
[9121]
[9122]
[9123]
[9124]
[9125]
[9126]
[9127]
[9128]
[9129]
[9130]
[9131]
[9132]
[9133]
[9134]
[9135]
[9136]
[9137]
[9138]
[9139]
[9140]
[9141]
[9142]
[9143]
[9144]
[9145]
[9146]
[9147]
[9148]
[9149]
[9150]
[9151]
[9152]
[9153]
[9154]
[9155]
[9156]
[9157]
[9158]
[9159]
[9160]
[9161]
[9162]
[9163]
[9164]
[9165]
[9166]
[9167]
[9168]
[9169]
[9170]
[9171]
[9172]
[9173]
[9174]
[9175]
[9176]
[9177]
[9178]
[9179]
[9180]
[9181]
[9182]
[9183]
[9184]
[9185]
[9186]
[9187]
[9188]
[9189]
[9190]
[9191]
[9192]
[9193]
[9194]
[9195]
[9196]
[9197]
[9198]
[9199]
[9200]
[9201]
[9202]
[9203]
[9204]
[9205]
[9206]
[9207]
[9208]
[9209]
[9210]
[9211]
[9212]
[9213]
[9214]
[9215]
[9216]
[9217]
[9218]
[9219]
[9220]
[9221]
[9222]
[9223]
[9224]
[9225]
[9226]
[9227]
[9228]
[9229]
[9230]
[9231]
[9232]
[9233]
[9234]
[9235]
[9236]
[9237]
[9238]
[9239]
[9240]
[9241]
[9242]
[9243]
[9244]
[9245]
[9246]
[9247]
[9248]
[9249]
[9250]
[9251]
[9252]
[9253]
[9254]
[9255]
[9256]
[9257]
[9258]
[9259]
[9260]
[9261]
[9262]
[9263]
[9264]
[9265]
[9266]
[9267]
[9268]
[9269]
[9270]
[9271]
[9272]
[9273]
[9274]
[9275]
[9276]
[9277]
[9278]
[9279]
[9280]
[9281]
[9282]
[9283]
[9284]
[9285]
[9286]
[9287]
[9288]
[9289]
[9290]
[9291]
[9292]
[9293]
[9294]
[9295]
[9296]
[9297]
[9298]
[9299]
[9300]
[9301]
[9302]
[9303]
[9304]
[9305]
[9306]
[9307]
[9308]
[9309]
[9310]
[9311]
[9312]
[9313]
[9314]
[9315]
[9316]
[9317]
[9318]
[9319]
[9320]
[9321]
[9322]
[9323]
[9324]
[9325]
[9326]
[9327]
[9328]
[9329]
[9330]
[9331]
[9332]
[9333]
[9334]
[9335]
[9336]
[9337]
[9338]
[9339]
[9340]
[9341]
[9342]
[9343]
[9344]
[9345]
[9346]
[9347]
[9348]
[9349]
[9350]
[9351]
[9352]
[9353]
[9354]
[9355]
[9356]
[9357]
[9358]
[9359]
[9360]
[9361]
[9362]
[9363]
[9364]
[9365]
[9366]
[9367]
[9368]
[9369]
[9370]
[9371]
[9372]
[9373]
[9374]
[9375]
[9376]
[9377]
[9378]
[9379]
[9380]
[9381]
[9382]
[9383]
[9384]
[9385]
[9386]
[9387]
[9388]
[9389]
[9390]
[9391]
[9392]
[9393]
[9394]
[9395]
[9396]
[9397]
[9398]
[9399]
[9400]
[9401]
[9402]
[9403]
[9404]
[9405]
[9406]
[9407]
[9408]
[9409]
[9410]
[9411]
[9412]
[9413]
[9414]
[9415]
[9416]
[9417]
[9418]
[9419]
[9420]
[9421]
[9422]
[9423]
[9424]
[9425]
[9426]
[9427]
[9428]
[9429]
[9430]
[9431]
[9432]
[9433]
[9434]
[9435]
[9436]
[9437]
[9438]
[9439]
[9440]
[9441]
[9442]
[9443]
[9444]
[9445]
[9446]
[9447]
[9448]
[9449]
[9450]
[9451]
[9452]
[9453]
[9454]
[9455]
[9456]
[9457]
[9458]
[9459]
[9460]
[9461]
[9462]
[9463]
[9464]
[9465]
[9466]
[9467]
[9468]
[9469]
[9470]
[9471]
[9472]
[9473]
[9474]
[9475]
[9476]
[9477]
[9478]
[9479]
[9480]
[9481]
[9482]
[9483]
[9484]
[9485]
[9486]
[9487]
[9488]
[9489]
[9490]
[9491]
[9492]
[9493]
[9494]
[9495]
[9496]
[9497]
[9498]
[9499]
[9500]
[9501]
[9502]
[9503]
[9504]
[9505]
[9506]
[9507]
[9508]
[9509]
[9510]
[9511]
[9512]
[9513]
[9514]
[9515]
[9516]
[9517]
[9518]
[9519]
[9520]
[9521]
[9522]
[9523]
[9524]
[9525]
[9526]
[9527]
[9528]
[9529]
[9530]
[9531]
[9532]
[9533]
[9534]
[9535]
[9536]
[9537]
[9538]
[9539]
[9540]
[9541]
[9542]
[9543]
[9544]
[9545]
[9546]
[9547]
[9548]
[9549]
[9550]
[9551]
[9552]
[9553]
[9554]
[9555]
[9556]
[9557]
[9558]
[9559]
[9560]
[9561]
[9562]
[9563]
[9564]
[9565]
[9566]
[9567]
[9568]
[9569]
[9570]
[9571]
[9572]
[9573]
[9574]
[9575]
[9576]
[9577]
[9578]
[9579]
[9580]
[9581]
[9582]
[9583]
[9584]
[9585]
[9586]
[9587]
[9588]
[9589]
[9590]
[9591]
[9592]
[9593]
[9594]
[9595]
[9596]
[9597]
[9598]
[9599]
[9600]
[9601]
[9602]
[9603]
[9604]
[9605]
[9606]
[9607]
[9608]
[9609]
[9610]
[9611]
[9612]
[9613]
[9614]
[9615]
[9616]
[9617]
[9618]
[9619]
[9620]
[9621]
[9622]
[9623]
[9624]
[9625]
[9626]
[9627]
[9628]
[9629]
[9630]
[9631]
[9632]
[9633]
[9634]
[9635]
[9636]
[9637]
[9638]
[9639]
[9640]
[9641]
[9642]
[9643]
[9644]
[9645]
[9646]
[9647]
[9648]
[9649]
[9650]
[9651]
[9652]
[9653]
[9654]
[9655]
[9656]
[9657]
[9658]
[9659]
[9660]
[9661]
[9662]
[9663]
[9664]
[9665]
[9666]
[9667]
[9668]
[9669]
[9670]
[9671]
[9672]
[9673]
[9674]
[9675]
[9676]
[9677]
[9678]
[9679]
[9680]
[9681]
[9682]
[9683]
[9684]
[9685]
[9686]
[9687]
[9688]
[9689]
[9690]
[9691]
[9692]
[9693]
[9694]
[9695]
[9696]
[9697]
[9698]
[9699]
[9700]
[9701]
[9702]
[9703]
[9704]
[9705]
[9706]
[9707]
[9708]
[9709]
[9710]
[9711]
[9712]
[9713]
[9714]
[9715]
[9716]
[9717]
[9718]
[9719]
[9720]
[9721]
[9722]
[9723]
[9724]
[9725]
[9726]
[9727]
[9728]
[9729]
[9730]
[9731]
[9732]
[9733]
[9734]
[9735]
[9736]
[9737]
[9738]
[9739]
[9740]
[9741]
[9742]
[9743]
[9744]
[9745]
[9746]
[9747]
[9748]
[9749]
[9750]
[9751]
[9752]
[9753]
[9754]
[9755]
[9756]
[9757]
[9758]
[9759]
[9760]
[9761]
[9762]
[9763]
[9764]
[9765]
[9766]
[9767]
[9768]
[9769]
[9770]
[9771]
[9772]
[9773]
[9774]
[9775]
[9776]
[9777]
[9778]
[9779]
[9780]
[9781]
[9782]
[9783]
[9784]
[9785]
[9786]
[9787]
[9788]
[9789]
[9790]
[9791]
[9792]
[9793]
[9794]
[9795]
[9796]
[9797]
[9798]
[9799]
[9800]
[9801]
[9802]
[9803]
[9804]
[9805]
[9806]
[9807]
[9808]
[9809]
[9810]
[9811]
[9812]
[9813]
[9814]
[9815]
[9816]
[9817]
[9818]
[9819]
[9820]
[9821]
[9822]
[9823]
[9824]
[9825]
[9826]
[9827]
[9828]
[9829]
[9830]
[9831]
[9832]
[9833]
[9834]
[9835]
[9836]
[9837]
[9838]
[9839]
[9840]
[9841]
[9842]
[9843]
[9844]
[9845]
[9846]
[9847]
/*****************************************************************************/
#ifdef COMMENTS_WITH_COMMENTS
/*
                                  DCL.c

*************
** CAUTION **
*************

THIS MODULE IS TASK-ORIENTED, NOT REQUEST-ORIENTED.

That is, most of the functions take a pointer to DCL task rather than a pointer
to request as do other modules. The reason is simple. In this module the
more-permanent data-structures are those associated with the DCL script
processes, which persist for multiple requests. With the requests transient the
DCL script processes must be managed in their absence. Hence requests are
associated with DCL script processes not vice-versa.


OVERVIEW
--------
Provides multi-threaded, concurrent HTTPd script processes executing DCL.

This module never returns a valid status and ALWAYS calls the supplied next
task (AST) function.  This should check for a generated error message to
determine is there were any problems.

The DCL can either be in the form of a command, or a procedure or executable
image file specification. Both should not be supplied, but file specifications
have precedence. If a file specfication is supplied the module verifies its
existance, and if not qualified with an extension, looks for a procedure first
(".COM"), then an executable image (".EXE"), then through any user-defined
list of file types (extensions) and associated scripting executables (e.g.
".PL" associated with the verb "PERL"). Furthermore, the DCL can be executed
either standalone or as a CGI script (indicated by the presence of a script
name in the request data structure). If a CGI script, then the output stream
is parsed for header information, if not a script then the stream is just
checked for correct carriage control (terminated by a newline). CGI variables
are created for both standalone DCL and scripts, although some (e.g.
WWW_SCRIPT_NAME) will be empty, and meaningless, for standalone DCL. 

The AST-driven nature makes the code a little more difficult to follow, but 
creates a powerful, event-driven, multi-threaded server.  All of the 
necessary functions implementing this module are designed to be non-blocking. 

All of these functions are designed to be, and should be, called at AST 
delivery level, which means they cannot be interrupted at the same level (in 
this case USER mode), and so their actions are essentially atomic at that 
level, meaning no additional synchronization is required for such activities 
as thread disposal, etc.

The HTTPd can maintain a number of script processes limited only by its process 
quotas, memory is dynamically allocated and there are no fixed data structures 
related to script process management. 

The use of byte-streams (effectively "pipes") allows even DCL procedures to
output as HTTP servers, without the need for explicit network I/O. 

Four mailboxes are created for each script process' IPC:

  1.  A mailbox connected to its SYS$COMMAND.  This is used to pass DCL
      commands and/or other data to the script process.  It effectively allows
      the HTTPd to control the activities of the script process this way.

  2.  A mailbox connected to its SYS$OUTPUT.  This receives records from
      the script process, if required appends HTTP-required carriage-control
      (single <LF>), then sends the record to the client via the network.
      This allows even DCL procedures to supply a correct output stream to
      the client (see next paragraph).

      If the first line from a script is an HTTP status line (e.g.
      "HTTP/1.0 200 ok") then HTTPD assumes the script will be supplying
      a complete HTTP data stream, including full header and required
      carriage control (single <LF> terminating each line).  If the first
      line is not a HTTP status line it assumes CGI script output compliance
      and also ensures each record (line) received has correct HTTP
      carriage-control.

      This stream also attempts to maintain compliance with CGI scripting.
      If the first line output by a script is not an HTTP status line it
      creates and sends one to the client before sending the first line.

  3.  A mailbox defined for the script process by the name HTTP$INPUT.
      This may be used to read the request data steam sent by the client.
      Note that from v4.2 this is also the SYS$INPUT <stdin> stream as well,
      which appears to be the more common CGI implementation. As of version
      4.3 the default behaviour is to supply only the request body to the
      script (CGI standard and the more common implementation).  Defining the 
      environment variable HTTPD_DCL_FULL_REQUEST it is possible to revert
      to the previous behaviour of supplying the header then the body.
      (It's an easy enough modification for most scripts to skip the header by
      reading until the header-separating empty (blank) line is encountered.)

  4.  A mailbox defined by the name CGIPLUSIN.  This allows CGIplus scripts
      to read a stream of CGI variable information.  Each request begins with
      a comment line "!", which can be used for request start synchronisation
      and may always be discarded, and ends with an empty record (blank line),
      with a variable number of records in between.

The script script processes can use the basic CGI variables (VMS CERN-like) and 
behave very much like a CGI script.

That is, if a script wants to be CGI-compliant it provides as the first line a 
"Status:", "Content-type:" or a "Location:" then a blank line.   If the first 
line output by a script is a "Content-Type:" header line an HTTP "200" status 
line is prepended.  If the first line output by a script is a "Location:" 
redirection header line the redirection is processed to ensure CERN HTTPD/CGI 
behaviour.  An HTTP "302" status line is prepended if not a local redirection. 
If none of these, HTTPD creates a complete HTTP header comprising status line, 
"Content-Type: text/plain" and blank line (this is an extension of CERN HTTPD 
behaviour). 

If the first characters are "HTTP/1.0 ..." the script will be considered to be 
supplying the raw HTTP stream and record boundaries, carriage-control, etc., 
are of no further concern to the module.  This is the equivalent of a
"no-parse-header" script.  If CGI-compliant each record should represent a 
line of output.   That is lines should not be buffered together and sent as a 
block unless the script is supplying a raw HTTP data stream. 


CGI VARIABLES
-------------
See CGI.C module.


BUILD-RECORD OUTPUT MODE
------------------------ 
Generally the script's response header output would be issued as records.  A
record is defined as a 'line' of script output that is delimited by a newline
character ('\n', 0x0a), or a carriage-return then newline character ('\r\n',
0x0d 0x0a).  The CGI header processing code of CGI.C can also cope with
non-record header responses because the logical line is delimited by the
newline.  The script body can be issued in any way consistent with the response
MIME content-type and required record carriage control (which the server will
supply if required).

Generally compiled scripts output in record-mode unless explicitly programmed
to output in binary mode.  Some pre-built scripting environments are somewhat
poorly designed or ported to VMS and will provide all the output as single
character 'records'.  Horribly inefficient!!  This server still allows for such
environments by noting the first record.  If a single byte it switches to
'build-record' mode.   In 'build-record' mode each "real" record is assumed to
be any zero or more bytes delimited by a newline character.  A zero-byte record
is transmogrified into a single-byte, newline character record.  In this mode
the single byte I/Os are buffered until the newline is received (and appended
to the buffer) whereupon that built-up record is then processed as if received
as a single record.  (For more detail query Alex Ivanov about the vicissitudes
of GhostScript PostScript RTE programming. :^)


CGI-PLUS
--------
CGI plus lower latency, plus greater efficiency, plus less system impact!

CGIplus attempts to eliminate the overhead associated with creating the script
process and then executing the image of a CGI script.  It does this by allowing
the script process and associated image to continue executing in-between uses,
eliminating the startup overhead.  This both reduces the load on the system and
the request latency where one of these scripts is involved. In this sense these
advantages parallel those offered by commercial HTTP server-integration APIs,
such as Netscape NSAPI and Microsoft ISAPI.  The script interface is still
largely CGI, which means a new API does not need to be learned and that
existing CGI scripts are simple to modify.

The script must read the CGI variables from CGIPLUSIN.

They are supplied either as:

1)  A series of plain-text, records (lines).  The first contains a single "!",
used as a start sentinal.  A series of records then follows, containing the CGI
variable name, an equate symbol and then the variable value.  This format may
be easily parsed and as the value contains no encoded characters may be
directly used.  An empty record (blank line) indicates the end of the request
information.  (This is the default mode, though can be reverted to by a
"CGIPLUS: record" callout - see below.)

2)  Two records.  The first contains a leading sequence of "!!" followed by a
series of ASCII characters forming a number representing in plain-test the size
of the following binary record (e.g. "!!1563").  This binary record has the
structure described in the CGI.C module topic "CGIplus Variable Structure", and
must be parsed by the receiving application.  (This is by far the more
efficient mode and can be selected using a "CGIPLUS: struct" callout - see
below.)  Although the author had already developed a concept similar in
approach it was the independent suggestion and some initial performance
bench-marking by Jean-François Piéronne (jf.pieronne@laposte.net) that prompted
it's inclusion in the 7.2 release.

The request may be processed at that stage.

After processing the CGIplus script can loop, waiting to read the details of
the next request from CGIPLUSIN.  The first record read may ALWAYS be discarded
allowing a read to be used as a simple synchronization mechanism.

HTTP output (to the client) is written to SYS$OUTPUT (stdout). End of output
MUST be indicated by writing a special EOF string to the output stream. This is
a KLUDGE, and the least elegant part of CGIplus design, BUT it is also the
simplest implementation and should work in all but the most exceptional
circumstances. The special EOF string has been chosen to be most unlikely to
occur in normal output (a hopefully unique 224 bit sequence), but there is
still a very, very small chance! The CGIplus EOF string is obtained from the
logical name CGIPLUSEOF, defined in the script process's process table, using
the language's equivalent of F$TRNLNM(), SYS$TRNLNM(), or a getenv() call in
the C Language. This string will always contain less than 32 characters and
comprise only common, printable characters. It must be written at the
conclusion of a request's output to the output stream as a single record (line)
but may also contain a <CR><LF> or just <LF> trailing carriage-control (to
allow for programming language constraints). See examples in
HT_ROOT:[SRC.CGIPLUS]

HTTP input (raw request stream, header and any body) is still available to the
CGIplus script.

Multiple CGIplus scripts may be executing in script processes at any one time.
This includes multiple instances of any particular script.  It is the server's
task to track these, distributing appropriate requests to idle script processes,
monitoring those currently processing requests, creating new instances if and
when necessary, and deleting the least-used, idle CGIplus script processes when
configurable thresholds are reached.

A CGIplus script can be terminated by the server at any time (the script
process $FORCEX()ed then $DELPRC()ed) so resources should be largely quiescent
when not actually processing. CGIplus script processes may also be terminated
from the command line using STOP/id=. The server administration menu provides a
simple mechansim to purge (stop) all CGIplus processes, allowing the server to
be flushed of all script processes. This can be useful if some new compilation
of a CGIplus script executable needs to made available.

CGIplus scripts are differentiated from "normal" CGI scripts in the mapping
rule configuration file using the "script+" and "exec+" directives.  Of course
it would be possible to design a script to simply modify it's behaviour so it
was possible to execute in both environments.  Simply detecting the presence
or absence of one of the "normal" CGI variables (i.e. DCL symbols,
e.g. WWW_PATH_INFO, WWW_CGI_GATEWAY_INTERFACE, etc.) would be sufficient
indication.

See examples in HT_ROOT:[SRC.CGIPLUS]

April 1998 Note:  It has been observed that under rare circumstances a
persistent script process script-serviced request can die unexpectedly.  This
has been isolated to the following scenario.  A request underway results in a
CGIplus script terminating and the script process exiting.  Any output in the
script's C RTL buffers is flushed during exit, including possibly the CGI
output EOF indicator, generating an I/O AST which is serviced indicating the
request is complete and the CGIplus script is ready for reuse.  In fact it
isn't because the process is running-down.  Before the script process
termination AST can be processed another AST containing a request for that same
CGIplus script is serviced.  The DCL task structure is allocated to the new
request but shortly, possibly immediately after, that DCL task receives the
termination AST and is run-down.  The request receives no output and Netscape
Navigator for instance reports "Document contains no data".  This has been
addressed by checking whether the script has begun processing (by reading from
the COMMAND or CGIPLUSIN variable stream.  If this stream has not been read
from it is considered the above has happened and the script request is
resubmitted to DclBegin().  A limit is placed on the number of times this may
happen in succession, to prevent an errant script from producing a runaway
condition in the server.

October 2005 Note:  Further to the April 1998 note above it has been shown that
a timing window exists for an exiting script to cause a similar problem.  It's
unknown whether this existed from the original fix or has crept back in during
subsequent development.  This issue was closed by placing a test in
DclSysCommandAst() to ensure that the script is only marked as having responded
after allowing for a CGIplus script's SYS$COMMAND queued STOP/id=0 and EOF. 


CGIPLUS RUNTIME
---------------
This is a variation on the CGIplus environment.  It allows for mapping a
request path into *three* components (well sort of).  MAPURL.C allows an EXEC
to do some special mapping, essentially the derivation of a special run-time
file (script), then completely remapping the whole thing again to derive a
script file name (provided as a "parameter" to the executing run-time file) and
a resultant path.  The idea is the run-time environment is some sort of
persistent engine/interpreter operating in a CGIplus environment and getting
its requests via the CGIplus stream.  The actual script to be processed by it
is passed as CGI variables SCRIPT_NAME and SCRIPT_FILENAME which the engine
can then use as source for it's interpreter.  The rest of the environment is
normal CGI/CGIplus.  When finished the engine then runs-down the processing
environment, signals CGIplus-EOF and goes quiescent waiting for the next
request.

These run-time environments are so much like CGIplus scripts (with only a
slightly different handling of the script file name itself) that CGIplus
scripts can behave as run-time environments.  For example the CONAN script.  It
essentially "interprets" the "scripting" input of a VMS Help or text library. 
See the examples in the section immediately below.


WEB SOCKETS
-----------
For WASD a Web Socket script is one that is activated in the same fashion as an
equivalent CGI/CGIplus/RTE and has an identical CGI environment (variables,
streams, etc.) but which uses a unique HTTP response and communicates with its
client using the Web Socket protocol.  See further description in WEBSOCKET.C
prologue.

WASD can also tunnel Web Socket connections to Web Socket and non- Web Socket
services (see PROXYTUNNEL.C).


SCRIPT RUNTIME ENVIRONMENTS
---------------------------
File types (extensions) and associated scripting languages can be defined in
the configuration file.  The syntax is "type foreign-verb".  For example:

  [DclRunTime]
  .PL  $PERL_EXE:PERL.EXE
  .CGI PERL

Three are predefined, ".COM" for DCL procedures, ".CLD" to define a verb via
command-definition file, and ".EXE" for executables.  There are two further
run-time types, CGIplus and (persitant) Run-Time Environment (RTE) indicated by
enclosing them in parentheses.  For example:

  [DclRunTime]
  .PL  (HT_EXE:PERLRTE.EXE)
  .HLB (CGI-BIN:[000000]CONAN)

When these are encountered against a file type the script processing is
restarted from the current CGI type, to either CGIplus or RTE respectively. 
This incurs a small request processing penalty but the potential efficiencies
of the latter two environments make it well worthwhile.

NOTE: it is assumed the RTE executable/procedure exists.  No check is made by
the server for its existance or access permissions before activating under DCL.


SCRIPT COMMAND PARAMETERS
-------------------------
The mapping rule

  SET * script=command="<string>"

can be used to provide optional command-line qualifiers and parameters during
CGI and CGIplus script activation.  To add such to a script activation the
first character in the string should be an asterisk.  This indicates the verb
created by the DCL modules should be used to activate the script and anything
followed should just be appended to the verb's command-line.  The following
mapping

  SET /cgi-bin/script.exe script=command="* /QUALIFIER1 PARAMETER1"

would result in the script being activated using the following DCL commands

  WASDVERB:=$CGI-BIN:[000000]SCRIPT.EXE
  WASDVERB /QUALIFIER1 PARAMETER1

If the first character is not an asterisk the path SETing completely replaces
the server-generated script activation command allowing a completely different
command to be used to activate the script.  This mapping

  SET /cgi-bin/script.exe script=command="OKEYDOKEY /QUALIFIER1 PARAMETER1"

would result in the following DCL commands being generated

  WASDVERB:=$CGI-BIN:[000000]SCRIPT.EXE
  OKEYDOKEY /QUALIFIER1 PARAMETER1

As can be seen the first command is effectively ignored.


CGI CALLOUT
-----------
The CGIplus input/output streams are used to provide support for the script
process to "escape" from the normal SYS$OUTPUT stream and send records directly
to a server function for interpretation and processing.  In turn this function
can return records to the script via the CGIPLUSIN stream.  This works for
*BOTH* CGIplus *AND* vanilla CGI scripting!

The script indicates it wishes to suspend normal output by providing a record
containing the string found in the script process' CGIPLUSESC logical.  End of
this mode of communication is indicated by a record containing the string from
the CGIPLUSEOT logical (after which output to the client is resumed).  These
sequences are generated and used in much the same way as CGIPLUSEOF.

This functionality is used to supports CGIplus scripts that act not in the
traditional role as a CGI script but as "agents" to perform some required
function transparently to request processing.  An obvious example is an
external authentication/authorization processor.  These agents execute in the
normal CGI environment, with the request's CGI variables available (with some
minor differences depending on authorization state), <stdout> output stream,
etc.  There are some behavioural constraints on agents but this general
approach confers the considerable benefits of being able to write and operate
these agents as if CGI/CGIplus scripts, even as (CG)ISAPI DLLs.

A default callout for a CGIplus script is provided.  This function provides a
number of operations that may be useful to special-purpose scripts.  The
responses provided by the server are always an HTTP-like code, 200 for success,
400 for script request error, etc., with trailing plain-text explanation. 
The provision of and requirement for reading a response may be suppressed by
leading the directive with a '!' or '#'.

CGI "callout" requests (case-insensitive):

  100 AUTHAGENT-CALLOUT       avoid auth agents being run as scripts
  AGENT-BEGIN:string          provide v12... agent request
  AGENT-END:string            receive v12... agent response
  AUTH-FILE:string            authorize/deny SYSPRV access to file specified
  BODY:                       obsolete
  BUFFER-BEGIN:integer[k|M]   create temporary global section for output
  BUFFER-END:                 release the global section
  BUFFER-WRITE:integer        write <integer> bytes from the buffer
  CGI:[!]cgi_[<var>[=<value]] set/reset config CGI dictionary entry
                              (really only meaningful for meta-agents)
  CGIPLUS:string              provide CGI variables, "struct" or "record"
  CLIENT-READ:[string]        initiate reads directly from client to script
  CONTENT-TYPE:string         map the file extension to a MIME content-type
  CSP:string                  ("content-security-policy:") into response
  CSPRO:string                ("..policy-report-only:") into response
  DICT:[!][<key>[=<value]]    set/reset config dictionary entry
  GATEWAY-BEGIN:integer       HTTP response status code (e.g. 200) BG: device
  GATEWAY-CCL:integer         1 enables, 0 disables BG: device carriage-control
  GATEWAY-END:integer         count of bytes output directly to the BG: device
  ICON-TYPE:string            map the content-type/file extension to icon URL
  HTTP-STATUS:                return response status (i.e. 200, 0 if none yet)
  LIFETIME:integer|hh:mm:ss   or "do-not-disturb" (re)sets process lifetime
  MAP-FILE:string             map the supplied file to a path
  MAP-PATH:string             map the supplied path to a file
  NOOP:[string]               do nothing, just return a success status
  REDACT:opaque               append the trailing binary data to the buffer
  REDACT-SIZE:integer         pre-allocate buffer space
  SCRIPT-CONTROL:string       equivalent of CGI response Script-Control: field
  TIMEOUT-BIT-BUCKET:integer  or "none" sets script into bit-bucket timeout
  TIMEOUT-NOPROGRESS:integer  or "none" sets request no-progress timeout
  TIMEOUT-OUTPUT:integer      or "none" sets request output timeout
  WATCH:string                when WATCHing 'script' display this string


CLIENT-READ: CALLOUT
--------------------
A script can initiate reads direct from the client using the CLIENT-READ:
callout.  Although this has little value for the standard browser, which when
using HTTP will only supply a body with a POSTed request and then only as a
block of request data, a custom application or Java applet could initiate an
"interactive" dialog with a script.  When the CLIENT-READ: callout is received
by the server it queues a network read from the client.  If an when this
completes the record is written to the script via the normal HTTP$INPUT stream. 
The script can write records to the client via it's normal SYS$OUTPUT stream. 
This I/O is asynchronous.  The client records read are transported via the
normal server protocols and so support communication via SSL, providing a
secured stream for such communication.  Any functionality that can be built
into a server-end script and it's associated client-end application should be
able to be supported via this mechanism.  Of course, for extended transactions
some consideration must be given to request and script timeouts.


REQUEST REDACTION
-----------------
Callout processing may redact (completely rewrite and restart) a request.

  re-dact

    -verb (used with object)

    1.  to put into suitable literary form; revise; edit.
    2.  to draw up or frame (a statement, proclamation, etc.).

    [Origin: 13501400; ME < L redctus (ptp. of redigere to lead back), equiv.
    to red- red- + ctus, ptp. of agere to lead; see act] 

To do this a script must use the REDACT:<opaque> callout to send back to the
server a completely new request header and body (if applicable) which the
server then treats as if received from the client over the network.  This
allows a request to be partially or completely rewritten (as required) and
restarted.  The data supplied to this callout is treated as completely opaque
and care must be taken to include all and no extra carriage-control, etc.

An elementary (and somewhat contrived) example:

  stdout = freopen ("SYS$OUTPUT:", "w", stdout, "ctx=bin", "ctx=xplct");
  fputs (getenv("CGIPLUSESC"),stdout);
  fflush (stdout);
  fwrite ("REDACT:HTTP/1.1 POST /and_example.php\r\n", 39, 1, stdout);
  fflush (stdout);
  fwrite ("REDACT:Host: example.com\r\n", 26, 1, stdout);
  fflush (stdout);
  fwrite ("REDACT:Content-Length: 26\r\n", 27, 1, stdout);
  fflush (stdout);
  fwrite ("REDACT:Content-Type: application/x-www-form-urlencoded\r\n",
          58, 1, stdout);
  fflush (stdout);
  fputs ("REDACT:\r\n",stdout);
  fflush (stdout);
  fwrite ("REDACT:one=two&three=four\n", 26, 1, stdout);
  fflush (stdout);
  fputs (getenv("CGIPLUSEOT"),stdout);
  fflush (stdout);

Once the request has been redacted the script just finishes processing without
other output and the server transparently restarts processing.

This facility was originally incorporated to allow a PAPI

  http://papi.rediris.es/
  http://en.wikipedia.org/wiki/Point_of_Access_for_Providers_of_Information

authentication agent to store a request on-disk and then some time and several
processing steps later restart the original request processing again.


MEMORY BUFFER
-------------
Bulk data transfer from script to server is much more efficient using using a
(global section) memory buffer.  Intended for transfers of multiple megabytes,
tens of megabytes, and so up.  The script requests such a buffer using a
callout.  The script is advised of the global section name and maps the section
into its memory and then populates the buffer.  When the buffer if full or
otherwise ready the script issues another callout with the number of bytes to
write.  This write is accomplished asynchronously and may comprise multiple
network $QIOs.  Associated callouts:

  BUFFER-BEGIN:integer        create temporary global section for output
  BUFFER-END:                 release the global section
  BUFFER-WRITE:integer        write <integer> bytes from the buffer

See DCLMEMBUF.C module for internal details and [SRC.MISC]MEMBUFLIB.C and
[SRC.MISC]MEMBUFDEMO.C for examples of script code suitable to use the memory
buffer facility. 


GATEWAY_BG
----------
The CGI.C module provides a "GATEWAY_BG" CGI variable that contains the BG:
(socket) device connected to the client.  This device is created shareable. 
Opening a channel to it allows a script to directly output to the TCP/IP
socket, bypassing the server completely.  NEEDLESS TO SAY THIS REDUCES OVERHEAD
CONSIDERABLY and for a certain class of services may be appropriate.  Note that
this is a completely RAW stream, the script must supply all carriage-control,
etc.  Also, because it is raw, it is also completely unencrypted and so cannot
be used with an SSL request or WATCHed for trouble-shooting purposes.

The script must supply a full NPH response header to the client, and a
GATEWAY-BEGIN:nnn callout to the server, supplying (for logging, etc.) the HTTP
status code of the response.  When the response body transmission is complete
the script must supply a GATEWAY-END:nnn callout, providing the server with
the data count transfered (again for logging, etc.).  If a channel to the BG:
device is opened it should always be closed when it is finished with.  Failure
to do so could lead to resource starvation for the server.  When complete the
script just concludes as normal.  The following is an example.

  fflush (stdout);
  fprintf (stdout, "%s\n", getenv("CGIPLUSESC"));
  fflush (stdout);
  fprintf (stdout, "GATEWAY-BEGIN: %d\n", 200);
  fflush (stdout);

  byteCount = fprintf (BgOut, "All sorts of rubbish to the raw socket!\n");

  fprintf (stdout, "GATEWAY-END: %d\n", bytesCount);
  fflush (stdout);
  fprintf (stdout, "%s\n", getenv("CGIPLUSEOT"));
  fflush (stdout);


ZOMBIES
-------
The reuse of DCL script processes for CGI scripting provides very significant
performance gains with very little _real_ possibility of undesirable
interaction between uses (where scripts are "well-behaved", which should be all
enviornments). When a non-zero zombie lifetime is specified DCL script
processes implicitly persist between uses for standard CGI and DCL (SSI)
commands as well as explicitly with CGIplus scripts. When not being used to
process a request these script processes are termed "zombies" ;^) they are
neither "alive" (executing a script and processing a request) nor are they
"dead" (script process deleted and task structure free). Instead the script
process is in a LEF state waiting for more input via CGIPLUSIN. A great deal of
care is taken to ensure there is no interaction between uses (all symbols are
deleted, output mailbox is emptied), but there can be no "iron-clad" guarantee.
Use of zombies (persistent DCL processes) is disabled by setting the
appropriate configuration parameter to zero. The same DCL EOF mechansism is
used to signal end-of-output in all process-persistent environments.


SCRIPTING PROCESSES
-------------------
As of WASD 7.1 the creation of scripting processes has been moved from
lib$spawn() to sys$creprc().  This was primarily to support detached processes
executing under a different persona.  There are two modes for scripting now. 

The first exclusively bases scripting on subprocesses (still created using
sys$creprc()) executing using the server account).  This is (should be ;^)
completely compatible with versions prior to WASD 7.1 and can be supported on
all previous VMS versions WASD compiled and executed under.

The second mode uses detached processes.  These are completely autonomous
processes, with full, not pooled quotas, etc.  This may be an advantage in
itself, with resource exhaustion (by the server itself) less likely.  These
processes would usually be created using the same account as the server, but
with the server using the sys$persona...() services (the basics available since
VMS V6.2) can be executing under a different account opening up a whole raft of
possibilities (a la U**x setuid()), see below.

One of the real advantages in using subprocesses is their automatic cleanup
during parent process deletion.  With detached processes there is no such
convenience.  It is very much up to the application author to completely manage
the life-cycle of these processes.  Whilst the author wishes to only employ
user-mode code this becomes an issue under some circumstances.  The server
maintains a list of all processes it manages and so during normal image
run-down the exit handler can sys$delprc() these without any trouble.  This
will probably be 99.9% of the time.  The other 0.1% might be represented by a
site administrator doing a STOP/id= instead of the more usual and convenient
HTTPD/DO=EXIT on the server process for some reason.  The STOP results in the
exit handler not gaining control and so any scripting processes not being
deleted.

To avoid having potentially a large number of now unmanaged processes left
permanently on the system (or worse still, after a number of these accumulating
on the system), the server during startup scans all candidate processes on the
system and deletes those associated with it's previous incarnation.  How can it
tell processes it created from any others?  Good question!  Well, it may have
created them under a different account so it can't just delete any others
running under it's account besides itself, particularly if there may be
multiple server executing on the one system.  OK, how do we find them?  These
processes have a mailbox 'terminal', so scan for those with 'MBA'.  So do lots
of other processes!  But only those created by the server have a specific ACL
attached to the device, with a special, unique identifier in the first ACE.  If
this ACL is detected the process is deleted.  The rights identifier must be
server-process-unique and by default is generated from the process name.  For
instance "WASD:80" would require an identifier "WASD_PRC_WASD_80".  Not too
complex, especially considering the basics of the code to create such an ACL
must exist anyway, allowing processes under non-server accounts to connect to
them.

Yet another issue!  With detached processes created via LOGINOUT.EXE the full
process life-cycle is undertaken, including SYLOGIN.COM and LOGIN.COM, which
may write to SYS$OUTPUT during execution.  This output is obviously undesirable
;^) and so is absorbed.  A sentinal (similar to those used for script EOF and
callout ESC and EOT) is output when the server supplied DCL commands being read
via the SYS$COMMAND mailbox gain control.  This is detected by the server,
output absorbtion is turned off and normal CGI output processing begun.

Scripting process priorities are set in the following way.  Script processes
created for execution under the server username, or a username specified via a
"SET SCRIPT=AS=" are created one priority lower than the server process itself. 
Processes to be executed under a /~username, that is via a "SET SCRIPT=AS=~"
rule, are created two priorities lower than the server.  The rationale being
that the server process itself should always have a slight edge (it will
probably be I/O bound anyway), and "server" scripts should have a slight edge
over "user" scripts.  This way the server should respond quickly, even if
script processing on a busy system then takes a little time to complete the
request.  For example, if the server executes at 4 then scripts created under
the server account will execute at 3 and /~username scripts at 2.  These may be
changed in DCL.H and via recompilation.

Setting a script to have a maximum CPU consumption (set /path script=CPU=5)
Results in a "watchdog" routine being invoked each time the DCL supervisor
ticks.  This asynchronous $GETJPI compares the current CPU consumption with
that at the beginning of the script execution.  Note it's the *script* not
process, and is not the same as CPULM process quota.  This provides somewhat
more versatility than a CPULM-style (which won't work on LOGINOUT.EXE created
processes anyway).  It does however rely on the DCL supervisor and so is
subject to the timer granularity of that subsystem.  When the CPU is being
controlled in this way the supervisor ticks at a more appropriate period, so
that although not accurate to the second in terminating a excessive-CPU script
it should not be too far off the mark!


"suEXEC"/"SETUID" SCRIPTING
---------------------------
The detached scripting mechanism described above is coupled with the VMS V6.0
and later sys$persona...() system services to allow scripting under user
accounts specified by the system administrator using mapping rules.  This must
be enabled using the command-line qualifier /PERSONA.  As with all scripting
this should be used with caution, although the detached script process,
isolated from the main server by account differences, should not be able to
affect the server directly.  This only interaction with it should be via the
IPC mailboxes, which are still owned by the server process, with the user
script granted access via an ACL on the device.

The /PERSONA qualifier takes an optional rights identifier parameter.  If this
is supplied access to the persona services (as as a consequence all scripting)
is controlled by account possession of the identifier.  Note that this includes
*all* accounts, including the HTTP server account.  The format of the qualifier
use then becomes something like /PERSONA=WASD_SCRIPTING.

By default only non-privileged accounts can be used to script.  If privileged
accounts are required for scripting the /PERSONA=RELAXED keyword must be
supplied.

Persona scripting can be further restricted to authenticated and authorized
requests.  The /PERSONA=AUTHORIZED keyword will enable this.  Unless the
request has been subject to HTTP authorization the request just results in an
error.  A variation on this allows privileged accounts to be used for scripting
only within authorized requests using /PERSONA=RELAXED=AUTHORIZED.

The 'SET /path/* SCRIPT=AS=username' mapping rule allows user names (accounts)
to be specified for (a) script(s) with a particular path.  For instance, the
script "/database/query" could be set up to execute under the user name
DATABASE using rules similar to the following:

  set /database/* script=as=DATABASE
  exec /database/* /database_root/cgi-bin/*

General user scripting (that is, access to accounts via the "/~username" style
syntax) may also be enabled using rules such as the following:

  set /~*/cgi-bin/* script=as=~
  # the following is NOT a typo, the rule is UXEC (User eXEC)
  uxec /~*/cgi-bin/* /*/www/cgi-bin/*
  user /~*/* /*/www/*
  redirect /~* ///~*/

For requests that have been authenticated using the SYSUAF, the username
may provide the scripting account.  Use a SET script=as=$ rule, where the
dollar indicates that before activating the script the server should substitute
the authenticated VMS username ... CAUTION!  If the request was not SYSUAF
authenticated it fails.

  set /cgi-bin/showme* script=as=$

To optionally execute scripts user a SYSUAF authenticated username use the SET
script=as=$? rule.  If not SYSUAF authenticated it is executed under the
default scripting account.

  set /cgi-bin/showme* script=as=$?

It is also possible to direct the server to execute *all* of it's own scripts
under some non-server account by prefixing the entire rule file using something
like the following rule.

  set /* script=as=NOBODY


NOBODY SCRIPTING
----------------
Version 8.1 establishes a new strategy in scripting account - it always
attempts to enable detached scripting with a non-server account to perform the
scripting.  This is the algorithm:

1) If /DEMO subprocess scripting is forced.

2) If /SCRIPT=AS=SUBPROCESS is used subprocess scripting is forced.

3) If /SCRIPT=AS=username is used detached scripting is forced.

4) If the account HTTP$NOBODY exists detached scripting is forced.

5) If /PERSONA is used detached scripting is forced.

6) The scripting process mode is set by [DclDetachProcess].

The advantages of generally scripting under a totally non-server account,
non-user account cannot be overstated.  This /SCRIPT=AS= and HTTP$NOBODY
approach allows this to be available without enabling /PERSONA scripting in
general (and thereby having it not available via mapping rules).  Presto! It
all just happens.  Note that this CANNOT be a username with anything other than
the average Joe privileges.  This may also be used with PERSONA enabled.


SCRIPT RUN-DOWN
---------------
This excellent approach was suggested by Jean-François Piéronne
(jfp@altavista.net).  It makes a significant contribution to improving
performance and reducing overhead.

As of WASD 7.2 a change in behaviour for client connection drops.  Prior to
this version the first network write error caused the termination of the script
and process.  Now [DclBitBucketTimeout] or mapping set rule
SCRIPT=BIT-BUCKET=hh:mm:ss control behaviour.  If this is set (non-zero) the
server now just absorbs any further output from the script until the timeout
expires.  The rationale being that most scripts execute relatively quickly,
most connection drops are client impatience or changing of mind, script process
creation and instantiation is relatively expensive and it is better to try and
preserve these wherever possible, or at least allow them to complete their
processing.  Scripts can also set this timeout on a per-request basis using the
TIMEOUT-BIT-BUCKET: callout.

Do-Not-Disturb scripts, indicated by use of the "LIFETIME: do-not-disturb"
callouts, are never automatically run-down or otherwise touched.  Normal
behaviour can be reverted to using a "LIFETIME: configuration".  They can be
administratively purged or force-deleted of course (i.e. from the Admin Menu
and CLI /DO=DCL=).  Do-Not-Disturb lifetimes may be used during critical
sections of processing (ensuring it will not under any normal circumstances
have it's processing disturbed), at the beginning and ending of entire requests
(putting a critical section around the entire request), or even permanently,
making them effectively immortal and like many gods a potential source of all
sorts of subtle and gross affliction ;^)

Also with WASD 7.2 the script process is now checked for an executing image
(JPI$_IMAGNAME) and if it is a $FORCEX is issued.  The rationale is of course
to allow any image exit handlers a chance to do their job.  Prior to v7.2 a
$DELPRC was simply issued, which can cause some issues with some environments,
for example RDB (and other such-like I should imagine), where database
checkpoint/rollback can be induced.  Generally it will be CGIplus/RTE scripts
that require a $FORCEX on the image.  In these cases when the image exits the
queued SYS$COMMAND DCL will cause the process to perform a STOP/id=0 deleting
itself and delivering the completion AST.  On rare occasions (and with standard
CGI scripts) this may not happen so every few seconds (under the control of the
DCL supervisor) the process is agains checked for an executing image.  When it
isn't (or one minute passes, which-ever first) the process is $DELPRCed.


HT_SCRATCH
----------
If defined, this logical locates a directory where scripts can place temporary
files.  Although these scripts should clean up after themselves, temporary or
working files placed into this directory are automatically deleted if last
modified earlier than [DclCleanupScratchMinutesOld] before the scan starts. 
The scan that searches for and deletes these files if present occurs either
when there are no more script processes active or not greater than every
[DclCleanupScratchMinutesMax] minutes.

The CGI variable 'WWW_UNIQUE_ID' can be used to generate unique file names.  To
prevent a file being automatically cleaned up make the first character of it's
name a dollar symbol.  The following DCL code fragment creates unique server
and script file names.

  $ NAME = F$PARSE(WWW_SCRIPT_NAME,,,"NAME")
  $ FILENAME = NAME + "." + WWW_UNIQUE_ID
  $ OPEN /WRITE TMPFILE 'FILENAME'


LOGICAL NAMES
-------------
WASD_FILE_DEV   if defined, provides a command procedure early in the script
                            life-cycle for integrating a WASD-specific logical
                            name table in the process' LNM$FILE_DEV
WASD_FILE_DEV_2             same as above but for a non-primary group 2..15
...
WASD_FILE_DEV_15

WASD_LOGIN      if defined, provides a command procedure executed immediately
                            before the script command/procedure/image
HTTPD$LOGIN     same as above but deprecated as of v10.0

WASD_VERIFY     if defined, to an IP address turns on script/DCL-level verify
                            only for the REMOTE_ADDR client
                if defined, to something else turns on script/DCL-level verify
HTTPD$VERIFY    same as above but *obsolete* as of v10.0

HT_SCRATCH      if defined, directory for working/scratch files used by scripts
                            (cleaned up every [DclZombieLifeTime] minutes max.)


VERSION HISTORY
---------------
25-MAY-2021  MGD  AGENT-BEGIN/END: callouts interact with a v12... agent
                  CGI: set/reset CGI dictionary entry (see MetaConDictionary())
                  DICT: set/reset dictionary entry (see same)
                  WATCH: proctored script by checking *only* [x]Script
10-APR-2021  MGD  v12.0 process naming schema
                    disabled by defining logical name WASD_DCL_PRCNAM_PRE12
22-FEB-2021  MGD  bugfix; DclCalloutDefault() CLIENT-READ:
06-SEP-2020  MGD  callout HTTP-STATUS: detect if a script has responded yet
08-MAR-2020  MGD  DclControlPurgeScriptProcesses() include DclScriptProctor() 
12-FEB-2020  MGD  callout CSP: ("content-security-policy:")
                  callout CSPRO: ("..policy-report-only:")
08-FEB-2020  MGD  add DclPeekReport() activated by scripting report ?at=
                  DclTaskRunDown() rework
07-DEC-2017  MGD  bugfix; nil content CGI responses not delivered
11-OCT-2017  MGD  DclInit() do not adjust SYS$OUTPUT mailbox size when HTTP/2
                    is enabled, issue an informational as required
08-OCT-2017  MGD  DclMemBuf..() memory buffer script IPC (see DCLMEMBUF.C)
                  callout BUFFER-BEGIN:
                  callout BUFFER-END:
                  callout BUFFER-WRITE:
06-OCT-2017  MGD  DclCalloutDefault() GATEWAY-BEGIN flush for response header
15-JUL-2017  MGD  bugfix; DclCalloutDefault() NOTICED: and OPCOM: responses
27-JUN-2017  MGD  bugfix; DclScriptProctor() request is not actually "!!*!"
11-FEB-2017  MGD  DclScriptProctor() allow "*" general idle process
                  bugfix; DclScriptProctor() v11.0 request structure
                    requires dictionary and netio structures
17-APR-2016  MGD  bugfix; remove trailing ":" from |DefineWwwOut| SYS$OUTPUT
29-JAN-2015  MGD  bugfix; DclHttpInput() run down task on ABORT or CANCEL
07-NOV-2015  MGD  DclInit() fit |DclSysOutput| to (default) HTTP/2 frame size
13-JAN-2014  MGD  DclCountScriptProcess()
10-JUL-2013  MGD  DclMailboxAcl() allow usernames without associated
                    identifiers (i.e. shared UICs) by first trying with the
                    username and on failure getting the UIC and using that
16-SEP-2012  MGD  bugfix; distinguish between WebSocket and agent execution
26-NOV-2011  MGD  DclRestartScript() refine WebSocket handling
                  DclCgiPlusInAst() first status indicates script active
                  bugfix; DclScriptProcessCompletionAST() don't WebSockClose()
                    any WebSocket request currrently associated with the task
18-FEB-2011  MGD  bugfix; associated with AST delivery changes for WebSockets
06-JAN-2011  MGD  happy birthday Nomes!
                  DclFindScriptSearchAst() minor refinement; only search
                    for next if script file type not explicitly supplied
01-JUL-2010  MGD  bugfix; DclUpdateScriptNameCache() run-time pointer
14-JUN-2010  MGD  DclScriptProctor()
                  DclSupervisor() also purge script name cache at cleanup
04-JUN-2010  MGD  DclAllocateTask() default unconfigured CGIplus lifetime
09-FEB-2010  MGD  path SETing script=lifetime=<hh:mm:ss>
                  callout LIFETIME: can accept <hh:mm:ss>
26-JAN-2010  MGD  Web Socket scripting
                  callout SCRIPT-CONTROL:
11-JUL-2009  MGD  DclCgiScriptSysCommand() and DclCgiPlusScriptSysCommand()
                  WASD_FILE_DEV and WASD_FILE_DEV_n procedure
                  WASD_LOGIN procedure (obsolescents HTTPD$LOGIN)
                  WASD_VERIFY functionality supercedes HTTPD$VERIFY
18-MAY-2008  MGD  bugfix; DclUpdateScriptNameCache() undo bug from fix of
                    non-existant problem from 12-APR-2008 (talk about it!)
19-APR-2008  MGD  callout WATCH:string for WATCHing script item
12-APR-2008  MGD  bugfix; DclUpdateScriptNameCache() copy determined
                  script invocation method ("@","$","=", etc.) into cache
20-NOV-2007  MGD  callout REDACT: and REDACT-SIZE:
                  callout NOTICED:
                  callout OPCOM:
                  callout BODY: obsolete (and non-working)
24-JUL-2007  MGD  DclSysOutputAst() if WATCHing DCL and non-CGI-compliant
                  response continue to end-of-script bit-bucketing output
                  (DECNET.C code already provides this behaviour)
11-MAY-2007  MGD  bugfix; DclBegin() agent runs under default account
22-AUG-2006  MGD  add GATEWAY-CCL: callout
                  DclTaskRunDown() ensure socket carriage-control is reset
06-OCT-2005  MGD  bugfix; DclSysCommandAst() allow for the queued
                  post-CGIplus script STOP/id=0 and EOF,
                  bugfix; copy sentinals into request storage to prevent
                  them (potentially) being overwritten by an early call
                  to DclScriptProcessCompletionAST()
02-JUN-2005  MGD  ensure soft limit is no less than 75% of hard limit
25-MAY-2005  MGD  DclControlPurgeScriptProcesses() provide PURGE/DELETE
                  selected on username, script name, script file name
20-APR-2005  MGD  DclTaskRunDown() proactively handle task after SS$_NONEXPR
26-FEB-2005  MGD  relax configured file type check if path SETing
                  script=command=<..> provides a full activation command,
                  HTTPD$VERIFY can now specify a REMOTE_ADDR IP address
24-NOV-2004  MGD  bugfix; (authorization) agents should not begin to read
                  a POSTed request body (Jean-Pierre Petit, jpp@esme.fr)
18-MAY-2004  MGD  provide additional WATCH data when allocating persistent
                  DCL task (after nasty script name parse issue in .ru)
26-FEB-2004  MGD  script processes SET DEFAULT before activation
                  CGI variable SCRIPT_DEFAULT (script=default=<directory>)
14-FEB-2004  MGD  set script process parse extended/traditional if path ODS set
11-JAN-2004  MGD  bugfix; DclAllocateTask() CGIplus with virtual services
18-SEP-2003  MGD  bugfix; suppress output after "Script-Control: x-error..."
10-SEP-2003  MGD  refine MAP-PATH to return 400 response if no reverse,
                  bugfix; MAP-FILE: stripping leading character
19-JUL-2003  MGD  provide network mode detached process creation
                  revise detached process cleanup candidate identification
                  revise script activation code (include .CLD)
                  bugfix; DclScriptProcessPurge()
18-JUN-2003  MGD  bugfix; (potential anyway) correct increment of
                  queued I/O counters around delivery of error ASTs
19-APR-2003  MGD  bugfix; DclSysOutputAst() do not rundown script process 
                  if the error generated came from "Script-Control:",
                  bugfix; allow for '!' from (!$blah) mapping rule
15-MAR-2003  MGD  script=as=$? to indicate optional use of SYSUAF username
                  implement authorization "scriptas" keyword directive
16-FEB-2003  MGD  with RTEs look first for one that was executing the same
                  script name and path then if not found fall back to LRU
                  idle RTE executing same script or just to LRU RTE,
                  make DCL command buffer space dynamic
30-JAN-2003  MGD  build up 'records' from single byte output streams
                  (ask Alex Ivanov about GhostScript output),
                  path set carriage-control on CGIPLUSIN stream
                  (including end of callout stream)
08-OCT-2002  MGD  refine default scripting
23-SEP-2002  MGD  additional persona counters,
                  'CliScriptAs' allows a NOBODY scripting environment
                  without enabling PERSONA in general
15-JUN-2002  MGD  bugfix; BodyRead() QueuedClientRead++ in DclHttpInputAst()
27-APR-2002  MGD  use sys$setprv(),
                  bugfix; DclFindFileEnd() reset result file name
02-FEB-2002  MGD  rework HTTP$INPUT due to request body processing changes
26-JAN-2002  MGD  bugfix; DclTaskRunDown() reset script task type
29-OCT-2001  MGD  PERSONA_MACRO reporting
21-OCT-2001  MGD  kludge work around spawning authorized privs with $CREPRC
29-SEP-2001  MGD  multiple instance support (minor changes)
25-AUG-2001  MGD  bugfix; always generate callout sequences
04-AUG-2001  MGD  support module WATCHing
25-APR-2001  MGD  watchdog on CPU time consumed by scripts, 
                  use HttpdTick() to drive DclSupervisor(),
                  bugfix; SCRIPT_FILENAME with CGIplus
13-APR-2001  MGD  change client write error behaviour for CGIplus
                  (CGIplus script 'bit-bucket' period),
                  changes to script run-down ($FORCEX),
                  DCL supervisor now more granular at fifteen seconds,
                  callout BODY: to return request body on CGIPLUSIN stream,
                  callout CGIPLUS: to support stream variables
06-MAR-2001  MGD  CONTENT-TYPE: callout maps file suffix to MIME content-type
                  ICON-TYPE: callout maps file suffix/content-type to icon URL
05-DEC-2000  MGD  DclCleanupScratch(),
                  modify HTTPD$VERIFY to allow for strict CGI output
19-NOV-2000  MGD  bugfix; for $persona_assume() on VAX (sigh!)
01-OCT-2000  MGD  scripting process creation using sys$creprc(),
                  detached and persona-based scripting
13-SEP-2000  MGD  suppress callout response using leading '!' or '#',
                  APACHE_INPUT changed to APACHE$INPUT (1.3-12)
                  add GATEWAY-BEGIN: and GATEWAY-END: callouts,
                  add CLIENT-READ: callout reads direct from client to script
08-AUG-2000  MGD  limit script output of ENDOFFILE,
24-JUN-2000  MGD  persistent run-time environments,
                  script cache now uses mapped script file name,
                  fixed potential problem when setting 'DclSysOutputSize',
                  bugfix; HEAD requests specifying content-length
27-MAY-2000  MGD  add BYTLM check before creating mailboxes
08-APR-2000  MGD  some (VMS) Apache compatibility,
                  if(!cfptr->cfScript.Enabled)
04-MAR-2000  MGD  use FaolToNet(), et.al.
13-JAN-2000  MGD  add OPCOM messages
03-JAN-2000  MGD  support ODS-2 and ODS-5 using ODS module for script find
28-NOV-1999  MGD  provide HTTPD$LOGIN
10-OCT-1999  MGD  make SYS$COMMAND and CGIPLUSIN mailbox sizes configurable,
                  bugfix; DclSysOutputToClientAst()
28-AUG-1999  MGD  callout/agent support,
                  support Purveyor/Cern WWW_IN: and WWW_OUT:,
                  bugfix; sizeof(StopId)-1
12-JUN-1999  MGD  change some WatchData() to WatchDataDump()
12-FEB-1999  MGD  refine WATCH information
07-NOV-1998  MGD  WATCH facility
17-OCT-1998  MGD  script name cache,
                  error report support
19-SEP-1998  MGD  improve granularity of script search,
                  do not search for established CGIplus scripts
                  (this reduces CGIplus script activation time by 50%!!)
15-AUG-1998  MGD  replace per-script process timers with DclSupervisor()
27-MAY-1998  MGD  generate CGI variables only once for any one request
02-APR-1998  MGD  see "April 1998 Note" above,
                  report status 500/501 if script returns no output
28-MAR-1998  MGD  ensure script output is null-terminated (for CGI.C)
16-DEC-1997  MGD  generalized CGI processing unbundled into CGI.c module
06-DEC-1997  MGD  resolving a suspected inconsistent AST delivery situation
                  by requiring all $QIO()s with an AST routine to ensure any
                  queueing errors, etc. are reported via the AST routine
19-OCT-1997  MGD  extensible script run-time environment,
                  HTTP_ACCEPT_CHARSET, HTTP_FORWARDED and HTTP_HOST variables,
                  change in behaviour: CGI "Content-Type:" response bodies now
                  only have carriage-control checked/adjusted if "text/..."
10-SEP-1997  MGD  add "!'F$VERIFY(0)" to start of DCL in case verify on account
09-AUG-1997  MGD  ACCEPT_LANGUAGE variable
01-AUG-1997  MGD  allow supplying request header AS WELL AS body, or only body,
                  added AUTH_REALM, AUTH_GROUP, HTTP_ACCEPT, and 
                  REQUEST_TIME_GMT/LOCAL CGI variables
01-JUN-1997  MGD  persistent DCL processes, CGIplus, new for HTTPd v4.2,
                  DCL.C completely re-designed!
26-APR-1997  MGD  bugfix; serious flaw POST content handling since v4.0
                  to REQUEST.C, PUT.C in version 4.0 (rewrite of HTTP$INPUT)
01-FEB-1997  MGD  HTTPd version 4
14-NOV-1996  MGD  bugfix; no status was being returned after "DELETE/SYMBOL X"
                  in DclSysCommandStringSymbol()
06-APR-1996  MGD  miscellaneous refinements
26-MAR-1996  MGD  added WWW_HTTP_AUTHENTICATION, scripts can now authenticate
01-DEC-1995  MGD  HTTPd version 3
19-SEP-1995  MGD  changed carriage-control on records from <CR><LF> (the strict
                  HTTP requirement) to single newline (<LF>, de facto standard)
                  This will be slightly more efficient, and "more compliant"!
21-APR-1995  MGD  bugfix; DclSysOutputAst()
03-APR-1995  MGD  added remote user authentication and CGI symbol
20-MAR-1995  MGD  bugfix; DclQioHttpInput()
20-DEC-1994  MGD  initial development as a module for multi-threaded daemon
*/
#endif /* COMMENTS_WITH_COMMENTS */
/*****************************************************************************/

#ifdef WASD_VMS_V7
#undef _VMS__V6__SOURCE
#define _VMS__V6__SOURCE
#undef __VMS_VER
#define __VMS_VER 70000000
#undef __CRTL_VER
#define __CRTL_VER 70000000
#endif

/* standard C header files */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

/* VMS related header files */

/* cmbdef.h is not defined for VAXC 3.n */
#define CMB$M_READONLY 0x01
#define CMB$M_WRITEONLY 0x02

/* let's just make sure these are available everywhere */
#define IO$M_NORSWAIT 0x400
#define SS$_MBFULL 0x000008d8

#include <descrip.h>
#include <iodef.h>
#include <jpidef.h>
#include <kgbdef.h>
#include <libdef.h>
#include <libdtdef.h>
#include <prcdef.h>
#include <prvdef.h>
#include <rms.h>
#include <ssdef.h>
#include <stsdef.h>
#include <uaidef.h>

/* application header files */
#include "wasd.h"
#include "websock.h"

#define WASD_MODULE "DCL"

/* provides code to support vanilla-CGI use of CGIplus callouts */
#define CGIPLUS_CALLOUT_FOR_CGI 1

/* provides APACHE$INPUT: stream for VMS Apache compatibility */
#define STREAMS_FOR_APACHE 1

/* provides WWW_IN: and WWW_OUT: streams for Purveyor/Cern compatibility */
#define STREAMS_FOR_PURVEYOR_AND_CERN 1

/* in seconds */
#define DCL_SUPERVISOR_TICK_MIN  2
#define DCL_SUPERVISOR_TICK_MAX 15

/* just a sentinal used to indicate when the DCL supervisor timer expires */
#define DCL_SUPERVISOR_TICK -1

/* maximum period tryig to force an image to exit */
#define DCL_FORCE_IMAGE_EXIT_SECONDS 60

/******************/
/* global storage */
/******************/

BOOL  DclAgentPre12,
      DclNameProcessPre12,
      DclUseZombies;

int  DclCgiHeaderSize,
     DclCgiPlusLifeTimePurgeCount,
     DclCgiPlusInSize,
     DclCleanupMinutesMax,
     DclCleanupMinutesOld,
     DclCurrentScriptProcess,
     DclDetachProcessPriorityServer,
     DclDetachProcessPriorityUser,
     DclFauxRequestCount,
     DclHitHardLimitCount,
     DclMailboxBytLmRequired,
     DclPersonaServicesAvailable,
     DclProctorEnabled,
     DclPurgeCount,
     DclPurgeScriptProcessesCount,
     DclPurgeScriptNameCacheCount,
     DclScriptDetachProcess,
     DclSoftLimitPurgeCount,
     DclScriptProcessHardLimit,
     DclScriptProcessSoftLimit,
     DclSysCommandSize,
     DclSysOutputQuota,
     DclSysOutputSize,
     DclZombieLifeTimePurgeCount;

char  *DclHttpdScratch;

/* two longwords so it can be used by sys$grantid() */
unsigned long  ProcessRightsIdent [2];

LIST_HEAD  DclTaskList;

LIST_HEAD  DclScriptNameCacheList;

#define DEFAULT_CGI_VARIABLE_PREFIX "WWW_"
char DclCgiVariablePrefix [32] = DEFAULT_CGI_VARIABLE_PREFIX;
int DclCgiVariablePrefixLength = sizeof(DEFAULT_CGI_VARIABLE_PREFIX)-1;

/********************/
/* external storage */
/********************/

#ifdef DBUG
extern BOOL Debug;
#else
#define Debug 0 
#endif

extern BOOL  CliDemo,
             ControlExitRequested,
             ControlRestartRequested,
             Http2Enabled,
             HttpdNetworkMode,
             OdsExtended,
             OperateWithSysPrv,
             ProtocolHttpsAvailable,
             PersonaMacro;

extern const int64  Delta60Sec;

extern int  CliPersonaEnabled,
            DclMemBufFailCount,
            DclMemBufGblPageCount,
            DclMemBufGblPageCountMax,
            DclMemBufGblPageCountMin,
            DclMemBufGblPageMax,
            DclMemBufGblPageMin,
            DclMemBufSizeDefault,
            DclMemBufGblSectionCount,
            DclMemBufSizeMax,
            DclMemBufSizeMin,
            EfnWait,
            EfnNoWait,
            Http2MaxFrameSize,
            HttpdTickSecond,
            InstanceEnvNumber,
            InstanceNumber,
            NetAcceptBytLmRequired,
            NetConcurrentProcessMax,
            NetListenBytLmRequired,
            NetReadBufferSize,
            OpcomMessages,
            OutputBufferSize,
            ProcessPriority,
            ServerPort,
            WebSockCurrent;

extern int64  DclMemBufCount64,
              HttpdTime64;

extern int  ToLowerCase[],
            ToUpperCase[];

extern unsigned long  CrePrcMask[],
                      DetachMask[],
                      GrantIdMask[],
                      MailboxMask[],
                      SysPrvMask[],
                      WorldMask[];

extern char  CliScriptAs[],
             ErrorSanityCheck[],
             HttpProtocol[],
             HttpdScriptAsUserName[],
             ProcessIdentName[],
             ServerHostPort[],
             SoftwareID[];

extern LIST_HEAD  PersonaCacheList;
extern int  PersonaCacheCount,
            PersonaCacheEntries;

extern ACCOUNTING_STRUCT  *AccountingPtr;
extern CONFIG_STRUCT Config;
extern HTTPD_PROCESS  HttpdProcess;
extern MSG_STRUCT Msgs;
extern LIST_HEAD  RequestList;
extern LIST_HEAD  WebSockList;
extern WATCH_STRUCT  Watch;

/*****************************************************************************/
/*
Set and ensure limits are reasonable at server startup.
*/ 

DclInit ()

{
   int  cnt, status,
        SetPrvStatus;
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclInit()");

   DclAgentPre12 = (SysTrnLnm (WASD_DCL_AGENT_PRE12) != NULL);

   DclNameProcessPre12 = (SysTrnLnm (WASD_DCL_PRCNAM_PRE12) != NULL);

   DclHttpdScratch = v10orPrev10(DCL_HTTPD_SCRATCH,-1);

   /* command line overrides configuration, default fallbacks */
   if (!DclSysCommandSize) DclSysCommandSize = Config.cfBuffer.SizeDclCommand;
   if (!DclSysCommandSize) DclSysCommandSize = DEFAULT_DCL_SYSCOMMAND_SIZE;
   if (!DclSysOutputSize) DclSysOutputSize = Config.cfBuffer.SizeDclOutput;

   /* if not specified then make it the same as the network buffer */
   if (!DclSysOutputSize) DclSysOutputSize = OutputBufferSize;
   if (!DclSysOutputSize) DclSysOutputSize = DEFAULT_DCL_SYSOUTPUT_SIZE;

   if (Config.cfBuffer.SizeNetMTU)
   {
      /* MTU has been specified, adjust to an even number of MTUs */
      DclSysOutputSize /= Config.cfBuffer.SizeNetMTU;
      DclSysOutputSize++;
      DclSysOutputSize *= Config.cfBuffer.SizeNetMTU;
      /*
         Chunked output is so common for script output allow for the overhead.
         The trade-off is losing 8 bytes from non-chunked MTU.
      */
      if (DclSysOutputSize > 8) DclSysOutputSize -= 8;
   }
   /* let's not get too silly */
   if (DclSysOutputSize < 1024)
      DclSysOutputSize = DEFAULT_DCL_SYSOUTPUT_SIZE;

   if (!DclSysOutputQuota) DclSysOutputQuota = Config.cfBuffer.QuotaDclOutput;
   if (DclSysOutputQuota <= DclSysOutputSize)
      DclSysOutputQuota = DclSysOutputSize + 256;

   if (!DclCgiHeaderSize) DclCgiHeaderSize = Config.cfBuffer.SizeDclCgiHeader;
   if (!DclCgiHeaderSize) DclCgiHeaderSize = DEFAULT_DCL_CGI_HEADER_SIZE;
   if (!DclCgiPlusInSize) DclCgiPlusInSize = Config.cfBuffer.SizeDclCgiPlusIn;
   if (!DclCgiPlusInSize) DclCgiPlusInSize = DEFAULT_DCL_CGIPLUSIN_SIZE;
   /* HTTP$INPUT size is determined by network read buffer size! */

   DclScriptProcessSoftLimit = Config.cfScript.ScriptProcessSoftLimit;
   DclScriptProcessHardLimit = Config.cfScript.ScriptProcessHardLimit;

   if (DclScriptProcessHardLimit < 20) DclScriptProcessHardLimit = 20;
   if (DclScriptProcessHardLimit > NetConcurrentProcessMax)
      DclScriptProcessHardLimit = NetConcurrentProcessMax;

   /* soft limit should be no less than 75% of hard limit */
   if (DclScriptProcessSoftLimit < DclScriptProcessHardLimit / 2 +
                                   DclScriptProcessHardLimit / 4)
      DclScriptProcessSoftLimit = DclScriptProcessHardLimit / 2 +
                                  DclScriptProcessHardLimit / 4;

   DclCleanupMinutesMax = Config.cfScript.CleanupScratchMinutesMax;
   DclCleanupMinutesOld = Config.cfScript.CleanupScratchMinutesOld;
   if (DclCleanupMinutesOld < DclCleanupMinutesMax)
      DclCleanupMinutesOld = DclCleanupMinutesMax;

   if (Config.cfScript.ZombieLifeTime) DclUseZombies = true;

   if (DclMemBufSizeDefault) DclMemBufInit ();

   if (CliDemo)
      DclScriptDetachProcess = false; 
   else
   if (strsame (CliScriptAs, "SUBPROCESS", -1))
      DclScriptDetachProcess = false;
   else
   if (HttpdScriptAsUserName[0])
      DclScriptDetachProcess = true;
   else
   if (CliPersonaEnabled)
      DclScriptDetachProcess = true;
   else
      DclScriptDetachProcess = Config.cfScript.DetachProcess;

   if (DclScriptDetachProcess)
   {
      FaoToStdout ("%HTTPD-I-DCL, detached process scripting\n");

      DclCleanupScriptProcesses ();

      DclPersonaServicesAvailable = CliPersonaEnabled;
      FaoToStdout ("%HTTPD-I-DCL, persona !&?\rnot \renabled at command line\n",
                   DclPersonaServicesAvailable);

      if (DclPersonaServicesAvailable || HttpdScriptAsUserName[0])
      {
         status = PersonaInit ();
         if (VMSnok (status))
         {
            FaoToStdout ("%HTTPD-F-DCL, persona not available\n-!&M\n", status);
            exit (status);
         }
      }

      if (Config.cfScript.DetachProcessPriority[0])
      {
         /* get at most two integers from this parameter */
         cptr = Config.cfScript.DetachProcessPriority;
         while (*cptr && !isdigit(*cptr)) cptr++;
         if (isdigit(*cptr))
         {
            DclDetachProcessPriorityServer = atoi(cptr);
            while (*cptr && isdigit(*cptr)) cptr++;
         }
         while (*cptr && !isdigit(*cptr)) cptr++;
         if (isdigit(*cptr)) DclDetachProcessPriorityUser = atoi(cptr);
         /* can't set user script priorities above those of the server! */
         if (DclDetachProcessPriorityUser > DclDetachProcessPriorityServer)
            DclDetachProcessPriorityUser = DclDetachProcessPriorityServer;
      }
   }
   else
      FaoToStdout ("%HTTPD-I-DCL, subprocess scripting\n");

   if (Http2Enabled)
   {
      if (Http2MaxFrameSize <= 64000)
         if (DclSysOutputSize != Http2MaxFrameSize - HTTP2_FRAME_HEADER_SIZE)
            FaoToStdout ("%HTTPD-I-DCL, with HTTP/2 enabled \
SYS$OUTPUT mailbox might be more efficient at !UL bytes\n",
                         Http2MaxFrameSize - HTTP2_FRAME_HEADER_SIZE);
   }

   if (DclProctorEnabled) SysDclAst (&DclScriptProctor, NULL);

   DclCountScriptProcess ();
}

/*****************************************************************************/
/*
This function does not return a status value. If an error occurs the
'NextTaskFunction()' is executed. The calling routine may assume that this
module will always execute the 'NextTaskFunction()' at some stage. No need to
look for an established CGIplus script, we know it's there otherwise it never
would have been allocated. For new CGIplus scripts, as well as for standard
CGI scripts, first find the script file (as well as confirming it does exist!)
Already established CGIplus scripts and DCL commands can begin I/O with the
script process immediately.
*/ 

DclBegin
(
REQUEST_STRUCT *rqptr,
REQUEST_AST NextTaskFunction,
char *DclCommand,
char *ScriptName,
char *CgiScriptFileName,
char *CgiPlusScriptFileName,
char *ScriptRunTime,
REQUEST_AST CalloutFunction
)
{
   BOOL  MappedScriptAs;
   int  len, status,
        BasePriority,
        TaskType;
   char  *ScriptAsPtr;
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
   {
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL, "DclBegin()");
      WatchDataFormatted (
"DclCommand !&Z\n\
ScriptName !&Z\n\
CgiScriptFileName !&Z\n\
CgiPlusScriptFileName !&Z\n\
ScriptRunTime !&Z\n\
CalloutFunction !&A\n\
ProctorPtr !8XL\n\
AgentRequestPtr !&Z\n\
Md5HashPath: !16&H\n",
         DclCommand, ScriptName, CgiScriptFileName, CgiPlusScriptFileName,
         ScriptRunTime, CalloutFunction, rqptr->ProctorPtr,
         rqptr->AgentRequestPtr, &rqptr->Md5HashPath);
   }

   if (rqptr->AgentRequestPtr &&
       rqptr->AgentResponsePtr)
   {
      /* should not (still) have a response at this stage */
      rqptr->AgentResponsePtr = NULL;
      rqptr->rqResponse.HttpStatus = 500;
      ErrorVmsStatus (rqptr, SS$_BUGCHECK, FI_LI);
      ErrorNoticed (rqptr, SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
      SysDclAst (NextTaskFunction, rqptr);
      return;
   }

   if (!ProtocolHttpsAvailable)
   {
      /* WebSockets require SHA-1 hash supplied by OpenSSL */
      if (rqptr->WebSocketRequest)
      {
         rqptr->rqResponse.HttpStatus = 502;
         ErrorGeneral (rqptr, MsgFor(rqptr,MSG_REQUEST_FORMAT), FI_LI);
         ErrorNoticed (rqptr, 0, "WebSocket requires SSL", FI_LI);
         SysDclAst (NextTaskFunction, rqptr);
         return;
      }
   }

   if (ERROR_REPORTED (rqptr))
   {
      /* previous error, cause threaded processing to unravel */
      SysDclAst (NextTaskFunction, rqptr);
      return;
   }

   if (!Config.cfScript.Enabled)
   {
      rqptr->rqResponse.HttpStatus = 403;
      ErrorGeneral (rqptr, MsgFor(rqptr,MSG_GENERAL_DISABLED), FI_LI);
      SysDclAst (NextTaskFunction, rqptr);
      return;
   }

   BasePriority = ProcessPriority - DclDetachProcessPriorityServer;
   if (DclScriptDetachProcess)
   {
      if (HttpdScriptAsUserName[0])
         ScriptAsPtr = HttpdScriptAsUserName;
      else
         ScriptAsPtr = HttpdProcess.UserName;
   }
   else
      ScriptAsPtr = "";
   MappedScriptAs = false;

   if ((void*)CalloutFunction == (void*)&AuthAgentCallout)
   {
      /* authorization agent task, ensure it runs under a suitable account */
      if (rqptr->rqPathSet.ScriptAgentAsPtr)
      {
         ScriptAsPtr = rqptr->rqPathSet.ScriptAgentAsPtr;
         MappedScriptAs = true;
      }
      if (WATCHING (rqptr, WATCH_DCL))
         WatchThis (WATCHITM(rqptr), WATCH_DCL, "AGENT as !AZ", ScriptAsPtr);
   }
   else
   if (rqptr->rqAuth.VmsUserScriptAs)
   {
      /* authorization rule has precedence over mapping rule */
      if (rqptr->RemoteUser[0] &&
          rqptr->rqAuth.SysUafAuthenticated)
      {
         ScriptAsPtr = rqptr->RemoteUser;
         BasePriority = ProcessPriority - DclDetachProcessPriorityUser;
         MappedScriptAs = true;
      }
      else
      {
         rqptr->rqResponse.HttpStatus = 403;
         ErrorGeneral (rqptr, MsgFor(rqptr,MSG_AUTH_REQUIRED), FI_LI);
         SysDclAst (NextTaskFunction, rqptr);
         return;
      }
   }
   else
   if (rqptr->rqPathSet.ScriptAsPtr)
   {
      if (rqptr->rqPathSet.ScriptAsPtr[0] == '~')
      {
         /* from a user rule mapping */
         ScriptAsPtr = rqptr->rqPathSet.ScriptAsPtr+1;
         BasePriority = ProcessPriority - DclDetachProcessPriorityUser;
         MappedScriptAs = true;
      }
      else
      if (SAME2(rqptr->rqPathSet.ScriptAsPtr,'$?'))
      {
         /* optionally use SYSUAF authenticated username */
         if (rqptr->RemoteUser[0] &&
             rqptr->rqAuth.SysUafAuthenticated)
         {
            ScriptAsPtr = rqptr->RemoteUser;
            BasePriority = ProcessPriority - DclDetachProcessPriorityUser;
            MappedScriptAs = true;
         }
      }
      else
      if (rqptr->rqPathSet.ScriptAsPtr[0] == '$')
      {
         /* must use a SYSUAF authenticated username */
         if (rqptr->RemoteUser[0] &&
             rqptr->rqAuth.SysUafAuthenticated)
         {
            ScriptAsPtr = rqptr->RemoteUser;
            BasePriority = ProcessPriority - DclDetachProcessPriorityUser;
            MappedScriptAs = true;
         }
         else
         {
            rqptr->rqResponse.HttpStatus = 403;
            ErrorGeneral (rqptr, MsgFor(rqptr,MSG_AUTH_REQUIRED), FI_LI);
            SysDclAst (NextTaskFunction, rqptr);
            return;
         }
      }
      else
      {
         /* an explicitly specified username */
         ScriptAsPtr = rqptr->rqPathSet.ScriptAsPtr;
         MappedScriptAs = true;
      }
   }

   if (BasePriority < 0) BasePriority = 0;

   if (ScriptRunTime &&
       ScriptRunTime[0] &&
       ScriptRunTime[0] != '!')
      TaskType = DCL_TASK_TYPE_RTE_SCRIPT;
   else
   if (CgiPlusScriptFileName && CgiPlusScriptFileName[0])
      TaskType = DCL_TASK_TYPE_CGIPLUS_SCRIPT;
   else
   if (CgiScriptFileName && CgiScriptFileName[0])
      TaskType = DCL_TASK_TYPE_CGI_SCRIPT;
   else
   if (DclCommand && DclCommand[0])
      TaskType = DCL_TASK_TYPE_CLI;
   else
      ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);

   if (WATCHING (rqptr, WATCH_RESPONSE))
   {
      switch (TaskType)
      {
         case DCL_TASK_TYPE_CGI_SCRIPT :
            WatchThis (WATCHITM(rqptr), WATCH_RESPONSE,
                       "SCRIPT!&@ CGI !AZ !AZ (!AZ)",
                       ScriptAsPtr[0] ? " as !AZ" : "!+", ScriptAsPtr,
                       ScriptName, CgiScriptFileName,
                       ScriptRunTime ? ScriptRunTime+1 : "");
            break;
         case DCL_TASK_TYPE_CGIPLUS_SCRIPT :
            WatchThis (WATCHITM(rqptr), WATCH_RESPONSE,
                       "SCRIPT!&@ CGIplus !AZ !AZ (!AZ)",
                       ScriptAsPtr[0] ? " as !AZ" : "!+", ScriptAsPtr,
                       ScriptName, CgiPlusScriptFileName,
                       ScriptRunTime ? ScriptRunTime+1 : "");
            break;
         case DCL_TASK_TYPE_RTE_SCRIPT :
            WatchThis (WATCHITM(rqptr), WATCH_RESPONSE,
                       "SCRIPT!&@ RTE !AZ !AZ (!AZ)",
                       ScriptAsPtr[0] ? " as !AZ" : "!+", ScriptAsPtr,
                       ScriptName, CgiScriptFileName, ScriptRunTime);
            break;
         case DCL_TASK_TYPE_CLI :
            WatchThis (WATCHITM(rqptr), WATCH_RESPONSE,
                       "CLI!&@ !AZ", 
                       ScriptAsPtr[0] ? " as !AZ" : "!+", ScriptAsPtr,
                       DclCommand);
            break;
         default :
               ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
      }
   }

   if (MappedScriptAs &&
       !DclPersonaServicesAvailable &&
       /* these latter two allow Server Admin process reports */
       ScriptAsPtr != HttpdScriptAsUserName &&
       ScriptAsPtr != HttpdProcess.UserName)
   {
      rqptr->rqResponse.HttpStatus = 403;
      ErrorGeneral (rqptr, MsgFor(rqptr,MSG_GENERAL_DISABLED), FI_LI);
      SysDclAst (NextTaskFunction, rqptr);
      return;
   }

   status = DclAllocateTask (rqptr, TaskType,
                             ScriptAsPtr, BasePriority,
                             ScriptName, CgiPlusScriptFileName,
                             ScriptRunTime);
   if (VMSnok (status))
   {
      SysDclAst (NextTaskFunction, rqptr);
      return;
   }

   /* get a local pointer to the newly allocated DCL task structure */
   tkptr = rqptr->DclTaskPtr;

   tkptr->NextTaskFunction = NextTaskFunction;
   tkptr->LastUsedTime64 = rqptr->rqTime.BeginTime64;
   tkptr->LastUsedSecond = HttpdTickSecond;
   tkptr->ProctorPtr = rqptr->ProctorPtr;
   tkptr->WatchItem = rqptr->WatchItem;

   /* as if on-stack because of the reuse of the task structure */
   OdsStructInit (&tkptr->SearchOds, true);

   if (tkptr->ProctorPtr)
   {
      /* must be stable for this many timer ticks (or reset by real request) */
      tkptr->ProctorProcess = 5;
      /* add PRN seconds so group of unused proctored expiries don't cluster */
      if (DclUseZombies &&
          (Config.cfScript.ZombieLifeTime ||
           (rqptr->rqPathSet.ScriptLifeTime &&
            rqptr->rqPathSet.ScriptLifeTime != -1)))
         tkptr->LifeTimeSecond += tkptr->ScriptProcessPid % 15 * 5;
   }

   if (!rqptr->AgentRequestPtr)
   {
      if (rqptr->WebSocketRequest)
      {
         InstanceGblSecIncrLong (&AccountingPtr->DclWebSocketCount);
         if (rqptr->RawSocketRequest)
            InstanceGblSecIncrLong (&AccountingPtr->DclWebSocketRawCount);
      }
   }

   switch (tkptr->TaskType)
   {
      case DCL_TASK_TYPE_CGI_SCRIPT :

         if (CalloutFunction)
            tkptr->CalloutFunction = CalloutFunction;
         else
            tkptr->CalloutFunction = &DclCalloutDefault;

         strcpy (tkptr->ScriptName, ScriptName);
         strcpy (tkptr->ScriptFileName, CgiScriptFileName);
         if (ScriptRunTime)
         {
            strcpy (tkptr->ScriptRunTime, ScriptRunTime);
            tkptr->ScriptRunTimePtr = tkptr->ScriptRunTime;
         }

         /* reset CGI output processing */
         CgiOutput (rqptr, NULL, 0);

         if (!rqptr->AccountingDone++)
            InstanceGblSecIncrLong (&AccountingPtr->DoScriptCount);

         break;

      case DCL_TASK_TYPE_CGIPLUS_SCRIPT :

         if (CalloutFunction)
            tkptr->CalloutFunction = CalloutFunction;
         else
            tkptr->CalloutFunction = &DclCalloutDefault;

         /* reset CGI output processing */
         CgiOutput (rqptr, NULL, 0);

         if (!tkptr->ScriptName[0])
         {
            /* no need to reset these for established CGIplus scripts! */
            strcpy (tkptr->ScriptName, ScriptName);
            strcpy (tkptr->ScriptFileName, CgiPlusScriptFileName);
            if (ScriptRunTime)
            {
               strcpy (tkptr->ScriptRunTime, ScriptRunTime);
               tkptr->ScriptRunTimePtr = tkptr->ScriptRunTime;
            }
         }

         if (!rqptr->AccountingDone++)
         {
            InstanceGblSecIncrLong (&AccountingPtr->DoCgiPlusScriptCount);
            if (tkptr->CgiPlusUsageCount > 1)
               InstanceGblSecIncrLong (&AccountingPtr->DclCgiPlusReusedCount);
         }

         break;

      case DCL_TASK_TYPE_RTE_SCRIPT :

         if (CalloutFunction)
            tkptr->CalloutFunction = CalloutFunction;
         else
            tkptr->CalloutFunction = &DclCalloutDefault;

         /* reset CGI output processing */
         CgiOutput (rqptr, NULL, 0);

         strcpy (tkptr->ScriptName, ScriptName);
         strcpy (tkptr->ScriptFileName, CgiScriptFileName);
         /* RTEs must have a run-time otherwise they're not RTEs */
         strcpy (tkptr->ScriptRunTime, ScriptRunTime);
         tkptr->ScriptRunTimePtr = tkptr->ScriptRunTime;
         memcpy (&tkptr->Md5HashPath,
                 &rqptr->Md5HashPath,
                 sizeof(tkptr->Md5HashPath));

         if (!rqptr->AccountingDone++)
         {
            InstanceGblSecIncrLong (&AccountingPtr->DoRteScriptCount);
            if (tkptr->CgiPlusUsageCount > 1)
               InstanceGblSecIncrLong (&AccountingPtr->DclRteReusedCount);
         }

         break;

      case DCL_TASK_TYPE_CLI :

         tkptr->CalloutFunction = NULL;
         len = strzcpy (tkptr->DclCommandPtr, DclCommand,
                        tkptr->DclCommandSize);
         if (len > tkptr->DclCommandSize)
         {
            len = tkptr->DclCommandLength = strlen(DclCommand);
            len = ((len / DCL_COMMAND_MIN_SIZE) + 1) * DCL_COMMAND_MIN_SIZE;
            if (len > DCL_COMMAND_MAX_SIZE)
            {
               tkptr->DclCommandLength = 0;
               rqptr->rqResponse.HttpStatus = 500;
               ErrorGeneralOverflow (rqptr, FI_LI);
               SysDclAst (NextTaskFunction, rqptr);
               return;
            }
            VmFree (tkptr->DclCommandPtr, FI_LI);
            tkptr->DclCommandPtr = VmGet (len);
            tkptr->DclCommandSize = len;
            strcpy (tkptr->DclCommandPtr, DclCommand);
         }

         /* reset CGI output processing */
         CgiOutput (rqptr, NULL, 0);

         /*
            As CLI commands are always used during some other request
            processing count them independent of any other AccountingPtr->
            Exclude proctored processes from this count.
         */
         if (!MATCH4(tkptr->DclCommandPtr, "!!*!"))
            InstanceGblSecIncrLong (&AccountingPtr->DoDclCommandCount);

         break;

      default :
            ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
   }

   if (tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT &&
       (rqptr->rqPathSet.ScriptNoFind ||
        tkptr->NextTaskFunction == &DclScriptProctorAst))
   {
      /* the RTE will handle all script locating, error reporting, etc. */
      rqptr->rqCgi.ScriptFileNamePtr = tkptr->ScriptFileName;
      strcpy (tkptr->SearchOds.ResFileName, tkptr->ScriptFileName);
   }
   else
   if (tkptr->TaskType != DCL_TASK_TYPE_CLI)
   {
      /* look for a script file */
      if (tkptr->SearchOds.ResFileName[0])
      {
         rqptr->rqCgi.ScriptFileNamePtr = tkptr->ScriptFileName;
         strcpy (tkptr->SearchOds.ResFileName, tkptr->ScriptFileName);
      }
      else
      {
         if (DclUseZombies) DclSearchScriptNameCache (tkptr, rqptr);

         /* if not found in the name cache then look in the file system! */
         if (!(tkptr->SearchOds.ResFileName[0] &&
               tkptr->ScriptRunTimePtr))
         {
            /* script is being requested, first look for the script file */
            tkptr->FindScriptState = DCL_FIND_SCRIPT_BEGIN;
            DclFindScript (tkptr);
            return;
         }
      }
   }
  
   /* must be an established CGIplus script or DCL command (from SSI module) */
   DclBeginScript (tkptr);
}

/*****************************************************************************/
/*
Allocate a DCL task structure to the request. All task structures are linked
together in a single list, function and state indicated by the various flags
and counters associated with each.

If a CGIplus task script is to be executed then check for an already
established, idle CGIplus task structure executing that particular script. If
none found, or CGIplus script not required, and zombies in use
(persistent-script processes) then look through the list for an idle zombie
script process. If no zombie available (or not enabled) then check if we have
reached the script process creation hard-limit. If not reached look through the
list for an existing but no-script process-executing DCL task structure. If
none found create an additional DCL task structure and add it to the list.

Initialize the task structure (no matter from which scan it originated) and if
necessary create a script process for it. (An obvious improvement to processing
would be to have multiple lists, but that will have to wait for another time
:^) If an error is encountered an error message is generated and the error
status returned. It is up to the calling routine to abort the processing.
*/

int DclAllocateTask
(
REQUEST_STRUCT *rqptr,
int TaskType,
char *ScriptAsPtr,
int BasePriority,
char *ScriptName,
char *CgiPlusScriptFileName,
char *ScriptRunTime
)
{
   BOOL  WatchThisOne;
   int  status,
        CgiPlusScriptFileNameLength;
   int  LruSecond [2];
   char  *cptr;
   DCL_TASK  *tkptr;
   DCL_TASK  *lrutkptr [2];
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL,
                 "DclAllocateTask() !UL !&Z !&Z !&Z !&Z",
                 TaskType, ScriptName, CgiPlusScriptFileName,
                 ScriptRunTime, ScriptAsPtr);

   tkptr = NULL;

   if (WATCHING (rqptr, WATCH_DCL))
      WatchThisOne = true;
   else
      WatchThisOne = false;

   if (!rqptr->ProctorPtr)
   {
      if (TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT)
      {
         /******************************************************/
         /* look for an unused instance of this CGIplus script */
         /******************************************************/

         for (cptr = CgiPlusScriptFileName; *cptr; cptr++);
         CgiPlusScriptFileNameLength = cptr - CgiPlusScriptFileName;
         /* does it have a trailing file type? */
         while (cptr > CgiPlusScriptFileName && *cptr != ']' && *cptr != '.')
            cptr--;
         if (*cptr == ']') cptr = "."; else cptr = "";
         for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
         {
            tkptr = (DCL_TASK*)leptr;

            if (tkptr->TaskType != TaskType)
            {
               tkptr = NULL;
               continue;
            }

            if (WatchThisOne)
            {
               if (strsame (ScriptName, tkptr->ScriptName, -1) &&
                   !strsame (CgiPlusScriptFileName,
                             tkptr->ScriptFileName,
                             CgiPlusScriptFileNameLength))
                  WatchThis (WATCHITM(rqptr), WATCH_DCL,
                             "DEVICE-LOGICAL-NAME-ISSUE? !AZ !AZ",
                             CgiPlusScriptFileName, tkptr->ScriptFileName);
            }

            if (!tkptr->ScriptProcessPid ||
                tkptr->QueuedSysCommand > tkptr->QueuedSysCommandAllowed ||
                tkptr->QueuedSysOutput ||
                tkptr->QueuedClientOutput ||
                tkptr->QueuedCgiPlusIn ||
                tkptr->QueuedHttpInput ||
                tkptr->QueuedClientRead ||
                tkptr->RequestPtr ||
                tkptr->FindScript ||
                tkptr->DeleteProcess ||
                !strsame (ScriptName, tkptr->ScriptName, -1) ||
                !strsame (CgiPlusScriptFileName,
                          tkptr->ScriptFileName,
                          CgiPlusScriptFileNameLength) ||
                tkptr->ScriptFileName[CgiPlusScriptFileNameLength] != *cptr ||
                (DclScriptDetachProcess &&
                 !strsame (ScriptAsPtr, tkptr->CrePrcUserName, -1)))
            {
               tkptr = NULL;
               continue;
            }

            break;
         }

         if (tkptr && WatchThisOne)
            WatchThis (WATCHITM(rqptr), WATCH_DCL,
                       "CGIPLUS idle pid:!8XL!&@", tkptr->ScriptProcessPid,
                       tkptr->CrePrcUserName[0] ? " of !AZ" : "!+",
                       tkptr->CrePrcUserName);
      }

      if (TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
      {
         /************************************************/
         /* look for an unused instance of this run-time */
         /************************************************/

         /* initialize least-recently-used storage */
         lrutkptr[0] = lrutkptr[1] = NULL;
         LruSecond[0] = LruSecond[1] = 0;

         for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
         {
            tkptr = (DCL_TASK*)leptr;

            if (!tkptr->ScriptProcessPid ||
                tkptr->TaskType != TaskType ||
                tkptr->QueuedSysCommand > tkptr->QueuedSysCommandAllowed ||
                tkptr->QueuedSysOutput ||
                tkptr->QueuedClientOutput ||
                tkptr->QueuedCgiPlusIn ||
                tkptr->QueuedHttpInput ||
                tkptr->QueuedClientRead ||
                tkptr->RequestPtr ||
                tkptr->FindScript ||
                tkptr->DeleteProcess ||
                !strsame (ScriptRunTime, tkptr->ScriptRunTime, -1) ||
                (DclScriptDetachProcess &&
                 !strsame (ScriptAsPtr, tkptr->CrePrcUserName, -1)))
            {
               tkptr = NULL;
               continue;
            }

            if (WATCHMOD (rqptr, WATCH_MOD_DCL))
               WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL,
"RTE !&Z !&Z !&B !16&H !16&H !&B !SL !SL !&B !SL !&B !&X !&X !&X",
                          ScriptName, tkptr->ScriptName,
                          strsame (ScriptName, tkptr->ScriptName, -1),
                          &tkptr->Md5HashPath, &rqptr->Md5HashPath,
                          !MATCH0 (&tkptr->Md5HashPath,
                                   &rqptr->Md5HashPath,
                                   sizeof(rqptr->Md5HashPath)),
                          tkptr->LastUsedSecond, LruSecond[0],
                          tkptr->LastUsedSecond < LruSecond[0],
                          tkptr->LastUsedSecond, LruSecond[1],
                          tkptr->LastUsedSecond < LruSecond[1],
                          tkptr, lrutkptr[0], lrutkptr[1] /* whew! */);

            if (!strsame (ScriptName, tkptr->ScriptName, -1))
            {
               /* not the same script being executed by the RTE */
               if (tkptr->LastUsedSecond < LruSecond[0] || !LruSecond[0])
               {
                  LruSecond[0] = tkptr->LastUsedSecond;
                  lrutkptr[0] = tkptr;
               }
               tkptr = NULL;
               continue;
            }
            if (!MATCH0 (&tkptr->Md5HashPath,
                         &rqptr->Md5HashPath,
                         sizeof(rqptr->Md5HashPath)))
            {
               /* not the same path being supplied to the script */
               if (tkptr->LastUsedSecond < LruSecond[1] || !LruSecond[1])
               {
                  LruSecond[1] = tkptr->LastUsedSecond;
                  lrutkptr[1] = tkptr;
               }
               tkptr = NULL;
               continue;
            }

            break;
         }

         if (WATCHMOD (rqptr, WATCH_MOD_DCL))
            WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL, "!&X !SL !&X !SL !&X",
                       tkptr, LruSecond[0], lrutkptr[0],
                              LruSecond[1], lrutkptr[1]);

         if (!tkptr)
         {
            /* none was found having the same script and path */
            if (lrutkptr[1])
               /* use the one with the same script in preference to ... */
               tkptr = lrutkptr[1];
            else
            if (lrutkptr[0])
               /* the one just executing the same RTE */
               tkptr = lrutkptr[0];
         }

         if (tkptr)
         {
            if (WatchThisOne)
               WatchThis (WATCHITM(rqptr), WATCH_DCL,
                          "RTE idle pid:!8XL!&@(!AZ)", tkptr->ScriptProcessPid,
                          tkptr->CrePrcUserName[0] ? " of !AZ " : "!+",
                          tkptr->CrePrcUserName, tkptr->ScriptName);

            /* ensure the previous script information is not carried over */
            tkptr->ScriptName[0] =
               tkptr->ScriptFileName[0] =
               tkptr->SearchOds.ResFileName[0] = '\0';
            memset (&tkptr->Md5HashPath, 0, sizeof(tkptr->Md5HashPath));
         }
      }

      if (!tkptr && DclUseZombies)
      {
         /************************/
         /* look for idle zombie */
         /************************/

         for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
         {
            tkptr = (DCL_TASK*)leptr;

            if (!tkptr->ScriptProcessPid ||
                tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
                tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT ||
                tkptr->QueuedSysCommand ||
                tkptr->QueuedSysOutput ||
                tkptr->QueuedClientOutput ||
                tkptr->QueuedCgiPlusIn ||
                tkptr->QueuedHttpInput ||
                tkptr->QueuedClientRead ||
                tkptr->FindScript ||
                tkptr->DeleteProcess ||
                tkptr->RequestPtr ||
                (DclScriptDetachProcess &&
                 !strsame (ScriptAsPtr, tkptr->CrePrcUserName, -1)))
            {
               tkptr = NULL;
               continue;
            }

            tkptr->BuildRecords =
               tkptr->CgiPlusVarStruct = false;
            tkptr->DclCommandLength =
               tkptr->CgiPlusUsageCount =
               tkptr->LifeTimeSecond =
               tkptr->SysOutputBuildCount = 0;
            tkptr->DclCommandPtr[0] =
               tkptr->ScriptRunTime[0] =
               tkptr->ScriptName[0] =
               tkptr->ScriptFileName[0] =
               tkptr->SearchOds.ResFileName[0] = '\0';
            tkptr->ScriptRunTimePtr = NULL;
            memset (&tkptr->Md5HashPath, 0, sizeof(tkptr->Md5HashPath));

            break;
         }

         if (tkptr && WatchThisOne)
            WatchThis (WATCHITM(rqptr), WATCH_DCL,
                       "ZOMBIE idle pid:!8XL!&@", tkptr->ScriptProcessPid,
                       tkptr->CrePrcUserName[0] ? " of !AZ" : "!+",
                       tkptr->CrePrcUserName);
      }
   }

   if (!tkptr && DclCurrentScriptProcess >= DclScriptProcessHardLimit)
   {
      if (WatchThisOne)
         WatchThis (WATCHITM(rqptr), WATCH_DCL,
                    "SCRIPT-PROCESS hard-limit !UL", DclCurrentScriptProcess);

      /* let's see if we can do something about it! */
      DclScriptProcessPurge ();

      DclHitHardLimitCount++;
      InstanceGblSecIncrLong (&AccountingPtr->DclHitHardLimitCount);
      rqptr->rqResponse.HttpStatus = 503;
      ErrorGeneral (rqptr, MsgFor(rqptr,MSG_SCRIPT_HARD_LIMIT), FI_LI);
      return (STS$K_ERROR);
   }

   if (!tkptr)
   {
      /********************************/
      /* look for free task structure */
      /********************************/

      for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
      {
         tkptr = (DCL_TASK*)leptr;

         if (tkptr->ScriptProcessPid ||
             tkptr->QueuedSysCommand ||
             tkptr->QueuedSysOutput ||
             tkptr->QueuedClientOutput ||
             tkptr->QueuedCgiPlusIn ||
             tkptr->QueuedHttpInput ||
             tkptr->QueuedClientRead ||
             tkptr->FindScript ||
             tkptr->DeleteProcess ||
             tkptr->RequestPtr)
         {
            tkptr = NULL;
            continue;
         }

         tkptr->BuildRecords =
            tkptr->CgiPlusVarStruct = false;
         tkptr->DclCommandLength =
            tkptr->CgiPlusUsageCount =
            tkptr->LifeTimeSecond =
            tkptr->SysOutputBuildCount = 0;
         tkptr->CrePrcUserName[0] =
            tkptr->DclCommandPtr[0] =
            tkptr->ScriptRunTime[0] =
            tkptr->ScriptName[0] =
            tkptr->ScriptFileName[0] =
            tkptr->SearchOds.ResFileName[0] = '\0';
         tkptr->ScriptRunTimePtr = NULL;
         memset (&tkptr->Md5HashPath, 0, sizeof(tkptr->Md5HashPath));
         memset (&tkptr->PrcNamActive, 0, sizeof(tkptr->PrcNamActive));
         memset (&tkptr->PrcNamDefault, 0, sizeof(tkptr->PrcNamDefault));
         tkptr->ProcessNamePid = 0;
         break;
      }
   }

   if (!tkptr)
   {
      /* if we're getting short of script processes then start purging */
      if (DclCurrentScriptProcess >= DclScriptProcessSoftLimit)
      {
         if (WatchThisOne)
            WatchThis (WATCHITM(rqptr), WATCH_DCL,
                       "SCRIPT-PROCESS soft-limit purge !UL",
                       DclCurrentScriptProcess);

         DclScriptProcessPurge ();
      }
   }

   if (!tkptr)
   {
      /*********************/
      /* create a new task */
      /*********************/

      tkptr = VmGet (sizeof(DCL_TASK));

      /* allocate an ambit minimum size DCL command buffer */
      tkptr->DclCommandPtr = VmGet (DCL_COMMAND_MIN_SIZE);
      tkptr->DclCommandSize = DCL_COMMAND_MIN_SIZE;
      tkptr->DclCommandLength = 0;
      
      /*
         Allocate memory in the DCL task for SYS$OUTPUT buffer.
         Allow two bytes for carriage control and terminating null.
      */
      tkptr->SysOutputPtr = VmGet (DclSysOutputSize+3);
      tkptr->SysOutputSize = DclSysOutputSize;

      if (VMSnok (status = DclCreateMailboxes (tkptr)))
      {
         VmFree (tkptr->SysOutputPtr, FI_LI);
         VmFree (tkptr, FI_LI);
         rqptr->rqResponse.ErrorTextPtr = MsgFor(rqptr,MSG_SCRIPT_IPC);
         ErrorVmsStatus (rqptr, status, FI_LI);
         return (status);
      }

      ListAddTail (&DclTaskList, tkptr, LIST_ENTRY_TYPE_DCL);
   }

   /*******************/
   /* initialize task */
   /*******************/

   /* associate the DCL task and the request */
   rqptr->DclTaskPtr = tkptr;
   tkptr->RequestPtr = rqptr;          

   tkptr->TaskType = TaskType;
   tkptr->TotalUsageCount++;
   tkptr->ForceImageExit = true;
   tkptr->DeleteProcess =
      tkptr->WatchNonCgiCompliant = false;

   tkptr->ClientWriteErrorCount =
      tkptr->ForceImageExitSecond =
      tkptr->ProctorProcess =
      tkptr->ScriptCpuTimMax =
      tkptr->SysOutputEndOfFileCount =
      tkptr->TaskRunDown = 0;

   tkptr->ProctorPtr = NULL;
   if (rqptr->rqPathSet.ScriptBitBucketTimeout)
      tkptr->BitBucketTimeout = rqptr->rqPathSet.ScriptBitBucketTimeout;
   else
      tkptr->BitBucketTimeout = Config.cfScript.BitBucketTimeout;
   tkptr->ScriptCpuMax = rqptr->rqPathSet.ScriptCpuMax;

   switch (TaskType)
   {
      case DCL_TASK_TYPE_CGI_SCRIPT :

         rqptr->rqCgi.IsCliDcl =
            tkptr->BuildRecords =
            tkptr->CgiPlusVarStruct =
            tkptr->ScriptProcessActivated =
            tkptr->ScriptProcessResponded = false;
         tkptr->CgiPlusUsageCount =
            tkptr->CgiBelLength =
            tkptr->CgiEofLength =
            tkptr->CgiEotLength =
            tkptr->CgiEscLength =
            tkptr->LifeTimeSecond =
            tkptr->SysOutputBuildCount = 0;
         tkptr->CgiBel[0] =
            tkptr->CgiEof[0] =
            tkptr->CgiEot[0] =
            tkptr->CgiEsc[0] = '\0';

         /* limited life in the twilight zone */
         if (DclUseZombies &&
             (Config.cfScript.ZombieLifeTime ||
              (rqptr->rqPathSet.ScriptLifeTime &&
               rqptr->rqPathSet.ScriptLifeTime != -1)))
         {
            DclSupervisor (0);
            if (rqptr->rqPathSet.ScriptLifeTime)
               tkptr->LifeTimeSecond = HttpdTickSecond +
                                       rqptr->rqPathSet.ScriptLifeTime;
            else
               tkptr->LifeTimeSecond = HttpdTickSecond +
                                       Config.cfScript.ZombieLifeTime;
         }

         /* always generate new strings for standard CGI scripts */
         CgiSequenceBel (tkptr->CgiBel, &tkptr->CgiBelLength);
         CgiSequenceEof (tkptr->CgiEof, &tkptr->CgiEofLength);
         CgiSequenceEot (tkptr->CgiEot, &tkptr->CgiEotLength);
         CgiSequenceEsc (tkptr->CgiEsc, &tkptr->CgiEscLength);

         /* note: CgiBel is for DCL module internal use only */
         strcpy (rqptr->rqCgi.EofStr, tkptr->CgiEof);
         rqptr->rqCgi.EofLength = tkptr->CgiEofLength;
         strcpy (rqptr->rqCgi.EotStr, tkptr->CgiEot);
         rqptr->rqCgi.EotLength = tkptr->CgiEotLength;
         strcpy (rqptr->rqCgi.EscStr, tkptr->CgiEsc);
         rqptr->rqCgi.EscLength = tkptr->CgiEscLength;

         break;

      case DCL_TASK_TYPE_CGIPLUS_SCRIPT :
      case DCL_TASK_TYPE_RTE_SCRIPT :

         rqptr->rqCgi.IsCliDcl =
            tkptr->ScriptProcessActivated =
            tkptr->ScriptProcessResponded = false;
         tkptr->CgiPlusUsageCount++;
         tkptr->ZombieCount = 0;

         /* give it three-score years and ten if life-time is specified */
         if (Config.cfScript.CgiPlusLifeTime ||
             (rqptr->rqPathSet.ScriptLifeTime &&
              rqptr->rqPathSet.ScriptLifeTime != -1))
         {
            /* if set do-not-disturb carries across CGIplus requests */
            if (tkptr->LifeTimeSecond != DCL_DO_NOT_DISTURB)
            {
               DclSupervisor (0);
               if (rqptr->rqPathSet.ScriptLifeTime)
                  tkptr->LifeTimeSecond = HttpdTickSecond +
                                          rqptr->rqPathSet.ScriptLifeTime;
               else
                  tkptr->LifeTimeSecond = HttpdTickSecond +
                                          Config.cfScript.CgiPlusLifeTime;
            }
         }
         else
         if (tkptr->LifeTimeSecond != DCL_DO_NOT_DISTURB)
         {
            DclSupervisor (0);
            tkptr->LifeTimeSecond = HttpdTickSecond + DCL_CGIPLUS_LIFETIME;
         }

         /* CGIplus MUST retain original EOF/EOT/ESC until process dies */
         if (!tkptr->CgiBelLength)
            CgiSequenceBel (tkptr->CgiBel, &tkptr->CgiBelLength);
         if (!tkptr->CgiEofLength)
            CgiSequenceEof (tkptr->CgiEof, &tkptr->CgiEofLength);
         if (!tkptr->CgiEotLength)
            CgiSequenceEot (tkptr->CgiEot, &tkptr->CgiEotLength);
         if (!tkptr->CgiEscLength)
            CgiSequenceEsc (tkptr->CgiEsc, &tkptr->CgiEscLength);

         /* note: CgiBel is for DCL module internal use only */
         strcpy (rqptr->rqCgi.EofStr, tkptr->CgiEof);
         rqptr->rqCgi.EofLength = tkptr->CgiEofLength;
         strcpy (rqptr->rqCgi.EotStr, tkptr->CgiEot);
         rqptr->rqCgi.EotLength = tkptr->CgiEotLength;
         strcpy (rqptr->rqCgi.EscStr, tkptr->CgiEsc);
         rqptr->rqCgi.EscLength = tkptr->CgiEscLength;

         break;

      case DCL_TASK_TYPE_CLI :

         rqptr->rqCgi.IsCliDcl = true;
         tkptr->BuildRecords =
            tkptr->CgiPlusVarStruct = false;
         tkptr->CgiPlusUsageCount =
            tkptr->CgiEofLength =
            tkptr->CgiEotLength =
            tkptr->CgiEscLength =
            tkptr->LifeTimeSecond =
            tkptr->SysOutputBuildCount = 0;
         tkptr->CgiEof[0] =
            tkptr->CgiEot[0] =
            tkptr->CgiEsc[0] = '\0';
         CgiSequenceBel (tkptr->CgiBel, &tkptr->CgiBelLength);

         /* limited life in the twilight zone */
         if (DclUseZombies &&
             (Config.cfScript.ZombieLifeTime ||
              (rqptr->rqPathSet.ScriptLifeTime &&
               rqptr->rqPathSet.ScriptLifeTime != -1)))
         {
            DclSupervisor (0);
            if (rqptr->rqPathSet.ScriptLifeTime)
               tkptr->LifeTimeSecond = HttpdTickSecond +
                                       rqptr->rqPathSet.ScriptLifeTime;
            else
               tkptr->LifeTimeSecond = HttpdTickSecond +
                                       Config.cfScript.ZombieLifeTime;
         }

         if (DclUseZombies)
         {
            /* always generate a new EOF string for DCL commands */
            CgiSequenceEof (tkptr->CgiEof, &tkptr->CgiEofLength);
            strcpy (rqptr->rqCgi.EofStr, tkptr->CgiEof);
            rqptr->rqCgi.EofLength = tkptr->CgiEofLength;
         }

         break;

      default :
            ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
   }

   if (Watch.Category && WatchThisOne)
   {
      WatchThis (WATCHITM(rqptr), WATCH_DCL, "MBX SYS$COMMAND !AZ size:!UL",
                 tkptr->SysCommandDevName, DclSysCommandSize);
      WatchThis (WATCHITM(rqptr), WATCH_DCL, "MBX SYS$OUTPUT !AZ size:!UL",
                 tkptr->SysOutputDevName, DclSysOutputSize);
      WatchThis (WATCHITM(rqptr), WATCH_DCL, "MBX CGIPLUSIN !AZ size:!UL",
                 tkptr->CgiPlusInDevName, DclCgiPlusInSize);
      WatchThis (WATCHITM(rqptr), WATCH_DCL, "MBX HTTP$INPUT !AZ size:!UL",
                 tkptr->HttpInputDevName, NetReadBufferSize);
      WatchThis (WATCHITM(rqptr), WATCH_DCL, "MBX termination !AZ",
                 tkptr->CrePrcTermMbxDevName);
   }

   if (tkptr->ScriptProcessPid)
   {
      /******************/
      /* process exists */
      /******************/

      /* kick off the first of the CPU consumption watchdogs */
      if (tkptr->ScriptCpuMax) DclScriptCpuTim (tkptr);

      /* if existing (CGI) process being pressed into CGIplus or RTE service */
      if (TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
          TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
         DclCountScriptProcess ();

      return (SS$_NORMAL);
   }

   /******************/
   /* create process */
   /******************/

   status = DclCreateScriptProcess (tkptr, ScriptAsPtr, BasePriority);
   if (VMSok (status))
   {
      tkptr->ZombieCount = 0;
      DclCurrentScriptProcess++;

      DclCountScriptProcess ();

      /* in this case we know the CPU consumption is starting at zero ;^) */
      if (tkptr->ScriptCpuMax)
         /* multiply by one hundred turning seconds into 10mS ticks */
         tkptr->ScriptCpuTimMax = tkptr->ScriptCpuMax * 100;

      return (status);
   }
   else
   {
      /* disassociate the DCL task and request structures */
      rqptr->DclTaskPtr = tkptr->RequestPtr = NULL;
      tkptr->WatchItem = 0;
      return (status);
   }
}

/*****************************************************************************/
/*
Search the script name cache using a task structure to get information about
the script's environment.
*/ 

DclSearchScriptNameCache
(
DCL_TASK *tkptr,
REQUEST_STRUCT *rqptr
)
{
   DCL_SCRIPT_NAME_ENTRY  *captr;
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL,
                 "DclSearchScriptNameCache() !&Z !&Z",
                 tkptr->ScriptFileName, tkptr->ScriptRunTime);

   for (leptr = DclScriptNameCacheList.HeadPtr;
        leptr;
        leptr = leptr->NextPtr)
   {
      captr = (DCL_SCRIPT_NAME_ENTRY*)leptr;

      if (WATCHMOD (rqptr, WATCH_MOD_DCL))
         WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL, "!&Z !&Z !&B !&Z",
                    tkptr->ScriptFileName, captr->ScriptFileName,
                    strsame (tkptr->ScriptFileName, captr->ScriptFileName, -1),
                    captr->ResFileName);

      if (!captr->ResFileName[0]) continue;
      if (!strsame (tkptr->ScriptFileName, captr->ScriptFileName, -1)) continue;

      if (!rqptr->NotFromCache)
      {
         /* found it */
         if (WATCHING (rqptr, WATCH_DCL))
            WatchThis (WATCHITM(rqptr), WATCH_DCL,
                       "SCRIPT name cache !UL hit!%s !AZ as !AZ (!AZ)",
                       captr->HitCount+1, tkptr->ScriptFileName, 
                       captr->ResFileName, captr->ScriptRunTime);

         /* emulate what happens at DclScriptFindEnd() */
         strcpy (tkptr->ScriptFileName, captr->ResFileName);
         rqptr->rqCgi.ScriptFileNamePtr = tkptr->ScriptFileName;
         strcpy (tkptr->SearchOds.ResFileName, captr->ResFileName);
         if (captr->ScriptRunTime[0])
         {
            strcpy (tkptr->ScriptRunTime, captr->ScriptRunTime);
            tkptr->ScriptRunTimePtr = tkptr->ScriptRunTime;
         }
         else
         if (captr->ScriptRunTime[1])
         {
            /* ("bit too clever" but) redeploy this storage */
            strcpy (tkptr->ScriptRunTime+1, captr->ScriptRunTime+1);
            tkptr->ScriptRunTimePtr = tkptr->ScriptRunTime+1;
            tkptr->ScriptRunTime[0] = '\0';
         }
         else
         {
            tkptr->ScriptRunTime[0] = '\0';
            tkptr->ScriptRunTimePtr = NULL;
         }
         captr->HitCount++;
         captr->LastTime64 = rqptr->rqTime.BeginTime64;

         return;
      }

      /* "reload" is used to purge the script name cache entry */
      captr->ResFileName[0] = captr->ScriptRunTime[0] = '\0';
      tkptr->ScriptRunTimePtr = NULL;
      return;
   }

   if (WATCHING (rqptr, WATCH_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_DCL,
                 "SCRIPT name cache !AZ not found", tkptr->ScriptFileName); 
}

/*****************************************************************************/
/*
Add the name details of a script to the cache.  First check that no other
request has provided this same entry while this request was finding the script
details.  Then update an empty entry if it can be found in the list, or create
a new entry and add it to the list.
*/ 

DclUpdateScriptNameCache (DCL_TASK *tkptr)

{
   DCL_SCRIPT_NAME_ENTRY  *captr;
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclUpdateScriptNameCache() !&Z !&Z !&Z",
                 tkptr->ScriptFileName, tkptr->SearchOds.ResFileName,
                 tkptr->ScriptRunTime);

   /* check that no one has beaten us to it */
   for (leptr = DclScriptNameCacheList.HeadPtr;
        leptr;
        leptr = leptr->NextPtr)
   {
      captr = (DCL_SCRIPT_NAME_ENTRY*)leptr;
      if (strsame (tkptr->ScriptFileName, captr->ScriptFileName, -1) &&
          captr->ResFileName[0]) return;
   }

   /* now look for an empty entry */
   for (leptr = DclScriptNameCacheList.HeadPtr;
        leptr;
        leptr = leptr->NextPtr)
   {
      captr = (DCL_SCRIPT_NAME_ENTRY*)leptr;
      if (!captr->ResFileName[0]) break;
   }

   if (!leptr)
   {
      /* didn't find an instance of the script create a new entry */
      captr = VmGet (sizeof(DCL_SCRIPT_NAME_ENTRY));
      ListAddTail (&DclScriptNameCacheList, captr, LIST_ENTRY_TYPE_SCRIPT);
   }

   /* cache the script name information */
   strcpy (captr->ScriptFileName, tkptr->ScriptFileName);
   strcpy (captr->ResFileName, tkptr->SearchOds.ResFileName);
   if (tkptr->ScriptRunTime[0])
      strcpy (captr->ScriptRunTime, tkptr->ScriptRunTime);
   else
   if (tkptr->ScriptRunTimePtr)
   {
      strcpy (captr->ScriptRunTime+1, tkptr->ScriptRunTimePtr);
      captr->ScriptRunTime[0] = '\0';
   }
   else
      captr->ScriptRunTime[0] = captr->ScriptRunTime[1] = '\0';
   captr->HitCount = 0;
   captr->LastTime64 = tkptr->RequestPtr->rqTime.BeginTime64;

   if (WATCHITM(tkptr) && WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "SCRIPT name cache update !AZ as !AZ",
                 captr->ScriptFileName, captr->ResFileName);
}

/*****************************************************************************/
/*
Set all expanded file name entries in the script name cache to empty.  This
function is called when the DCLSupervisor() determines there are no more
zombies or CGIplus scripts active, and also when script processes are purged.
*/ 

DclPurgeScriptNameCache ()

{
   DCL_SCRIPT_NAME_ENTRY  *captr;
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclPurgeScriptNameCache()");

   DclPurgeScriptNameCacheCount++;

   for (leptr = DclScriptNameCacheList.HeadPtr;
        leptr;
        leptr = leptr->NextPtr)
   {
      captr = (DCL_SCRIPT_NAME_ENTRY*)leptr;
      captr->ResFileName[0] = captr->ScriptRunTime[0] = '\0';
      captr->HitCount = 0;
   }
}

/*****************************************************************************/
/*
Build a request-like structure (e.g. RequestAccept(), Http2RequestBegin2())
that DCL can use to run a script.  First call with /rqptr/ NULL sets up the
basic structure and the second call executes the specified script/command. 
Between the first and second calls additional request setup may be performed. 
Failure returns a NULL.
*/ 

REQUEST_STRUCT* DclFauxRequest
(
REQUEST_STRUCT *rqptr,
char *ScriptPath,
REQUEST_AST NextTaskFunction
)
{
   char  *cptr, *sptr, *zptr;
   char  DclCommand [256],
         MappedFile [ODS_MAX_FILE_NAME_LENGTH+1],
         MappedScript [ODS_MAX_FILE_NAME_LENGTH+1],
         MappedRunTime [ODS_MAX_FILE_NAME_LENGTH+1],
         ScriptName [ODS_MAX_FILE_NAME_LENGTH+1];

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclFauxRequest() !8XL", rqptr);

   if (!rqptr)
   {
      /**************/
      /* initialise */
      /**************/

      rqptr = VmGetRequest (-(++DclFauxRequestCount));
      sys$gettim (&rqptr->rqTime.BeginTime64);
      rqptr->rqDictPtr = DictCreate (rqptr, -1);
   }
   else
   {
      /***********/
      /* execute */
      /***********/

      if (!rqptr->ClientPtr)
         rqptr->ClientPtr = VmGetHeap (rqptr, sizeof(CLIENT_STRUCT));
      if (!rqptr->ServicePtr)
         rqptr->ServicePtr = VmGetHeap (rqptr, sizeof(SERVICE_META));

      rqptr->NetIoPtr = VmGetHeap (rqptr, sizeof(NETIO_STRUCT));
      rqptr->NetIoPtr->ClientPtr = rqptr->ClientPtr;
      rqptr->NetIoPtr->ServicePtr = rqptr->ServicePtr;

      /* prevent writing a response header to no network! */
      rqptr->rqResponse.HeaderSent = true;

      if (WATCH_CATEGORY(WATCH_DCL)) WatchSetWatch (rqptr, WATCH_NEW_ITEM);

      if (ScriptPath[0] == '$')
      { 
         /* DCL command */
         zptr = (sptr = DclCommand) + sizeof(DclCommand)-1;
         for (cptr = ScriptPath+1; *cptr && sptr < zptr; *sptr++ = *cptr++);
         *sptr = '\0';

         DclBegin (rqptr, NextTaskFunction, DclCommand,
                   NULL, NULL, NULL, NULL, NULL);
      }
      else
      {
         /* map the script */
         *(ULONGPTR)MappedFile = *(ULONGPTR)ScriptName =
            *(ULONGPTR)MappedScript = *(ULONGPTR)MappedRunTime = 0;

         cptr = MapUrl_Map (ScriptPath, 0, 
                            MappedFile, sizeof(MappedFile),
                            ScriptName, sizeof(ScriptName),
                            MappedScript, sizeof(MappedScript),
                            MappedRunTime, sizeof(MappedRunTime),
                            NULL, rqptr, &rqptr->rqPathSet);

         if (!cptr[0] && cptr[1])
         {
            /* mapping failure */
            if (WATCHING (rqptr, WATCH_DCL))
               WatchThis (WATCHITM(rqptr), WATCH_DCL, "!AZ", cptr+1);
            VmFreeRequest (rqptr, FI_LI);
            rqptr = NULL;
         }
         else
         if (ScriptName[0] == '+')
         {
            ScriptName[0] = '/';
            DclBegin (rqptr, NextTaskFunction, NULL,
                      ScriptName, NULL, MappedScript, MappedRunTime, NULL);
         }
         else
            DclBegin (rqptr, NextTaskFunction, NULL,
                      ScriptName, MappedScript, NULL, MappedRunTime, NULL);
      }
   }

   return (rqptr);
}

/*****************************************************************************/
/*
Implements the [DclScriptProctor] global directive.  Script proctoring
proactively creates and maintains specific persistent scripts and scripting
environments (RTEs).  It is intended for those environments that have some
significant startup latency.  It could be used with non-persistent scripts but
there isn't any point (the only thing that remains instatiated is a zombie
script process).

For each proctor specification it scans the DCL task list for matching
run-times and/or script paths, counting the number of matches.  If fewer than
the item requires then a dummy request structure is generated and the script
creation function directly called (analagous to what happens with a genuine
request).

It is possible (and probably likely) that proctored script specification will
fail to activate the script (activation specification error, script unavailable
for some reason, etc., etc., etc.) which would lead to a runaway series of
attempts to proctor with each process exit.  To help mitigate this scenario an
algorithm is applied in DclScriptProcessCompletionAST() which for repeated
failures no longer reproctors that particular item for a given period.  The
algorithm is weighted to quickly put the brakes on a failing item then more
slowly remove that weight over a period of time until it again begins to
proctor it again.  This is accomplished by starting with 3 and then multiplying
that value by itself for each failure.  Once it reaches 25 (3 * 3 := 9 * 9 :=
81, i.e. three failures) it no longer reproctors.  This value is then
decremented by the number of elapsed seconds until it falls below 25 (about a
minute) at which time the proctoring is attempted again.  If the value is
something like 24 then another failure results in a value of 576, or about
ten minutes before another attempt.  These are all reset to zero with a
/DO=DCL=PURGE or /DO=DCL=DELETE.

Proctored scripts contain *nothing* of the usual request-related environment. 
No CGI variables to speak of, no service, no request method, nothing!  The
easiest method for a script to detect if its been proctored into existence is
to look for the absence of this or these.  No REQUEST_METHOD is a fair
indicator as it should exist with all 'real' requests.  Of course a proctored
script is really just there to instatiate itself not do anything directly
productive and so a script/RTE can just recognise this and conclude with
perhaps a 204 HTTP status (no content) and then remain quiescent.

For an RTE the activation script specification in [DclScriptProctor] does not
need to actually exist.  It must contain a minimum path to activate the desired
environment but the script itself is not checked to exist by WASD and does not
need to exist.  If it does then it should do whatever is required to
instantiate its required environment and return a 204 (no content) response. 
If it does not exist then the RTE itself should detect it's a proctored
activation and return a default 204 response itself, instantiating only the RTE
environment.

Specific information *can* be passed to the proctored script using the
'script=param=name=...' mapping rule.  This appears as a [WWW_]NAME CGI
variable containing the value specified.  Proctored scripts could then act
according to any such data.

Proctored scripts can be detected during mapping using "if (request-method:)"
or "if (!request-method:%)" and information passed from proctor to mapping
using "if (notepad:blah)".

The combination of these allows some control of proctored scripting.

  # WASD_CONFIG_GLOBAL
  [DclScriptProctor]
  2 /cgi-bin/mgd* /cgi-bin/mgd proctor=daniel
  2+1 /cgi-bin/script* /cgi-bin/script anyoldname=dothis
  2 *
  2 * proctor=daniel

  # WASD_CONFIG_MAP
  if (request-method:)
     if (notepad:proctor=daniel) set /cgi-bin/mgd script=as=daniel
     if (notepad:anyoldname=dothis) set /cgi-bin/script script=param=DOTHIS=one
     script proctor=daniel proctor=daniel script=as=daniel
  endif
*/ 

DclScriptProctor ()

{
   static char  ProblemProctor [] = "[DclScriptProctor] problem";

   int  idx,
        BeginCount,
        IdleCount,
        ActiveCount;
   char  *cptr, *sptr, *zptr;
   char  DclCommand [256];
   DCL_TASK  *tkptr;
   LIST_ENTRY  *leptr;
   REQUEST_STRUCT  *rqptr;
   PROCTOR_STRUCT  *prptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclScriptProctor()");

   if (ControlExitRequested || ControlRestartRequested) return;

   for (idx = 0; idx < Config.cfScript.ProctorCount; idx++)
   {
      prptr = &Config.cfScript.Proctor[idx];

      /* if problem or place-holder then just continue */
      if (prptr->Problem) continue;
      if (!prptr->NumberMin && !prptr->NumberIdle) continue;

      if (prptr->FailWeight >= PROCTOR_FAIL_AT)
      {
         if (WATCH_CATEGORY(WATCH_DCL))
            WatchThis (WATCHALL, WATCH_DCL,
"PROCTOR FAILURE (!UL>=!UL) !UL+!UL !AZ!AZ!AZ!AZ!AZ!AZ!AZ!AZ!AZ",
                       prptr->FailWeight, PROCTOR_FAIL_AT,
                       prptr->NumberMin, prptr->NumberIdle,
                       *prptr->RunTimePtr ? "(" : "",
                       prptr->RunTimePtr,
                       *prptr->RunTimePtr ? ")" : "",
                       *prptr->ScriptPtr ? " " : "",
                       prptr->ScriptPtr,
                       *prptr->ActivatePtr ? " " : "",
                       prptr->ActivatePtr,
                       *prptr->NotePadPtr ? " " : "",
                       prptr->NotePadPtr);
         continue;
      }

      ActiveCount = IdleCount = 0;

      for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
      {
         tkptr = (DCL_TASK*)leptr;
         if (!tkptr->ScriptProcessPid) continue;
         if (*prptr->RunTimePtr)
         {
            if (!tkptr->ScriptRunTime[0]) continue;
            if (!StringMatch (NULL, tkptr->ScriptRunTime, prptr->RunTimePtr))
               continue;
         }
         if (*prptr->ScriptPtr)
         {
            if (*prptr->ScriptPtr == '*')
            {
               /* processes containing persistent scripts are of no use */
               if (tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
                   tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT) continue;
               /* if currently active then move on */
               if (tkptr->RequestPtr && !MATCH4(tkptr->DclCommandPtr, "!!*!"))
                   continue;
               /* if not the same activation string then not a match */
               if (!*(cptr = prptr->ActivatePtr)) cptr = "proctor";
               if (!StringMatch (NULL,
                                 tkptr->DclCommandPtr+(sizeof("!!*!")-1),
                                 cptr))
                  continue;
               /* must be idle */
            }
            else
            {
               if (!tkptr->ScriptName[0]) continue;
               if (!StringMatch (NULL, tkptr->ScriptName, prptr->ScriptPtr))
                  continue;
            }
         }

         /* if not yet concluded the proctoring consider it idle */
         if (tkptr->NextTaskFunction == &DclScriptProctorAst)
            IdleCount++;
         else
         if (tkptr->RequestPtr)
            ActiveCount++;
         else
            IdleCount++;
      }

      BeginCount = 0;
      if (ActiveCount + IdleCount < prptr->NumberMin)
      {
         BeginCount = prptr->NumberMin - ActiveCount - IdleCount;
         prptr->TotalMin += BeginCount;
      }
      if (IdleCount < prptr->NumberIdle &&
          BeginCount < prptr->NumberIdle)
      {
         prptr->TotalIdle += prptr->NumberIdle - BeginCount - IdleCount;
         BeginCount += prptr->NumberIdle - BeginCount - IdleCount;
      }

      if (WATCH_CATEGORY(WATCH_DCL))
         WatchThis (WATCHALL, WATCH_DCL,
"PROCTOR !&B !UL<!UL+!UL<!UL=!UL !AZ!AZ!AZ!AZ!AZ!AZ!AZ!AZ!AZ",
                    BeginCount, ActiveCount+IdleCount, prptr->NumberMin,
                    IdleCount, prptr->NumberIdle, BeginCount,
                    *prptr->RunTimePtr ? "(" : "",
                    prptr->RunTimePtr,
                    *prptr->RunTimePtr ? ")" : "",
                    *prptr->ScriptPtr ? " " : "",
                    prptr->ScriptPtr,
                    *prptr->ActivatePtr ? " " : "",
                    prptr->ActivatePtr,
                    *prptr->NotePadPtr ? " " : "",
                    prptr->NotePadPtr);

      while (BeginCount-- > 0)
      {
         rqptr = DclFauxRequest (NULL, NULL, NULL);

         rqptr->ProctorPtr = prptr;

         if (prptr->NotePadLength)
         {
            rqptr->NotePadPtr = VmGetHeap (rqptr, prptr->NotePadLength+1);
            strcpy (rqptr->NotePadPtr, prptr->NotePadPtr);
         }

         if (*prptr->ScriptPtr == '*')
         { 
            /* just an idle process (commented DCL command) */
            zptr = (sptr = DclCommand) + sizeof(DclCommand)-1;
            for (cptr = "$!!*!"; *cptr && sptr < zptr; *sptr++ = *cptr++);
            if (*prptr->ActivatePtr)
               cptr = prptr->ActivatePtr;
            else
               cptr = "proctor";
            while (*cptr && sptr < zptr) *sptr++ = *cptr++;
            *sptr = '\0';

            rqptr = DclFauxRequest (rqptr, DclCommand, DclScriptProctorAst);
         }
         else
         {
            /* a script */
            rqptr = DclFauxRequest (rqptr, prptr->ScriptPtr,
                                    DclScriptProctorAst);
         }

         if (!rqptr)
         {
            if (WATCHING (rqptr, WATCH_DCL))
               WatchThis (WATCHITM(rqptr), WATCH_DCL, "PROCTOR !AZ",
                          prptr->ScriptPtr);
            ErrorNoticed (NULL, 0, ProblemProctor, FI_LI);

            /* disable the proctoring entry immediately */
            prptr->FailWeight = PROCTOR_FAIL_NOW;
            DclScriptProctorReportFail (prptr, "!AZ", cptr+1);
            continue;
         }

         prptr->LastTime64 = HttpdTime64;

         InstanceGblSecIncrLong (&AccountingPtr->DclProctorCount);
      }
   }
}

/*****************************************************************************/
/*
Proctor script has concluded.
*/ 

DclScriptProctorAst (REQUEST_STRUCT *rqptr)

{

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL,
                 "DclScriptProctorAst() !&F !&X",
                 &DclScriptProctorAst, rqptr);

   if (WATCHING (rqptr, WATCH_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_DCL, "PROCTOR ready");

   /* remove from any supervisory list */
   HttpdSupervisorList (rqptr, -1);

   VmFreeRequest (rqptr, FI_LI);
}

/*****************************************************************************/
/*
Report a proctoring failure.
*/ 

DclScriptProctorReportFail
(
PROCTOR_STRUCT *prptr,
char *ReportFao,
...
)
{
   int  argcnt;
   unsigned long  *vecptr;
   unsigned long  FaoVector [16];
   char  buf [512];
   va_list  argptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclScriptProctorReportFail()");

   prptr->TotalFail++;
   prptr->LastFailTime64 = HttpdTime64;

   va_count (argcnt);
   va_start (argptr, ReportFao);
   vecptr = FaoVector;
   for (argcnt -= 2; argcnt; argcnt--)
      *vecptr++ = va_arg (argptr, unsigned long);
   va_end (argptr);
   *vecptr++ = 0;

   FaolToBuffer (prptr->FailReason, sizeof(prptr->FailReason), NULL,
                 ReportFao, &FaoVector);

   FaoToBuffer (buf, sizeof(buf), NULL,
                "!UL+!UL !AZ!AZ!AZ!AZ!AZ!AZ!AZ !UL failure!%s, !AZ\n",
                prptr->NumberMin, prptr->NumberIdle,
                *prptr->RunTimePtr ? "(" : "",
                prptr->RunTimePtr,
                *prptr->RunTimePtr ? ")" : "",
                *prptr->ScriptPtr ? " " : "",
                prptr->ScriptPtr,
                *prptr->ActivatePtr ? " " : "",
                prptr->ActivatePtr,
                prptr->TotalFail, prptr->FailReason);

   FaoToStdout ("%HTTPD-W-PROCTOR, !20%D, !AZ\n", 0, buf);

   /* report this message via OPCOM */
   if (OpcomMessages & OPCOM_HTTPD) FaoToOpcom ("%HTTPD-W-PROCTOR, !AZ", buf);
}

/*****************************************************************************/
/*
Perform an asynchronous search for the script file specified by
'tkptr->ScriptFileName'.  When found return the actual script file in
'tkptr->SearchOds.ResFileName' and call DclBeginScript().  If not found set to
empty and conclude the task.  The search is performed first by checking for a
file with the file type supplied with the script specification (usually not),
then by defaulting to ".COM", then ".EXE", and finally to any configured
runtime file types, in that order.

The file search uses a DCL task structure but no script process I/O is actually
underway. As the search is AST-driven it is possible for a cancelling client
to disconnect from the task structure via DclTaskRunDown() while the search
is in progress. Each find-script-file function checks for the request pointer
and aborts the search if no longer present. The 'tkptr->FindScript' flag
indicates the structure is in use for this purpose and so will not be
reallocated until reset as the search is finally aborted.
*/ 

DclFindScript (DCL_TASK *tkptr)

{
   int  status, idx;
   REQUEST_STRUCT  *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclFindScript() !UL !&Z !&Z",
                 tkptr->FindScriptState, tkptr->ScriptFileName,
                 tkptr->ScriptRunTime);

   if (!(rqptr = tkptr->RequestPtr))
   {
      /* request thread has disconnected during file search */
      DclFindScriptEnd (tkptr, false);
      return;
   }

   switch (tkptr->FindScriptState)
   {
      case DCL_FIND_SCRIPT_BEGIN :

         tkptr->FindScript = true;
         tkptr->FindScriptFileNamePtr = tkptr->ScriptFileName;

         /* first look for DCL procedure (overridden if file type supplied) */
         tkptr->FindScriptState = DCL_FIND_SCRIPT_COM;
         OdsParse (&tkptr->SearchOds,
                   tkptr->FindScriptFileNamePtr, 0, ".COM;", 5,
                   0, &DclFindScriptParseAst, tkptr);
         return;

      case DCL_FIND_SCRIPT_COM :

         /* command procedure not found, look for a command definition */
         tkptr->FindScriptState = DCL_FIND_SCRIPT_CLD;
         OdsParse (&tkptr->SearchOds,
                   tkptr->FindScriptFileNamePtr, 0, ".CLD;", 5,
                   0, &DclFindScriptParseAst, tkptr);
         return;

      case DCL_FIND_SCRIPT_CLD :

         /* command procedure not found, look for an executable */
         tkptr->FindScriptState = DCL_FIND_SCRIPT_EXE;
         OdsParse (&tkptr->SearchOds,
                   tkptr->FindScriptFileNamePtr, 0, ".EXE;", 5,
                   0, &DclFindScriptParseAst, tkptr);

         return;

      case DCL_FIND_SCRIPT_EXE :

         /* command definition not found, look for a configured run-time */
         tkptr->FindScriptRunTimeIdx = 0;
         tkptr->FindScriptState = DCL_FIND_SCRIPT_RUNTIME;

      case DCL_FIND_SCRIPT_RUNTIME :

         /* looking through any list of user-defined script file types */
         idx = tkptr->FindScriptRunTimeIdx++;
         if (idx >= Config.cfScript.RunTimeCount)
         {
            /********************/
            /* script not found */
            /********************/

            /* indicate the script was not found */
            tkptr->SearchOds.ResFileName[0] = '\0';

            if (((void*)tkptr->CalloutFunction == (void*)&AuthAgentCallout))
            {
               /* not a standard script, an (authorization) agent task */
               rqptr->rqResponse.HttpStatus = 500;
               ErrorGeneral (rqptr, MsgFor(rqptr,MSG_AUTH_AGENT_NOT_FOUND), FI_LI);
            }
            else
            {
               /* standard CGI/CGIplus script */
               rqptr->rqResponse.HttpStatus = 404;
               ErrorGeneral (rqptr, MsgFor(rqptr,MSG_SCRIPT_NOT_FOUND), FI_LI);
            }

            DclFindScriptEnd (tkptr, false);

            return;
         }

         OdsParse (&tkptr->SearchOds,
                   tkptr->FindScriptFileNamePtr, 0,
                   Config.cfScript.RunTime[idx].StringPtr,
                   Config.cfScript.RunTime[idx].FileTypeLength,
                   0, &DclFindScriptParseAst, tkptr);

         return;

      default :
            ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
   }
}

/*****************************************************************************/
/*
AST called from DclFindScript() when asynchronous parse completes.  Check for
error status, then perform an asynchronous search with AST to
DclFindScriptSearchAst()
*/

DclFindScriptParseAst (DCL_TASK *tkptr)

{
   int  status;
   REQUEST_STRUCT  *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclFindScriptParseAst() !&F sts:!&S stv:!&S",
                 &DclFindScriptParseAst,
                 tkptr->SearchOds.Fab.fab$l_sts,
                 tkptr->SearchOds.Fab.fab$l_stv);

   if (!(rqptr = tkptr->RequestPtr))
   {
      /* request thread has disconnected during file search */
      DclFindScriptEnd (tkptr, false);
      return;
   }

   if (VMSnok (status = tkptr->SearchOds.Fab.fab$l_sts))
   {
      rqptr->rqResponse.ErrorTextPtr = tkptr->ScriptName;
      rqptr->rqResponse.ErrorOtherTextPtr = tkptr->ScriptFileName;
      ErrorVmsStatus (rqptr, status, FI_LI);
      DclFindScriptEnd (tkptr, false);
      return;
   }

   if (tkptr->SearchOds.Nam_fnb & NAM$M_WILDCARD)
   {
      rqptr->rqResponse.HttpStatus = 403;
      rqptr->rqResponse.ErrorTextPtr = tkptr->ScriptName;
      rqptr->rqResponse.ErrorOtherTextPtr = tkptr->ScriptFileName;
      ErrorGeneral (rqptr, MsgFor(rqptr,MSG_GENERAL_NO_WILDCARD), FI_LI);
      DclFindScriptEnd (tkptr, false);
      return;
   }

   OdsSearch (&tkptr->SearchOds, &DclFindScriptSearchAst, tkptr);
}

/*****************************************************************************/
/*
AST called from DclFindScriptParseAst() when asynchronous search completes.
Check for a file-not-found status, if so then call DclFindScript() to search
for the next possibility.  Check for an error status.  If the file has been
found determine the runtime environment and initiate the script process
execution. 
*/

DclFindScriptSearchAst (DCL_TASK *tkptr)

{
   int  status, idx;
   char  *cptr, *sptr, *zptr;
   REQUEST_STRUCT  *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclFindScriptSearchAst() !&F sts:!&S stv:!&S",
                 &DclFindScriptSearchAst,
                 tkptr->SearchOds.Fab.fab$l_sts,
                 tkptr->SearchOds.Fab.fab$l_stv);

   if (!(rqptr = tkptr->RequestPtr))
   {
      /* request thread has disconnected during file search */
      DclFindScriptEnd (tkptr, false);
      return;
   }

   if (VMSnok (status = tkptr->SearchOds.Fab.fab$l_sts))
   {
      if (WATCHING (rqptr, WATCH_DCL))
      {
         tkptr->SearchOds.NamVersionPtr[0] = '\0';
         WatchThis (WATCHITM(rqptr), WATCH_DCL,
                    "SEARCH !AZ !&S",
                    tkptr->SearchOds.NamDevicePtr, status);
         tkptr->SearchOds.NamVersionPtr[0] = ';';
      }

      if (status == RMS$_FNF)
      {
          /* not found */
         if (!(tkptr->SearchOds.Nam_fnb & NAM$M_EXP_TYPE))
         {
            /* only if type not explicitly supplied then look for another */
            DclFindScript (tkptr);
            return;
         }
      }

      /* some other error, report it and finish up */
      rqptr->rqResponse.ErrorTextPtr = tkptr->ScriptName;
      rqptr->rqResponse.ErrorOtherTextPtr = tkptr->ScriptFileName;
      ErrorVmsStatus (rqptr, status, FI_LI);
      DclFindScriptEnd (tkptr, false);
      return;
   }

   if (WATCHING (rqptr, WATCH_DCL))
   {
      tkptr->SearchOds.NamVersionPtr[0] = '\0';
      WatchThis (WATCHITM(rqptr), WATCH_DCL,
                 "SEARCH found !AZ", tkptr->SearchOds.NamDevicePtr);
      tkptr->SearchOds.NamVersionPtr[0] = ';';
   }

   /*************/
   /* found it! */
   /*************/

   if (tkptr->ScriptRunTime[0])
      tkptr->ScriptRunTimePtr = tkptr->ScriptRunTime;
   else
   if (strsame (tkptr->SearchOds.NamTypePtr, ".COM;", 5))
      tkptr->ScriptRunTimePtr = "@";
   else
   if (strsame (tkptr->SearchOds.NamTypePtr, ".CLD;", 5))
      tkptr->ScriptRunTimePtr = "=";
   else
   if (strsame (tkptr->SearchOds.NamTypePtr, ".EXE;", 5))
      tkptr->ScriptRunTimePtr = "$";
   else
   {
      /* look through the list of user-definable script file types */
      for (idx = 0; idx < Config.cfScript.RunTimeCount; idx++)
      {
         if (WATCHMOD (tkptr, WATCH_MOD_DCL))
            WatchDataFormatted ("!&Z !&Z\n",
                                tkptr->SearchOds.NamTypePtr,
                                Config.cfScript.RunTime[idx].StringPtr);
         if (strsame (tkptr->SearchOds.NamTypePtr,
                      Config.cfScript.RunTime[idx].StringPtr,
                      Config.cfScript.RunTime[idx].FileTypeLength))
            break;
      }
      if (idx < Config.cfScript.RunTimeCount)
      {
         /* found the file type (file extension) */
         cptr = Config.cfScript.RunTime[idx].StringPtr;
         while (*cptr && *cptr != ' ') cptr++;
         if (*cptr) cptr++;
         tkptr->ScriptRunTimePtr = cptr;
      }
      else
      if (tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
         tkptr->ScriptRunTimePtr = NULL;
      else
      if (rqptr->rqPathSet.ScriptCommandPtr &&
          rqptr->rqPathSet.ScriptCommandPtr[0] != '*')
         tkptr->ScriptRunTimePtr = "";
      else
      {
         /********************************************/
         /* don't know how to execute this file type */
         /********************************************/

         rqptr->rqResponse.HttpStatus = 500;
         tkptr->SearchOds.NamVersionPtr[0] = '\0';
         ErrorGeneral (rqptr,
"Execution of &nbsp;<tt>!AZ</tt>&nbsp; script types not configured.",
                       tkptr->SearchOds.NamTypePtr, FI_LI);
         DclFindScriptEnd (tkptr, false);
         return;
      }
   }

   /**********************/
   /* execute the script */
   /**********************/

   /* terminate the expanded CGI file name */
   tkptr->SearchOds.NamVersionPtr[0] = '\0';

   DclFindScriptEnd (tkptr, true);
}

/*****************************************************************************/
/*
The parse structures only really need to be explicitly released if the script
is actually found, otherwise they are always implicitly released on the
sys$search() file-not-found! Here we'll do it all the time as we are dealing
with possible search abort as well as general search conclusion. When doing so
use scratch expanded file name space so as not to overwrite the CGI file name
if the script file was found.
*/

DclFindScriptEnd
(
DCL_TASK *tkptr,
BOOL FileFound
)
{
   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclFindScriptEnd() !&F !&B", &DclFindScriptEnd, FileFound);

   tkptr->FindScript = false;

   /* ensure parse internal data structures are released */
   OdsParseRelease (&tkptr->SearchOds);

   if (FileFound)
   {
      /* update the cache */
      DclUpdateScriptNameCache (tkptr);

      /* NOW update the script file name with the one actually resolved */
      strcpy (tkptr->ScriptFileName, tkptr->SearchOds.ResFileName);
      tkptr->RequestPtr->rqCgi.ScriptFileNamePtr = tkptr->ScriptFileName;

      DclBeginScript (tkptr);
      return;
   }
   else
   if (tkptr->NextTaskFunction == &DclScriptProctorAst)
   {
      /* disable the proctoring entry immediately */
      tkptr->ProctorPtr->FailWeight = PROCTOR_FAIL_NOW;
      DclScriptProctorReportFail (tkptr->ProctorPtr, "activator not found");
   }

   /* ensure it looks as if it was NOT found */
   tkptr->SearchOds.ResFileName[0] = '\0';
   DclTaskRunDown (tkptr); 
   return;
}

/*****************************************************************************/
/*
Abort current request script processing, freeing the request and DCL task from
each other, then restart DCL processing appropriately.  Is used to restart
processing after CGIplus script failed to start (see "April 1998 Note:" above)
or when a run-time configuration entry indicates either CGIplus or RTE should
be used to handle scripting the file type.  When restarting for RTE two sources
of the RTE executable must be considered.  If from the [DclScriptRunTime]
configuration structure then 'ScriptRunTimePtr' points to a file name,
otherwise 'ScriptRunTimePtr' points to either "$" or "@" to indicate how the
file should be handled.  If the second character is a null then it's the latter
and the 'ResFileName' should be used.
*/ 

DclRestartScript (DCL_TASK *tkptr)

{
   int  status,
        TaskType;
   char  *ScriptRunTimePtr;
   char  DclCommand [DCL_COMMAND_MAX_SIZE],
         ScriptRunTime [ODS_MAX_FILE_NAME_LENGTH+1],
         ResFileName [ODS_MAX_FILE_NAME_LENGTH+1],
         ScriptFileName [ODS_MAX_FILE_NAME_LENGTH+1],
         ScriptName [SCRIPT_NAME_SIZE];
   PROCTOR_STRUCT  *ProctorPtr;
   REQUEST_AST  NextTaskFunction;
   REQUEST_STRUCT  *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL, "DclRestartScript()");

   rqptr = tkptr->RequestPtr;

   if (WATCHING (rqptr, WATCH_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_DCL, "RESTART script !UL",
                 tkptr->RequestPtr->rqCgi.ScriptRetryCount);

   if (!rqptr->AgentRequestPtr)
      if (rqptr->WebSocketRequest)
         WebSockRemove (rqptr);

   /* retrieve necessary information from the current DCL task */
   TaskType = tkptr->TaskType;
   NextTaskFunction = tkptr->NextTaskFunction;
   ProctorPtr = tkptr->ProctorPtr;
   strcpy (ResFileName, tkptr->SearchOds.ResFileName);
   strcpy (ScriptFileName, tkptr->ScriptFileName);
   strcpy (ScriptName, tkptr->ScriptName);
   strcpy (DclCommand, tkptr->DclCommandPtr);
   if (tkptr->ScriptRunTime[0])
   {
      strcpy (ScriptRunTime, tkptr->ScriptRunTime);
      ScriptRunTimePtr = ScriptRunTime;
   }
   else
      ScriptRunTimePtr = NULL;

   /* disassociate the DCL task and request structures, then conclude */
   tkptr->RequestPtr->DclTaskPtr = NULL;
   tkptr->RequestPtr = tkptr->NextTaskFunction = NULL;
   tkptr->WatchItem = 0;

   DclTaskRunDown (tkptr); 

   /* restart using a new DCL task */
   switch (TaskType)
   {
      case DCL_TASK_TYPE_CGIPLUS_SCRIPT :

         DclBegin (rqptr, NextTaskFunction, NULL, ScriptName, NULL,
                   ScriptFileName, ScriptRunTimePtr, NULL);
         return;

      case DCL_TASK_TYPE_CGI_SCRIPT :

         DclBegin (rqptr, NextTaskFunction, NULL, ScriptName, ScriptFileName,
                   NULL, ScriptRunTimePtr, NULL);
         return;

      case DCL_TASK_TYPE_RTE_SCRIPT :

         DclBegin (rqptr, NextTaskFunction, NULL, ScriptName, ScriptFileName,
                   NULL, ScriptRunTime, NULL);
         return;

      case DCL_TASK_TYPE_CLI :

         DclBegin (rqptr, NextTaskFunction, DclCommand, NULL, NULL,
                   NULL, NULL, NULL);
         return;

      default :

         ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
   }
}

/*****************************************************************************/
/*
Called with an already-established CGIplus script, a DCL command, or when a
new CGIplus or CGI script file name has been searched for and found.  Begin
the I/O with the script process.
*/ 

DclBeginScript (DCL_TASK *tkptr)

{
   int  status,
        Length;
   char  *ContentPtr;
   REQUEST_STRUCT  *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL, "DclBeginScript()");

   if (!(rqptr = tkptr->RequestPtr))
   {
      /* request thread has disconnected during file search */
      DclTaskRunDown (tkptr);
      return;
   }

   if (tkptr->TaskType != DCL_TASK_TYPE_CLI)
   {
      /* provide request stream (HTTP$INPUT) to script process */
      if (Config.cfScript.FullRequest)
      {
         ErrorGeneral (rqptr, "[DclFullRequest] no longer supported!", FI_LI);
         DclTaskRunDown (tkptr);
         return;
      }

      if (!rqptr->AgentRequestPtr &&
          !rqptr->WebSocketRequest)
      {
         BodyReadBegin (rqptr, &DclHttpInput, NULL);
         tkptr->QueuedClientRead++;
      }
   }

   /* queue the initial read of the script process' SYS$OUTPUT */
   DclQioSysOutput (tkptr);

   if (!rqptr->AgentRequestPtr &&
       rqptr->WebSocketRequest)
   {
      WebSockCreateMailboxes (rqptr);
      rqptr->rqWebSocket.ScriptProcessPid = tkptr->ScriptProcessPid;
   }

   switch (tkptr->TaskType)
   {
      case DCL_TASK_TYPE_CGI_SCRIPT :

         tkptr->QueuedSysCommandAllowed = 0;
         rqptr->rqResponse.ErrorTextPtr =
            MsgFor(rqptr,MSG_SCRIPT_DCL_ENVIRONMENT);
         if (VMSnok (DclCgiScriptSysCommand (tkptr)))
         {
            tkptr->DeleteProcess = true;
            DclTaskRunDown (tkptr);
            return;
         }

         break;

      case DCL_TASK_TYPE_CGIPLUS_SCRIPT :
      case DCL_TASK_TYPE_RTE_SCRIPT :

         /* allow for the outstanding queued "STOP/id=0" and EOF */
         tkptr->QueuedSysCommandAllowed = 2;
         if (tkptr->QueuedSysCommand < tkptr->QueuedSysCommandAllowed)
            DclCgiPlusScriptSysCommand (tkptr);

         /* here comes the CGI variable stream */
         if (VMSnok (DclCgiPlusScriptCgiPlusIn (tkptr)))
         {
            tkptr->DeleteProcess = true;
            DclTaskRunDown (tkptr);
            return;
         }

         break;

      case DCL_TASK_TYPE_CLI :

         tkptr->QueuedSysCommandAllowed = 0;
         if (VMSnok (DclCgiScriptSysCommand (tkptr)))
         {
            tkptr->DeleteProcess = true;
            DclTaskRunDown (tkptr);
            return;
         }

         break;

      default :
            ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
   }

   /* remove default error message */
   rqptr->rqResponse.ErrorTextPtr = NULL;
}

/*****************************************************************************/
/*
Delete any scripting processes. 
Called by the image user-mode exit handler.
*/

void DclExit ()

{
   DCL_TASK  *tkptr;
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclExit()");

   for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      tkptr = (DCL_TASK*)leptr;
      if (!tkptr->ScriptProcessPid) continue;
      DclDeleteProcess (tkptr);
   }
}

/*****************************************************************************/
/*
Update the accounting accumulators.
*/

void DclCountScriptProcess ()

{
   int  ScriptCgiPlusCount,
        ScriptRteCount,
        ScriptProcessCount;
   DCL_TASK  *tkptr;
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclCountScriptProcess()");

   ScriptCgiPlusCount = ScriptRteCount = ScriptProcessCount = 0;
   for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      tkptr = (DCL_TASK*)leptr;
      if (!tkptr->ScriptProcessPid) continue;
      ScriptProcessCount++;
      if (tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT)
         ScriptCgiPlusCount++;
      else
      if (tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
         ScriptRteCount++;
   }

   InstanceMutexLock (INSTANCE_MUTEX_HTTPD);

   AccountingPtr->CurrentDclScriptCgiPlus[InstanceNumber] = ScriptCgiPlusCount;
   AccountingPtr->CurrentDclScriptRTE[InstanceNumber] = ScriptRteCount;
   AccountingPtr->CurrentDclScriptProcess[InstanceNumber] = ScriptProcessCount;

   InstanceMutexUnLock (INSTANCE_MUTEX_HTTPD);
}

/*****************************************************************************/
/*
The maximum number of concurrent script processes has been reached. Look
through the DCL task structure for a CGIplus script process not currently in
use.  Find the least used script process and delete it.  A lifetime count of -1
or if it set as do-not-disturb indicates the script process has requested that
it be immune to supervisor purging.
*/

DclScriptProcessPurge ()

{
   int  status,
        MinUsageCount;
   DCL_TASK  *mintkptr;
   DCL_TASK  *tkptr;
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclScriptProcessPurge() !UL !UL",
                 DclCurrentScriptProcess, DclScriptProcessSoftLimit);

   DclPurgeCount++;
   MinUsageCount = 999999999;
   mintkptr = NULL;

   for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      tkptr = (DCL_TASK*)leptr;

      if (!tkptr->ScriptProcessPid ||
          tkptr->QueuedSysOutput ||
          tkptr->QueuedClientOutput ||
          tkptr->QueuedCgiPlusIn ||
          tkptr->QueuedHttpInput ||
          tkptr->QueuedClientRead ||
          (tkptr->TaskType != DCL_TASK_TYPE_CGIPLUS_SCRIPT &&
           tkptr->TaskType != DCL_TASK_TYPE_RTE_SCRIPT) ||
          tkptr->LifeTimeSecond == DCL_DO_NOT_DISTURB ||
          tkptr->RequestPtr ||
          tkptr->FindScript ||
          tkptr->DeleteProcess)
         continue;

      if (WebSockCount (tkptr->ScriptProcessPid)) continue;

      if (tkptr->CgiPlusUsageCount < MinUsageCount)
         MinUsageCount = (mintkptr = tkptr)->CgiPlusUsageCount;
   }

   if (!mintkptr) return;

   mintkptr->DeleteProcess = true;
   DclTaskRunDown (mintkptr);
   DclSoftLimitPurgeCount++;
}

/*****************************************************************************/
/*
This function may be called at any stage to rundown or abort a DCL task,
including during the search for the script file (see note in DclFindScript()).
If there is still outstanding I/O this is cancelled as appropriate to task
rundown or abort. If no outstanding I/O then if there is an associated request
that request's next task function is called.
*/

DclTaskRunDown (DCL_TASK *tkptr)

{
   int  status,
        SetPrvStatus;
   REQUEST_STRUCT  *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
"DclTaskRunDown() rq:!&X state:!UL tcnt:!UL del:!&B imex:!&B exsec:!UL act:!&B \
syscom:!UL/!UL sysout:!UL client:!UL plusin:!UL httpin:!UL read:!UL pid:!8XL",
         tkptr->RequestPtr,
         tkptr->RequestPtr ? tkptr->RequestPtr->RequestState : 0,
         tkptr->RequestPtr ? tkptr->RequestPtr->rqTmr.TimeoutCount : 0,
         tkptr->DeleteProcess,
         tkptr->ForceImageExit, tkptr->ForceImageExitSecond,
         tkptr->ScriptProcessActivated,
         tkptr->QueuedSysCommand, tkptr->QueuedSysCommandAllowed,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn, tkptr->QueuedHttpInput,
         tkptr->QueuedClientRead, tkptr->ScriptProcessPid);

   rqptr = tkptr->RequestPtr;

   if (tkptr->DeleteProcess) tkptr->QueuedSysCommandAllowed = 0;

   if (tkptr->QueuedSysOutput ||
       tkptr->QueuedCgiPlusIn ||
       tkptr->QueuedHttpInput ||
       tkptr->QueuedSysCommand > tkptr->QueuedSysCommandAllowed)
   {
      /* cancel any outstanding process I/O */
      sys$cancel (tkptr->SysOutputChannel);
      sys$cancel (tkptr->CgiPlusInChannel);
      sys$cancel (tkptr->HttpInputChannel);
      if (tkptr->QueuedSysCommand > tkptr->QueuedSysCommandAllowed)
         sys$cancel (tkptr->SysCommandChannel);
      return;
   }

   if (tkptr->QueuedClientOutput ||
       tkptr->QueuedClientRead)
   {
      /* cancel any outstanding client I/O */
      if (rqptr)
      {
        RequestIoCancel (rqptr);
        return;
      }
      /* hmmm */
      ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);
   }

   if (tkptr->MemBufGblSecPtr) DclMemBufDelete (tkptr);

   /* if there's still an outstanding CPU watchdog $GETJPI wait for it */
   if (tkptr->ScriptCpuTimGetJpi) return;

   if (tkptr->DeleteProcess)
      if (tkptr->ForceImageExit)
      {
         DclForceImageExit (tkptr);
         return;
      }

   /*********************/
   /* task has finished */
   /*********************/

   if (tkptr->ScriptName[0] && !tkptr->SearchOds.ResFileName[0])
   {
      /* search for script file was unsuccessful */
      if (rqptr)
      {
         /* still has an associated request, declare the next task */
         SysDclAst (tkptr->NextTaskFunction, rqptr);

         /* disassociate the DCL task and request structures */
         rqptr->DclTaskPtr = NULL;
         tkptr->RequestPtr = tkptr->NextTaskFunction = NULL;
         tkptr->WatchItem = 0;
      }

      if (tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
          tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
         tkptr->DeleteProcess = true;
   }
   else
   if (rqptr)
   {
      if (!tkptr->ScriptProcessActivated &&
          rqptr->rqCgi.ScriptRetryCount++ < DCL_MAX_SCRIPT_RETRY &&
          !rqptr->rqResponse.ErrorReportPtr)
      {
         /* looks like the script exited before actually starting! */
         tkptr->DeleteProcess = true;
         DclRestartScript (tkptr);
      }
      else
      {
         /* ensure carriage-control is (potentially) reset */
         if (!HTTP2_REQUEST(rqptr))
            if (Config.cfScript.GatewayBg)
               NetClientSocketCcl (rqptr->NetIoPtr, 0);

         if (tkptr->TaskType != DCL_TASK_TYPE_CLI &&
             (!tkptr->ScriptProcessResponded ||
              !tkptr->ScriptProcessActivated) &&
             !rqptr->rqResponse.ErrorReportPtr)
         {
            /* hmmm, script has not provided any output! */
            if (rqptr->rqHeader.Method == HTTP_METHOD_GET)
            {
               /* blame script for general GET method failures */
               rqptr->rqResponse.HttpStatus = 502;
               ErrorGeneral (rqptr, MsgFor(rqptr,MSG_SCRIPT_RESPONSE_ERROR), FI_LI);
            }
            else
            {
               /* other methods are probably not implemented by the script */
               rqptr->rqResponse.HttpStatus = 501;
               ErrorGeneral (rqptr, MsgFor(rqptr,MSG_REQUEST_METHOD), FI_LI);
            }
         }

         if (rqptr->rqResponse.RedactBufferPtr &&
             rqptr->rqResponse.RedactBufferCount)
         {
            /* redacted request invoked immediately */
            SysDclAst (RequestEnd, rqptr);
         }
         else
         {
            /* explicitly flushed in case it's an SSI activity */
            NetWriteFullFlush (rqptr, tkptr->NextTaskFunction);
         }

         /* disassociate the DCL task and request structures */
         rqptr->DclTaskPtr = NULL;
         tkptr->RequestPtr = tkptr->NextTaskFunction = NULL;
         tkptr->WatchItem = 0;
      }
   }

   if (DclUseZombies ||
       tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
       tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
   {
      /* empty any remains in sys$output! */
      DclEmptySysOutput (tkptr);
   }

   /* if marked for process deletion */
   if (tkptr->DeleteProcess)
   {
      if (tkptr->ScriptProcessPid)
         DclDeleteProcess (tkptr);
      else
      {
         tkptr->DeleteProcess = false;
         tkptr->TaskType = DCL_TASK_TYPE_NONE;
      }
   }

   if (DclUseZombies &&
       tkptr->TaskType != DCL_TASK_TYPE_CGIPLUS_SCRIPT &&
       tkptr->TaskType != DCL_TASK_TYPE_RTE_SCRIPT)
      tkptr->ZombieCount++;
}

/*****************************************************************************/
/*
$FORCEX is painful to use - It should have an AST like process deletion for
when it concludes.  You cannot issue a $DELPRC for the same process until you
are sure the image has run-down.  Hence, if a $FORCEX is issued for the target
process this function (and it's associated AST routine) must be called again to
determine if the image has exited.  If it hasn't then the check must be
performed again until it has (or until you are out of patience ;^).  Once the
image exits the $DELPRC can be issued.

This function is called to check if a script is executing an image.  An
asynchronous $GETJPI delivers to DclForceImageExitAst() where the decisions
are made.
*/

DclForceImageExit (DCL_TASK *tkptr)

{
   static unsigned long  GetJpiControlFlags = JPI$M_IGNORE_TARGET_STATUS;

   int  status,
        SetPrvStatus;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE (WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL,
                 "DclForceImageExit() !8XL", tkptr->ScriptProcessPid);

   /* if there's still an outstanding $GETJPI */
   if (tkptr->ForceImageExitGetJpi) return;

   if (!tkptr->ForceImageExitSecond)
   {
      /* set the timer to control how long the force image is waited for */
      tkptr->ForceImageExitSecond = HttpdTickSecond +
                                    DCL_FORCE_IMAGE_EXIT_SECONDS;
      tkptr->ForceImageExitIssued = tkptr->ForceImageExitGetJpi = false;
   }
   else
   if (HttpdTickSecond >= tkptr->ForceImageExitSecond)
   {
      /* exceeded maximum period trying to force the image to exit */
      tkptr->ForceImageExit = false;
      tkptr->ForceImageExitSecond = 0;
      DclTaskRunDown (tkptr);
      return;
   }

   /* using an asynchronous sys$getjpi() get (any) process image name */
   tkptr->JpiImagNameItem[0].buf_len = sizeof(GetJpiControlFlags);
   tkptr->JpiImagNameItem[0].item = JPI$_GETJPI_CONTROL_FLAGS;
   tkptr->JpiImagNameItem[0].buf_addr = &GetJpiControlFlags;
   tkptr->JpiImagNameItem[0].short_ret_len = 0;
   tkptr->JpiImagNameItem[1].buf_len = sizeof(tkptr->JpiImagName)-1;
   tkptr->JpiImagNameItem[1].item = JPI$_IMAGNAME;
   tkptr->JpiImagNameItem[1].buf_addr = tkptr->JpiImagName;
   tkptr->JpiImagNameItem[1].short_ret_len = &tkptr->JpiImagNameLength;
   tkptr->JpiImagNameItem[2].buf_len =
      tkptr->JpiImagNameItem[2].item =
      tkptr->JpiImagNameItem[2].buf_addr =
      tkptr->JpiImagNameItem[2].short_ret_len = 0;

   /* need WORLD privilege if process created under another username */
   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (1, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   status = sys$getjpi (0, &tkptr->ScriptProcessPid, 0,
                        &tkptr->JpiImagNameItem, &tkptr->JpiImagNameIOsb,
                        &DclForceImageExitAst, tkptr);

   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (0, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   if (VMSok (status))
   {
      tkptr->ForceImageExitGetJpi = true;
      /* if it's anything other than a CGIplus/RTE script look at it ASAP */
      if (!(tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
            tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT))
         DclSupervisor (DCL_SUPERVISOR_TICK_MIN);
      return;
   }

   tkptr->ForceImageExit = false;
   tkptr->ForceImageExitSecond = 0;

   /* commonly it can be gone but with termination AST not yet processed */
   if (status == SS$_NONEXPR) return;

   ErrorNoticed (NULL, status, NULL, FI_LI); 

   DclTaskRunDown (tkptr);
}

/*****************************************************************************/
/*
Called as an AST routine by the asynchronous $GETJPI in DclForceImageExit(). 
If the $GETJPI was successful and an image is running issue a $FORCEX to run
the image down.  If not just call DclTaskRunDown() again to begin running the
script process down.
*/

DclForceImageExitAst (DCL_TASK *tkptr)

{
   int  status,
        SetPrvStatus;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE (WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL,
                 "DclForceImageExitAst() !&F !8XL !&S {!UL}!-!#AZ",
                 &DclForceImageExitAst,
                 tkptr->ScriptProcessPid, tkptr->JpiImagNameIOsb.Status,
                 tkptr->JpiImagNameLength, tkptr->JpiImagName);

   tkptr->ForceImageExitGetJpi = false;

   if (VMSnok (tkptr->JpiImagNameIOsb.Status) || !tkptr->JpiImagNameLength)
   {
      /* sys$getjpi() unsuccessful or image not currently executing */
      tkptr->ForceImageExit = false;
      tkptr->ForceImageExitSecond = 0;
      DclTaskRunDown (tkptr);
      return;
   }

   /* if not the first check then return rather than using another $FORCEX */
   if (tkptr->ForceImageExitIssued) return;

   if WATCH_CATEGORY(WATCH_DCL)
      WatchThis (WATCHALL, WATCH_DCL, "FORCEX pid:!8XL !#AZ",
                 tkptr->ScriptProcessPid,
                 tkptr->JpiImagNameLength, tkptr->JpiImagName);

   /* need WORLD privilege if process created under another username */
   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (1, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   status = sys$forcex (&tkptr->ScriptProcessPid, 0, SS$_NORMAL);
   InstanceGblSecIncrLong (&AccountingPtr->DclForceXCount);

   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (0, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   if (VMSok (status))
   {
      tkptr->ForceImageExitIssued = true;
      return;
   }

   tkptr->ForceImageExit = false;
   tkptr->ForceImageExitSecond = 0;

   /* commonly it can be gone but with termination AST not yet processed */
   if (status == SS$_NONEXPR) return;

   ErrorNoticed (NULL, status, NULL, FI_LI); 

   DclTaskRunDown (tkptr);
}

/*****************************************************************************/
/*
Queue a $GETJPI to discover the CPU time consumed since start of script
processing.
*/

DclScriptCpuTim (DCL_TASK *tkptr)

{
   static unsigned long  GetJpiControlFlags = JPI$M_IGNORE_TARGET_STATUS;

   int  status,
        SetPrvStatus;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclScriptCpuTim() !8XL", tkptr->ScriptProcessPid);

   /* if there's still an outstanding $GETJPI */
   if (tkptr->ScriptCpuTimGetJpi) return;

   /* using an asynchronous sys$getjpi() get (any) process image name */
   tkptr->JpiCpuTimItem[0].buf_len = sizeof(GetJpiControlFlags);
   tkptr->JpiCpuTimItem[0].item = JPI$_GETJPI_CONTROL_FLAGS;
   tkptr->JpiCpuTimItem[0].buf_addr = &GetJpiControlFlags;
   tkptr->JpiCpuTimItem[0].short_ret_len = 0;
   tkptr->JpiCpuTimItem[1].buf_len = sizeof(tkptr->JpiCpuTim);
   tkptr->JpiCpuTimItem[1].item = JPI$_CPUTIM;
   tkptr->JpiCpuTimItem[1].buf_addr = &tkptr->JpiCpuTim;
   tkptr->JpiCpuTimItem[1].short_ret_len = 0;
   tkptr->JpiCpuTimItem[2].buf_len =
      tkptr->JpiCpuTimItem[2].item =
      tkptr->JpiCpuTimItem[2].buf_addr =
      tkptr->JpiCpuTimItem[2].short_ret_len = 0;

   /* need WORLD privilege if process created under another username */
   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (1, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   status = sys$getjpi (0, &tkptr->ScriptProcessPid, 0,
                        &tkptr->JpiCpuTimItem, &tkptr->JpiCpuTimIOsb,
                        &DclScriptCpuTimAst, tkptr);

   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (0, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   if (VMSok (status))
   {
      tkptr->ScriptCpuTimGetJpi = true;
      return;
   }

   /* commonly it can be gone but with termination AST not yet processed */
   if (status == SS$_NONEXPR) return;
   ErrorNoticed (NULL, status, NULL, FI_LI); 
}

/*****************************************************************************/
/*
*/

DclScriptCpuTimAst (DCL_TASK *tkptr)

{
   int  status,
        SetPrvStatus;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclScriptCpuTimAst() !&F !8XL !&S !UL !UL",
                 &DclScriptCpuTimAst,
                 tkptr->ScriptProcessPid, tkptr->JpiCpuTimIOsb.Status,
                 tkptr->JpiCpuTim, tkptr->ScriptCpuTimMax);
 
   tkptr->ScriptCpuTimGetJpi = false;

   if (tkptr->TaskRunDown)
   {
      /* task began run-down during asynchronous $GETJPI */
      DclTaskRunDown (tkptr);
      return;
   }

   /* sys$getjpi() unsuccessful (perhaps suspended), do nothing */
   if (VMSnok (tkptr->JpiCpuTimIOsb.Status)) return;

   /* if first time through with zombie then set the maximum allowed */
   if (!tkptr->ScriptCpuTimMax)
      /* multiply by one hundred turning seconds into 10mS ticks */
      tkptr->ScriptCpuTimMax = tkptr->JpiCpuTim + tkptr->ScriptCpuMax * 100;

   /* return if what's consumed is less that what's allowed */
   if (tkptr->JpiCpuTim < tkptr->ScriptCpuTimMax) return;

   if WATCH_CATEGORY(WATCH_DCL)
      WatchThis (WATCHALL, WATCH_DCL, "CPUMAX pid:!8XL cputim:!UL max:!UL",
                 tkptr->ScriptProcessPid, tkptr->JpiCpuTim,
                 tkptr->ScriptCpuTimMax);

   tkptr->ScriptCpuMax = tkptr->ScriptCpuTimMax = 0;
   tkptr->DeleteProcess = true;
   DclTaskRunDown (tkptr);
}

/*****************************************************************************/
/*
If an error is encountered an error message is generated and the error status
returned.  It is up to the calling routine to abort the processing.  Queue a
writer-wait I/O to the SYS$OUTPUT channel to stall I/O until the script process
has started.
*/ 

DclCreateScriptProcess
(
DCL_TASK *tkptr,
char *ScriptAsPtr,
int BasePriority
)
{
#if OPERATE_WITH_SYSPRV
   /* this mask does not get the SYSPRV bit reset during startup */
   static unsigned long  OperateSysPrvMask [2]  = { PRV$M_SYSPRV, 0 };
#endif

   static unsigned long  JpiAuthPriv [2],
                         PrevPrivMask [2];
   static char  CommandDevName [64];
   static $DESCRIPTOR (CommandDevNameDsc, CommandDevName);
   static $DESCRIPTOR (LoginOutDsc, "SYS$SYSTEM:LOGINOUT.EXE");

   static struct
   {
      short  flag;
      char  data [1+UAF$S_USERNAME + 1+UAF$S_USERNAME +
                  1+UAF$S_PASSWORD + 1+UAF$S_ACCOUNT];
   } LgiData;
   static $DESCRIPTOR (LgiDataDsc,"");

   static struct
   {
      unsigned short  buf_len;
      unsigned short  item;
      unsigned char   *buf_addr;
      unsigned short  *short_ret_len;
   }
      JpiItems [] =
   {
      { sizeof(JpiAuthPriv), JPI$_AUTHPRIV, &JpiAuthPriv, 0 },
      { 0,0,0,0 }
   };

   int  idx, pronum, status,
        Count,
        BecomeStatus,
        SetPrvStatus;
   unsigned short  Length;
   unsigned long  CrePrcFlags;
   char  *cptr, *sptr, *zptr,
         *ProcessTypePtr;
   IO_SB  IOsb;
   REQUEST_STRUCT  *rqptr;
   struct dsc$descriptor_s  *ProcessNameDscPtr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclCreateScriptProcess() !&Z !UL", ScriptAsPtr, BasePriority);

   rqptr = tkptr->RequestPtr;

   /* start with a known quantity (yep, got caught ;^) */
   status = SS$_NORMAL;

   /* sanity check */
   if (BasePriority > 5) BasePriority = 5;

#if OPERATE_WITH_SYSPRV
   /* if normally operating with SYSPRV *ensure* it's off before spawning */
   if (OperateWithSysPrv) 
      if (VMSnok (SetPrvStatus = sys$setprv (0, &OperateSysPrvMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);
#endif

   if (DclScriptDetachProcess)
   {
      if (HttpdNetworkMode)
         ProcessTypePtr = "network";
      else
         ProcessTypePtr = "detached";

      InstanceGblSecIncrLong (&AccountingPtr->DclCrePrcDetachCount);
      CrePrcFlags = PRC$M_DETACH;
      tkptr->CrePrcDetachProcess = tkptr->CrePrcDetachStarting = true;

      if (VMSnok (SetPrvStatus = sys$setprv (1, &CrePrcMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

      /* check if this task is for the same user as is required */
      if (strcmp (ScriptAsPtr, tkptr->CrePrcUserName)) 
      {
         /* nope, need to change the identity */
         zptr = (sptr=tkptr->CrePrcUserName) + sizeof(tkptr->CrePrcUserName)-1;
         for (cptr = ScriptAsPtr; *cptr && sptr < zptr; *sptr++ = *cptr++);
         *sptr = '\0';

         if (tkptr->CrePrcUserName[0] == '!')
         {
            /* used to disable default scripting account for some reason */
            status = SS$_INVUSER;
         }
         else
            status = SS$_NORMAL;

         /* set mailbox ACLs to "tag" the mailbox, and allow user access */
         if (VMSok (status))
            status = DclMailboxAcl (tkptr->SysCommandDevName,
                                    tkptr->CrePrcUserName);
         if (VMSok (status))
            status = DclMailboxAcl (tkptr->SysOutputDevName,
                                    tkptr->CrePrcUserName);
         if (VMSok (status))
            status = DclMailboxAcl (tkptr->HttpInputDevName,
                                    tkptr->CrePrcUserName);
         if (VMSok (status))
            status = DclMailboxAcl (tkptr->CgiPlusInDevName,
                                    tkptr->CrePrcUserName);
         if (VMSok (status))
            status = DclMailboxAcl (tkptr->CrePrcTermMbxDevName,
                                    tkptr->CrePrcUserName);

         /* no such id is generated by DclMailboxAcl() if username unknown */
         if (status == SS$_NOSUCHID) status = SS$_INVUSER;

         if (VMSok (status) &&
             (DclPersonaServicesAvailable ||
              ScriptAsPtr == HttpdScriptAsUserName))
         {
            status = PersonaAssume (tkptr->CrePrcUserName);
            if (VMSok (status) &&
                ScriptAsPtr != HttpdScriptAsUserName)
            {
               status = PersonaAllowed (rqptr, tkptr->CrePrcUserName);
               if (status == SS$_CREATED)
               {
                  /* bogus success message indicates privileged account */
                  InstanceGblSecIncrLong (&AccountingPtr->
                                          DclCrePrcPersonaPrvUserCount);
                  FaoToStdout ("%HTTPD-W-PERSONA, !20%D, privileged !AZ\n",
                               0, tkptr->CrePrcUserName);
                  /* report this message whenever any OPCOM is in use */
                  if (Config.cfOpcom.Messages)
                     FaoToOpcom ("%HTTPD-W-PERSONA, privileged !AZ",
                                 tkptr->CrePrcUserName);
               }
            }
            if (VMSok (status))
            {
               InstanceGblSecIncrLong (&AccountingPtr->DclCrePrcPersonaCount);
               if (ScriptAsPtr == HttpdProcess.UserName ||
                   ScriptAsPtr == HttpdScriptAsUserName)
                  InstanceGblSecIncrLong (&AccountingPtr->
                                          DclCrePrcPersonaDefaultCount);
            }
         }

         if WATCH_CATEGORY(WATCH_DCL)
         {
            if (VMSok (status))
               WatchThis (WATCHITM(tkptr), WATCH_DCL,
                  "USERNAME !AZ", tkptr->CrePrcUserName);
            else
               WatchThis (WATCHITM(tkptr), WATCH_DCL,
                  "USERNAME !AZ !&S", tkptr->CrePrcUserName, status);
         }

         if (status == SS$_INVUSER)
         {
            InstanceGblSecIncrLong (&AccountingPtr->
                                    DclCrePrcPersonaInvUserCount);
            FaoToStdout ("%HTTPD-W-PERSONA, !20%D, invalid user !AZ\n",
                         0, tkptr->CrePrcUserName);
            /* report this message whenever any OPCOM is in use */
            if (Config.cfOpcom.Messages)
               FaoToOpcom ("%HTTPD-W-PERSONA, invalid user !AZ",
                           tkptr->CrePrcUserName);
            /* report invalid user as "forbidden" */
            rqptr->rqResponse.HttpStatus = 403;
         }
      }
   }
   else
   {
      ProcessTypePtr = "subprocess";
      InstanceGblSecIncrLong (&AccountingPtr->DclCrePrcSubprocessCount);
      CrePrcFlags = 0;
      if (Config.cfScript.SpawnAuthPriv)
      {
         /* enable persona's authorized privileges prior to spawning */
         status = sys$getjpiw (EfnWait, 0, 0, &JpiItems, &IOsb, 0, 0);
         if (VMSok (status)) status = IOsb.Status;
         if (VMSnok (status))
            ErrorExitVmsStatus (status, NULL, FI_LI);
         if (VMSnok (SetPrvStatus =
             sys$setprv (1, &JpiAuthPriv, 0, &PrevPrivMask)))
            ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);
      }
   }

   if (VMSok (status))
   {                                
      /* allow for duplicate process name(s) */
      for (Count = 100; Count; Count--)
      {
         ProcessNameDscPtr = DclNameProcess (tkptr);

         if (HttpdNetworkMode)
         {
            /*********************************/
            /* create "network" mode process */
            /*********************************/

            memset (&LgiData, 0, sizeof(LgiData));
            LgiData.flag = LGI$M_NET_PROXY;
            idx = 0;
            cptr = tkptr->CrePrcUserName;
            LgiData.data[idx] = strlen(cptr);
            memcpy (&LgiData.data[idx+1], cptr, LgiData.data[idx]);
            idx += LgiData.data[idx] + 1;
            LgiData.data[idx++] = 0;
            LgiData.data[idx++] = 0;
            LgiData.data[idx++] = 0;
            LgiDataDsc.dsc$a_pointer = &LgiData;
            LgiDataDsc.dsc$w_length = sizeof(LgiData.flag) + idx;
            CrePrcFlags = PRC$M_DETACH | PRC$M_NETWRK | PRC$M_NOPASSWORD;

            /* create network log file name (e.g. "_MBX1234:NET$WASD.LOG") */
            zptr = (sptr = CommandDevName) + sizeof(CommandDevName)-1;
            for (cptr = tkptr->SysCommandDevName;
                 *cptr && sptr < zptr; 
                 *sptr++ = *cptr++);
            for (cptr = NETWORK_MODE_LOG_NAME;
                 *cptr && sptr < zptr; 
                 *sptr++ = *cptr++);
            *sptr = '\0';
            CommandDevNameDsc.dsc$w_length = sptr - CommandDevName;

            status = sys$creprc (&tkptr->ScriptProcessPid,
                                 &LoginOutDsc,
                                 /* composite SYS$INPUT and log file name */
                                 &CommandDevNameDsc,
                                 /* proxy login data structure */
                                 &LgiDataDsc,
                                 /* SYS$NET, which must be redirected to */
                                 &tkptr->SysOutputDevNameDsc,
                                 0, 0,
                                 ProcessNameDscPtr,
                                 BasePriority,
                                 0,
                                 tkptr->CrePrcTermMbxUnit,
                                 CrePrcFlags,
                                 0, 0);
         }
         else
         {
            /**************************************/
            /* create "other" mode or sub process */
            /**************************************/

            status = sys$creprc (&tkptr->ScriptProcessPid,
                                 &LoginOutDsc,
                                 &tkptr->SysCommandDevNameDsc,
                                 &tkptr->SysOutputDevNameDsc,
                                 0, 0, 0,
                                 ProcessNameDscPtr,
                                 BasePriority,
                                 0,
                                 tkptr->CrePrcTermMbxUnit,
                                 CrePrcFlags,
                                 0, 0);
         }

         if WATCH_CATEGORY(WATCH_DCL)
         {
            if (VMSok (status))
               WatchThis (WATCHITM(tkptr), WATCH_DCL,
                  "CREATE !AZ pid:!8XL priority !UL",
                  ProcessTypePtr, tkptr->ScriptProcessPid, BasePriority);
            else
               WatchThis (WATCHITM(tkptr), WATCH_DCL,
                  "CREATE !AZ !&S", ProcessTypePtr, status);
         }

         if (status != SS$_DUPLNAM) break;
      }
   }

   if (DclScriptDetachProcess)
   {
      tkptr->DetachedGrantId = true;
      if (DclPersonaServicesAvailable ||
          ScriptAsPtr == HttpdScriptAsUserName)
      {
         /* return to the "natural" persona of the server account */
         BecomeStatus = PersonaAssume (NULL);
         if (VMSnok (BecomeStatus)) status = BecomeStatus;
      }
      if (VMSnok (SetPrvStatus = sys$setprv (0, &CrePrcMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);
   }
   else
   if (Config.cfScript.SpawnAuthPriv)
   {
      /* spawned with authorized privileges, restore previous ones */
      if (VMSnok (SetPrvStatus = sys$setprv (0, &JpiAuthPriv, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);
      if (VMSnok (SetPrvStatus = sys$setprv (1, &PrevPrivMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);
   }

#if OPERATE_WITH_SYSPRV
   /* if normally operating with SYSPRV turn it back on */
   if (OperateWithSysPrv) 
      if (VMSnok (SetPrvStatus = sys$setprv (1, &OperateSysPrvMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);
#endif

   DclNameProcess (tkptr);

   if (VMSok (status))
   {
      /* queue a read from the process termination mailbox */
      memset (&tkptr->CrePrcTermRecord, 0, sizeof(tkptr->CrePrcTermRecord));
      status = sys$qio (EfnNoWait, tkptr->CrePrcTermMbxChannel, IO$_READLBLK,
                        &tkptr->CrePrcTermMbxIOsb,
                        &DclScriptProcessCompletionAST, tkptr,
                        &tkptr->CrePrcTermRecord,
                        sizeof(tkptr->CrePrcTermRecord),
                        0, 0, 0, 0);

      if (VMSnok (status))
         if (tkptr->ScriptProcessPid)
            DclDeleteProcess (tkptr);
   }

   DclCountScriptProcess ();

   if (VMSok (status))
   {
      InstanceGblSecIncrLong (&AccountingPtr->DclCrePrcCount);
      return (status);
   }

   rqptr->rqResponse.ErrorTextPtr = MsgFor(rqptr,MSG_SCRIPT_SPAWN);
   ErrorVmsStatus (rqptr, status, FI_LI);
   return (status);
}

/*****************************************************************************/
/*
Set the default and the executing script process names.
The initial (and historical) process name is "WASD:<port>-<nnn>".
The quiescent (zombie) process name is "WASD:<port>_<xpid>".
The active CGI script process name is "/<script-name>_<xpid>",
and "/<script-name>+<xpid>" for CGIplus,
and "/<rte-name>=<xpid>" for RTE,
and "/<script-name>~<xpid>" for WebSocket (CGIplus),
and "WASD:<port>$<xpid>" for CLI commands.
*/

struct dsc$descriptor_s* DclNameProcess (DCL_TASK *tkptr)

{
   static int  ProcessNumber = 0;
   static $DESCRIPTOR (ProcessName1FaoDsc, "!AZ-!UL");
   static $DESCRIPTOR (ProcessName2FaoDsc, "!#AZ!AZ!4XL");
   static $DESCRIPTOR (ProcessName3FaoDsc, "/!#AZ!AZ!4XL");
   static $DESCRIPTOR (ProcessNameDsc, "");
   static struct dsc$descriptor_s  *dscptr;

   int  ilen, pronum, status,
        SetPrvStatus;
   ushort  slen;
   char  *cptr, *faoptr, *sptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclNameProcess() !8XL", tkptr->ScriptProcessPid);

   dscptr = &ProcessNameDsc;

   /* if initial (and historical) process name */
   if (!tkptr->ScriptProcessPid)
   {
      /* script processes are consecutively numbered from 1..999 */
      dscptr->dsc$a_pointer = tkptr->PrcNamDefault;
      dscptr->dsc$w_length = sizeof(tkptr->PrcNamDefault)-1;
      pronum = ProcessNumber++ % 1000;
      if (!pronum) pronum++;
      cptr = HttpdProcess.PrcNam;
      if (HttpdProcess.PrcNamLength >= 12)
         cptr += HttpdProcess.PrcNamLength - 12;
      sys$fao (&ProcessName1FaoDsc, &slen, dscptr, cptr, pronum);
      dscptr->dsc$a_pointer[dscptr->dsc$w_length = slen] = '\0';
      return (dscptr);
   }

   if (DclNameProcessPre12) return (NULL);

   if (!tkptr->ProcessNamePid)
   {
      /* sentinal to indicate the name includes the PID */
      tkptr->ProcessNamePid = tkptr->ScriptProcessPid;
      /* set the process name to include the PID */
      dscptr->dsc$a_pointer = tkptr->PrcNamDefault;
      dscptr->dsc$w_length = sizeof(tkptr->PrcNamDefault)-1;
      cptr = HttpdProcess.PrcNam;
      if ((ilen = HttpdProcess.PrcNamLength) > 10)
         cptr += HttpdProcess.PrcNamLength - (ilen = 10);
      sptr = "_";
      sys$fao (&ProcessName2FaoDsc, &slen, dscptr, ilen, cptr, sptr,
               tkptr->ScriptProcessPid & 0xffff);
      dscptr->dsc$a_pointer[dscptr->dsc$w_length = slen] = '\0';
      return (NULL);
   }

   if (tkptr->TaskType == DCL_TASK_TYPE_CLI)
   {
      strcpy (tkptr->PrcNamActive, tkptr->PrcNamDefault);
      for (cptr = tkptr->PrcNamActive; *cptr && *cptr != '_'; cptr++);
      if (*cptr) *cptr = '$';
      return (NULL);
   }

   /* set the process name to represent the current script */
   dscptr->dsc$a_pointer = tkptr->PrcNamActive;
   dscptr->dsc$w_length = sizeof(tkptr->PrcNamActive)-1;

   if (tkptr->TaskType == DCL_TASK_TYPE_CGI_SCRIPT ||
       tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT)
   {
      for (cptr = tkptr->ScriptName; *cptr; cptr++);
      while (cptr > tkptr->ScriptName && *(cptr-1) != '/') cptr--;
      if ((ilen = strlen(cptr)) > 9) ilen = 9;
      if (tkptr->TaskType == DCL_TASK_TYPE_CGI_SCRIPT)
         sptr = "_";
      else
      if (tkptr->RequestPtr && tkptr->RequestPtr->WebSocketRequest)
         sptr = "~";
      else
         sptr = "+";
      faoptr = &ProcessName3FaoDsc;
   }
   else
   if (tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
   {
      for (cptr = tkptr->ScriptRunTimePtr; *cptr; cptr++);
      for (sptr = cptr;
           cptr-1 > tkptr->ScriptRunTimePtr && *(cptr-1) != ']';
           cptr--);
      if (*(cptr-1) != ']')
         for (cptr = sptr;
              cptr-1 > tkptr->ScriptRunTimePtr && *(cptr-1) != ':';
              cptr--);
      for (sptr = cptr; *sptr && *sptr != '.'; sptr++);
      if ((ilen = (sptr - cptr)) > 9) ilen = 9;
      sptr = "=";
      faoptr = &ProcessName3FaoDsc;
   }
   else
   {
      cptr = "BUGCHECK";
      sptr = "_";
      faoptr = &ProcessName2FaoDsc;
   }

   sys$fao (faoptr, &slen, dscptr, ilen, cptr, sptr,
            tkptr->ScriptProcessPid & 0xffff);
   dscptr->dsc$a_pointer[dscptr->dsc$w_length = slen] = '\0';
   return (NULL);
}

/*****************************************************************************/
/*
Delete the scripting process.
*/

int DclDeleteProcess (DCL_TASK *tkptr)

{
   int  status,
        SetPrvStatus;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclDeleteProcess() !8XL", tkptr->ScriptProcessPid);

   if (!tkptr->ScriptProcessPid) return (SS$_BUGCHECK);

   /* need WORLD privilege if process created under another username */
   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (1, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   status = sys$delprc (&tkptr->ScriptProcessPid, 0);
   if (VMSnok (status))
   {
      if (status == SS$_NONEXPR)
         tkptr->ScriptProcessPid = 0;
      else
         ErrorNoticed (NULL, status, "!8XL", FI_LI, tkptr->ScriptProcessPid); 
   }
   InstanceGblSecIncrLong (&AccountingPtr->DclDelPrcCount);

   if (tkptr->CrePrcUserName[0])
      if (VMSnok (SetPrvStatus = sys$setprv (0, &WorldMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   if (VMSok (status))
      if WATCH_CATEGORY(WATCH_DCL)
         WatchThis (WATCHITM(tkptr), WATCH_DCL,
                    "DELPRC pid:!8XL", tkptr->ScriptProcessPid);

   return (status);
}

/*****************************************************************************/
/*
This AST is called when the script processes exits.
*/

DclScriptProcessCompletionAST (DCL_TASK *tkptr)

{
   int  status;
   REQUEST_STRUCT  *rqeptr;
   LIST_ENTRY  *leptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
"DclScriptProcessCompletionAST() !&F !&S !8XL !4XL \'!12AZ\' !&S",
         &DclScriptProcessCompletionAST,
         tkptr->CrePrcTermMbxIOsb.Status,
         tkptr->ScriptProcessPid,
         tkptr->CrePrcTermRecord.acc$w_msgtyp,
         tkptr->CrePrcTermRecord.acc$t_username,
         tkptr->CrePrcTermRecord.acc$l_finalsts);

   if (VMSnok (tkptr->CrePrcTermMbxIOsb.Status))
   {
      if WATCH_CATEGORY(WATCH_DCL)
         WatchThis (WATCHITM(tkptr), WATCH_DCL,
                    "TERMINATION-MBX !8XL !&S",
                    tkptr->ScriptProcessPid,
                    tkptr->CrePrcTermMbxIOsb.Status);
      ErrorNoticed (NULL, tkptr->CrePrcTermMbxIOsb.Status,
                    "DclScriptProcessCompletionAST", FI_LI);
   }

   if WATCH_CATEGORY(WATCH_DCL)
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "!AZ completion pid:!8XL !&S",
                 DclScriptDetachProcess ? "DETACHED" : "SUBPROCESS",
                 tkptr->ScriptProcessPid,
                 tkptr->CrePrcTermRecord.acc$l_finalsts);

   /* ensure SYS$COMMAND gets emptied! */
   tkptr->QueuedSysCommandAllowed = 0;

   /* won't be getting anymore output from this process! */
   status = sys$qio (EfnNoWait, tkptr->SysOutputChannel,
                     IO$_WRITEOF | IO$M_NORSWAIT, 0, 0, 0,
                     0, 0, 0, 0, 0, 0);

   if (DclProctorEnabled)
   {
      if (tkptr->ProctorPtr)
      {
         /* the failure algorithm is faster to fail, slower to re-allow */
         if (tkptr->ProctorPtr->FailWeight)
         {
            if (tkptr->ProctorPtr->FailWeight < PROCTOR_FAIL_AT)
            {
               /* not yet in failure mode */
               tkptr->ProctorPtr->FailWeight = tkptr->ProctorPtr->FailWeight *
                                               tkptr->ProctorPtr->FailWeight;
               /* if just moved into failure mode */
               if (tkptr->ProctorPtr->FailWeight >= PROCTOR_FAIL_AT)
                  DclScriptProctorReportFail (tkptr->ProctorPtr,
                                              "process exit %X!8XL",  
                                              tkptr->CrePrcTermMbxIOsb.Status);
            }
            else
               tkptr->ProctorPtr->FailWeight = tkptr->ProctorPtr->FailWeight *
                                               tkptr->ProctorPtr->FailWeight;
         }
         else
            tkptr->ProctorPtr->FailWeight = PROCTOR_FAIL_BASE;

         /* only immediately reproctor for the first few attempts */
         if (tkptr->ProctorPtr->FailWeight < PROCTOR_FAIL_AT)
            SysDclAst (&DclScriptProctor, NULL);
      }
      else
         SysDclAst (&DclScriptProctor, NULL);
   }

   /* scan the web socket list for matching requests */
   for (leptr = WebSockList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      rqeptr = ((struct RequestWebSocketStruct*)leptr)->RequestPtr;

      /* if the WebSocket associated process is not this task */
      if (rqeptr->rqWebSocket.ScriptProcessPid != tkptr->ScriptProcessPid)
         continue;

      /* if this request is currently directly associated with the task */
      if (rqeptr == tkptr->RequestPtr) continue;

      if (WATCHMOD (tkptr, WATCH_MOD_DCL))
         WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL, "ws:!8XL", rqeptr);

      /* make the closure asynchronous to this list traversal */
      SysDclAst (WebSockClose, rqeptr);
   }

   /* no longer marked for delete (if it was), set PID and lifetime to zero */
   tkptr->BuildRecords =
      tkptr->ScriptCpuTimGetJpi =
      tkptr->DeleteProcess =
      tkptr->ForceImageExit =
      tkptr->ForceImageExitGetJpi =
      tkptr->ForceImageExitIssued = false;
   tkptr->ForceImageExitSecond =
      tkptr->JpiCpuTimIOsb.Status =
      tkptr->JpiImagNameIOsb.Status =
      tkptr->JpiImagNameLength =
      tkptr->LifeTimeSecond =
      tkptr->ScriptCpuMax =
      tkptr->ScriptCpuTimMax =
      tkptr->ScriptProcessPid = 
      tkptr->SysOutputBuildCount =
      tkptr->TaskRunDown = 0;
   tkptr->CrePrcUserName[0] = '\0';

   /* keep track of how many script processes are executing */
   if (DclCurrentScriptProcess) DclCurrentScriptProcess--;

   DclCountScriptProcess ();

   /* ensure any old sequence strings are not reused */
   tkptr->CgiBel[0] =
      tkptr->CgiEof[0] =
      tkptr->CgiEot[0] =
      tkptr->CgiEsc[0] = '\0';
   tkptr->CgiBelLength =
      tkptr->CgiEofLength =
      tkptr->CgiEotLength =
      tkptr->CgiEscLength = 0;

   DclTaskRunDown (tkptr);
}

/*****************************************************************************/
/*
If a script application writes any output before it was/is terminated that
output will still be laying unread in the mailbox.  Clear any such noise lest
it be read by the next script process to use the mailbox.  Does this
synchronously (i.e. with QIO waits).
*/

DclEmptySysOutput (DCL_TASK *tkptr)

{
   int  status,
        LastMessageCount;
   struct MbxSenseIOsb  SenseIOsb;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclEmptySysOutput() !UL !UL",
                 tkptr->SysOutputChannel, tkptr->QueuedSysOutput);

   LastMessageCount = 999999999;
   SenseIOsb.MessageCount = 0;

   if (!tkptr->SysOutputChannel) return;
   if (!tkptr->QueuedSysOutput) return;

   for (;;)
   {
      status = sys$qiow (EfnWait, tkptr->SysOutputChannel,
                         IO$_SENSEMODE, &SenseIOsb, 0, 0, 0, 0, 0, 0, 0, 0);
      if (VMSok (status)) status = SenseIOsb.Status;
      if (VMSnok (status)) ErrorExitVmsStatus (status, NULL, FI_LI);

      if (!SenseIOsb.MessageCount) break;
      /* potential infinite loop, check message count is decreasing! */
      if (LastMessageCount <= SenseIOsb.MessageCount) break;
      LastMessageCount = SenseIOsb.MessageCount;

      sys$qiow (EfnWait, tkptr->SysOutputChannel,
                IO$_READLBLK, &tkptr->SysOutputIOsb, 0, 0,
                tkptr->SysOutputPtr, tkptr->SysOutputSize, 0, 0, 0, 0);
   }

   tkptr->QueuedSysOutput = 0;
}

/*****************************************************************************/
/*
If an error is encountered an error message is generated and the error status
returned.  It is up to the calling routine to abort the processing.  Create
four mailboxes that will be associated with the script process I/O streams. If
an error occurs any mailbox created up to that point is deleted and the
channel set back to zero.
*/ 

#define DVI$_DEVNAM 32
#define DVI$_UNIT 12

DclCreateMailboxes (DCL_TASK *tkptr)

{
   static unsigned long  DevNamItem = DVI$_DEVNAM,
                         UnitItem = DVI$_UNIT;

   int  status;
   unsigned short  Length;
   unsigned long  BytLmAfter,
                  BytLmBefore,
                  LongUnit;
   struct dsc$descriptor_s  *dscptr;

   /*********/
   /* begin */
   /*********/

   BytLmBefore = GetJpiBytLm ();

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclCreateMailboxes() !UL !UL",
                 BytLmBefore, DclMailboxBytLmRequired);

   /* ensure we're leaving enough BYTLM for client socket creation at least */
   if (DclMailboxBytLmRequired &&
       BytLmBefore - DclMailboxBytLmRequired <=
       NetAcceptBytLmRequired * Config.cfServer.ProcessMax)
   {
      ErrorNoticed (NULL, 0, "BYTLM exhausted", FI_LI);
      return (SS$_EXQUOTA);
   }

   tkptr->CgiPlusInChannel =
      tkptr->CrePrcTermMbxChannel =
      tkptr->HttpInputChannel =
      tkptr->SysCommandChannel =
      tkptr->SysOutputChannel = 0;

   /***********************/
   /* SYS$COMMAND mailbox */
   /***********************/

   if (VMSnok (status =
       sys$crembx (0,
                   &tkptr->SysCommandChannel,
                   DclSysCommandSize, DclSysCommandSize,
                   DCL_PROCESS_MBX_PROT_MASK,
                   0, 0, CMB$M_WRITEONLY)))
      goto DclCreateMailBoxesError;

   dscptr = &tkptr->SysCommandDevNameDsc;
   dscptr->dsc$w_length = sizeof(tkptr->SysCommandDevName);
   dscptr->dsc$a_pointer = tkptr->SysCommandDevName;
   dscptr->dsc$b_class = DSC$K_CLASS_S;
   dscptr->dsc$b_dtype = DSC$K_DTYPE_T;

   if (VMSnok (status =
       lib$getdvi (&DevNamItem, &tkptr->SysCommandChannel,
                   0, 0, &tkptr->SysCommandDevNameDsc, &Length)))
      goto DclCreateMailBoxesError;
   tkptr->SysCommandDevName[dscptr->dsc$w_length = Length] = '\0';

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "$CREMBX() SYS$COMMAND !AZ !UL",
                 tkptr->SysCommandDevName, DclSysCommandSize);

   /**********************/
   /* SYS$OUTPUT mailbox */
   /**********************/

   if (VMSnok (status =
       sys$crembx (0,
                   &tkptr->SysOutputChannel,
                   DclSysOutputSize, DclSysOutputSize,
                   DCL_PROCESS_MBX_PROT_MASK,
                   0, 0, 0)))
      goto DclCreateMailBoxesError;

   dscptr = &tkptr->SysOutputDevNameDsc;
   dscptr->dsc$w_length = sizeof(tkptr->SysOutputDevName);
   dscptr->dsc$a_pointer = tkptr->SysOutputDevName;
   dscptr->dsc$b_class = DSC$K_CLASS_S;
   dscptr->dsc$b_dtype = DSC$K_DTYPE_T;

   if (VMSnok (status =
       lib$getdvi (&DevNamItem, &tkptr->SysOutputChannel,
                   0, 0, &tkptr->SysOutputDevNameDsc, &Length)))
      goto DclCreateMailBoxesError;
   tkptr->SysOutputDevName [dscptr->dsc$w_length = Length] = '\0';

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "$CREMBX() SYS$OUTPUT !AZ !UL",
                 tkptr->SysOutputDevName, DclSysOutputSize);

   /*********************/
   /* CGIPLUSIN mailbox */
   /*********************/

   if (VMSnok (status =
       sys$crembx (0,
                   &tkptr->CgiPlusInChannel,
                   DclCgiPlusInSize, DclCgiPlusInSize,
                   DCL_PROCESS_MBX_PROT_MASK,
                   0, 0, CMB$M_WRITEONLY)))
      goto DclCreateMailBoxesError;

   dscptr = &tkptr->CgiPlusInDevNameDsc;
   dscptr->dsc$w_length = sizeof(tkptr->CgiPlusInDevName);
   dscptr->dsc$a_pointer = tkptr->CgiPlusInDevName;
   dscptr->dsc$b_class = DSC$K_CLASS_S;
   dscptr->dsc$b_dtype = DSC$K_DTYPE_T;

   if (VMSnok (status =
       lib$getdvi (&DevNamItem, &tkptr->CgiPlusInChannel,
                   0, 0, &tkptr->CgiPlusInDevNameDsc, &Length)))
      goto DclCreateMailBoxesError;
   tkptr->CgiPlusInDevName[dscptr->dsc$w_length = Length] = '\0';

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "$CREMBX() CGIPLUSIN !AZ !UL",
                 tkptr->CgiPlusInDevName, DclCgiPlusInSize);

   /**********************/
   /* HTTP$INPUT mailbox */
   /**********************/

   if (VMSnok (status =
       sys$crembx (0,
                   &tkptr->HttpInputChannel,
                   NetReadBufferSize, NetReadBufferSize,
                   DCL_PROCESS_MBX_PROT_MASK,
                   0, 0, CMB$M_WRITEONLY)))
      goto DclCreateMailBoxesError;

   dscptr = &tkptr->HttpInputDevNameDsc;
   dscptr->dsc$w_length = sizeof(tkptr->HttpInputDevName);
   dscptr->dsc$a_pointer = tkptr->HttpInputDevName;
   dscptr->dsc$b_class = DSC$K_CLASS_S;
   dscptr->dsc$b_dtype = DSC$K_DTYPE_T;

   if (VMSnok (status =
       lib$getdvi (&DevNamItem, &tkptr->HttpInputChannel,
                   0, 0, &tkptr->HttpInputDevNameDsc, &Length)))
      goto DclCreateMailBoxesError;
   tkptr->HttpInputDevName[dscptr->dsc$w_length = Length] = '\0';

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "$CREMBX() HTTP$INPUT !AZ !UL",
                 tkptr->HttpInputDevName, NetReadBufferSize);

   /************************************/
   /* SYS$CREPRC() termination mailbox */
   /************************************/

   if (VMSnok (status =
       sys$crembx (0,
                   &tkptr->CrePrcTermMbxChannel,
                   sizeof(DCL_CREPRC_TERM),
                   sizeof(DCL_CREPRC_TERM),
                   0xff00,  /* no world or group access */
                   0, 0, CMB$M_READONLY)))
      goto DclCreateMailBoxesError;

   dscptr = &tkptr->CrePrcTermMbxDevNameDsc;
   dscptr->dsc$w_length = sizeof(tkptr->CrePrcTermMbxDevName);
   dscptr->dsc$a_pointer = tkptr->CrePrcTermMbxDevName;
   dscptr->dsc$b_class = DSC$K_CLASS_S;
   dscptr->dsc$b_dtype = DSC$K_DTYPE_T;

   status = lib$getdvi (&DevNamItem, &tkptr->CrePrcTermMbxChannel,
                        0, 0, &tkptr->CrePrcTermMbxDevNameDsc, &Length);
   if (VMSok (status))
      status = lib$getdvi (&UnitItem, &tkptr->CrePrcTermMbxChannel,
                           0, &LongUnit, 0, 0);
   if (VMSnok (status)) goto DclCreateMailBoxesError;

   /* lib$getdvi() requires 32 bit longs, the mailbox unit is only 16 bits */
   tkptr->CrePrcTermMbxUnit = (unsigned short)LongUnit;
   tkptr->CrePrcTermMbxDevName[dscptr->dsc$w_length = Length] = '\0';

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "$CREMBX() TERMINATION !AZ unit:!UL",
                 tkptr->CrePrcTermMbxDevName, tkptr->CrePrcTermMbxUnit);

   /******/
   /* OK */
   /******/

   if (!DclMailboxBytLmRequired)
   {
      BytLmAfter = GetJpiBytLm ();
      DclMailboxBytLmRequired = BytLmBefore - BytLmAfter;
      if (WATCH_MODULE(WATCH_MOD_DCL))
         WatchThis (WATCHALL, WATCH_MOD_DCL, "BytLm: !UL",
                    DclMailboxBytLmRequired);
   }

   return (SS$_NORMAL);

   /*********/
   /* ERROR */
   /*********/

DclCreateMailBoxesError:

   ErrorNoticed (NULL, status, "$CREMBX()", FI_LI);

   if (tkptr->CgiPlusInChannel) sys$dassgn (tkptr->CgiPlusInChannel);
   if (tkptr->CrePrcTermMbxChannel) sys$dassgn (tkptr->CrePrcTermMbxChannel);
   if (tkptr->HttpInputChannel) sys$dassgn (tkptr->HttpInputChannel);
   if (tkptr->SysCommandChannel) sys$dassgn (tkptr->SysCommandChannel);
   if (tkptr->SysOutputChannel) sys$dassgn (tkptr->SysOutputChannel);
   tkptr->CrePrcTermMbxChannel =
      tkptr->CgiPlusInChannel =
      tkptr->HttpInputChannel =
      tkptr->SysCommandChannel =
      tkptr->SysOutputChannel = 0;

   return (status);
}

/*****************************************************************************/
/*
Queue up a read from the script process "SYS$OUTPUT" mailbox.  When the read 
completes call function DclSysOutputAst(), do any post-processing required and
write the data to the client over the network.  The next read from the script
process via the mailbox will be queued by the network write completion AST
function.
*/ 

DclQioSysOutput (DCL_TASK *tkptr)

{
   int  status;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclQioSysOutput() !8XL", tkptr->ScriptProcessPid);

   tkptr->QueuedSysOutput++;

   if (tkptr->RequestPtr)
      if (tkptr->RequestPtr->RequestState >= REQUEST_STATE_ABORT)
      {
         tkptr->SysOutputIOsb.Status = SS$_ABORT;
         tkptr->SysOutputIOsb.Count = 0;
         SysDclAst (&DclSysOutputAst, tkptr);
         return;
      }

   status = sys$qio (EfnNoWait, tkptr->SysOutputChannel,
                     IO$_READLBLK, &tkptr->SysOutputIOsb,
                     &DclSysOutputAst, tkptr,
                     tkptr->SysOutputPtr, tkptr->SysOutputSize,
                     0, 0, 0, 0);

   if (VMSok (status)) return;

   /* report error via the AST */
   tkptr->SysOutputIOsb.Status = status;
   SysDclAst (&DclSysOutputAst, tkptr);
}

/*****************************************************************************/
/*
A queued asynchronous read from the script process "SYS$OUTPUT" mailbox has 
completed.  For 'build-records' mode see description in module prologue.
*/ 

DclSysOutputAst (DCL_TASK *tkptr)

{
   int  cnt, status, value;
   char  *cptr;
   REQUEST_STRUCT  *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
         "DclSysOutputAst() !&F !8XL !UL !UL !UL !UL !UL !UL !UL !&S",
         &DclSysOutputAst, tkptr->ScriptProcessPid, tkptr->QueuedSysCommand,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         tkptr->SysOutputIOsb.Count, tkptr->SysOutputIOsb.Status);

   if (tkptr->QueuedSysOutput) tkptr->QueuedSysOutput--;

   if (WATCHING (tkptr, WATCH_DCL))
   {
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "READ SYS$OUTPUT !&S !UL byte!%s",
                 tkptr->SysOutputIOsb.Status,
                 tkptr->SysOutputIOsb.Count);
      if (tkptr->SysOutputIOsb.Count)
      {
         if (tkptr->BuildRecords)
            WatchDataDump (tkptr->SysOutputPtr+tkptr->SysOutputBuildCount,
                           tkptr->SysOutputIOsb.Count);
         else
            WatchDataDump (tkptr->SysOutputPtr,
                           tkptr->SysOutputIOsb.Count);
      }
   }

   if (!(rqptr = tkptr->RequestPtr))
   {
      /* request is no longer attached */
      cptr = tkptr->SysOutputPtr;
      cnt = tkptr->SysOutputIOsb.Count;
      cptr[cnt] = '\0';

      if (tkptr->CgiEofLength &&
          cnt >= tkptr->CgiEofLength &&
          cnt <= tkptr->CgiEofLength+2 &&
          MATCH0 (cptr, tkptr->CgiEof, tkptr->CgiEofLength))
      {
         /* end of output from script! */
         DclTaskRunDown (tkptr);
      }
      else
      {
         /* just queue the next read */
         DclQioSysOutput (tkptr);
      }
      return;
   }

   if (ERROR_REPORTED(rqptr) && !ERROR_REPORTED_BY_SCRIPT(rqptr))
   {
      if (!tkptr->WatchNonCgiCompliant)
      {
         /* an opportune point to report any error generated elsewhere */
         tkptr->DeleteProcess = true;
         DclTaskRunDown (tkptr);
         return;
      }
   }

   if (tkptr->SysOutputIOsb.Status == SS$_ENDOFFILE)
   {
      if (!tkptr->ScriptProcessPid)
      {
         /* script process has already concluded, must be the last gasp! */
         DclTaskRunDown (tkptr);
         return;
      }

      /* 
          If a script spawns multiple script processes each will
          terminate by queueing an end-of-file.  Ignore these.
          Queue the next read of the script process' SYS$OUTPUT.
          The CRTL outputs an end-of-file for a zero-length record.
          Put a count on the maximum number of these before the
          script is considered to be misbehaving.
      */
      if (tkptr->SysOutputEndOfFileCount++ > DCL_SCRIPT_MAX_ENDOFFILE)
      {
         tkptr->RequestPtr->rqResponse.HttpStatus = 502;
         ErrorGeneral (tkptr->RequestPtr,
            MsgFor(tkptr->RequestPtr,MSG_SCRIPT_RESPONSE_ERROR), FI_LI);
         tkptr->DeleteProcess = true;
         DclTaskRunDown (tkptr);
         return;
      }

      DclQioSysOutput (tkptr);
      return;
   }

   if (tkptr->ViaSysOutputStatus)
      tkptr->SysOutputIOsb.Status = tkptr->ViaSysOutputStatus;

   if (VMSnok (tkptr->SysOutputIOsb.Status))
   {
      if (tkptr->SysOutputIOsb.Status == SS$_ABORT ||
          tkptr->SysOutputIOsb.Status == SS$_CANCEL)
      {
         tkptr->DeleteProcess = true;
         DclTaskRunDown (tkptr);
         return;
      }

      rqptr->rqResponse.ErrorTextPtr = MsgFor(rqptr,MSG_SCRIPT_IPC);
      ErrorVmsStatus (rqptr, tkptr->SysOutputIOsb.Status, FI_LI);

      tkptr->DeleteProcess = true;
      DclTaskRunDown (tkptr);
      return;
   }

   /*************/
   /* status OK */
   /*************/

   if (tkptr->CrePrcDetachStarting)
   {
      cptr = tkptr->SysOutputPtr;
      cnt = tkptr->SysOutputIOsb.Count;
      cptr[cnt] = '\0';

      if (cnt >= tkptr->CgiBelLength &&
          cnt <= tkptr->CgiBelLength+2 &&
          MATCH0 (cptr, tkptr->CgiBel, tkptr->CgiBelLength))
      {
         tkptr->CrePrcDetachStarting = false;
         /* reset CGI output processing */
         CgiOutput (rqptr, NULL, 0);

         if (WATCHING (tkptr, WATCH_DCL))
            WatchThis (WATCHITM(tkptr), WATCH_DCL, "DETACHED process ready");
      }

      /* absorb this, just queue the next read */
      DclQioSysOutput (tkptr);
      return;
   }

   if (!tkptr->ScriptProcessResponded)
   {
      /*********************/
      /* finally it's true */
      /*********************/

      tkptr->ScriptProcessResponded = true;
      if (tkptr->SysOutputIOsb.Count == 1)
      {
         /* hmmm, one byte only - start 'building records'! */
         tkptr->BuildRecords = true;
         if (WATCHING (tkptr, WATCH_DCL))
            WatchThis (WATCHITM(tkptr), WATCH_DCL, "BUILD records");
      }
   }

   if (tkptr->BuildRecords)
   {
      /*****************************************/
      /* building 'records' from single bytes! */
      /*****************************************/

      cptr = tkptr->SysOutputPtr + tkptr->SysOutputBuildCount;

      if (tkptr->SysOutputIOsb.Count)
      {
         tkptr->SysOutputBuildCount += tkptr->SysOutputIOsb.Count; 
         cnt = tkptr->SysOutputSize - tkptr->SysOutputBuildCount;

         if (tkptr->SysOutputIOsb.Count == 1 &&
             *cptr != '\n' && cnt > 0)
         {
            /* not a newline and still space in the buffer */
            tkptr->QueuedSysOutput++;
            status = sys$qio (EfnNoWait, tkptr->SysOutputChannel,
                              IO$_READLBLK, &tkptr->SysOutputIOsb,
                              &DclSysOutputAst, tkptr, cptr+1, cnt,
                              0, 0, 0, 0);
            if (VMSok (status)) return;
            /* report error via the AST */
            tkptr->SysOutputIOsb.Status = status;
            SysDclAst (&DclSysOutputAst, tkptr);
            return;
         }
      }
      else
      {
         *cptr = '\n';
         tkptr->SysOutputBuildCount++;
      }

      /* newline, zero bytes, multiple bytes, or out of buffer space */
      tkptr->SysOutputIOsb.Count = tkptr->SysOutputBuildCount;
      tkptr->SysOutputBuildCount = 0;

      if (WATCHING (tkptr, WATCH_DCL))
      {
         WatchThis (WATCHITM(tkptr), WATCH_DCL,
                    "BUILT record !UL byte!%s", tkptr->SysOutputIOsb.Count);
         WatchDataDump (tkptr->SysOutputPtr, tkptr->SysOutputIOsb.Count);
      }
   }

   /******************/
   /* process record */
   /******************/

   cptr = tkptr->SysOutputPtr;
   cnt = tkptr->SysOutputIOsb.Count;
   cptr[cnt] = '\0';

   if (tkptr->WatchNonCgiCompliant)
   {
      if (rqptr->rqCgi.EofLength &&
          cnt >= rqptr->rqCgi.EofLength &&
          cnt <= rqptr->rqCgi.EofLength+2 &&
          MATCH0 (cptr, rqptr->rqCgi.EofStr, rqptr->rqCgi.EofLength))
      {
         /* end of output from script! */
         tkptr->DeleteProcess = true;
         value = CGI_OUTPUT_END;
      }
      else
      {
         /* just queue the next read */
         DclQioSysOutput (tkptr);
         return;
      }
   }
   else
      value = CgiOutput (rqptr, tkptr->SysOutputPtr,
                                tkptr->SysOutputIOsb.Count);

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL, "!SL", value);

   switch (value)
   {
      case CGI_OUTPUT_END :

         if (!rqptr->AgentRequestPtr &&
             rqptr->WebSocketRequest)
         {
            /* disassociate the DCL task and request structures */
            tkptr->RequestPtr->DclTaskPtr = NULL;
            tkptr->RequestPtr = tkptr->NextTaskFunction = NULL;
            WebSockIfEnd (rqptr);
            /* WebSocket throttling is a request startup activity only */
            if (rqptr->rqPathSet.ThrottleSet) ThrottleEnd (rqptr);
         }

         /* terminate processing */
         DclTaskRunDown (tkptr);

         if (rqptr->rqCgi.CalloutInProgress)
         {
            if (WATCHING (tkptr, WATCH_DCL))
               WatchThis (WATCHITM(rqptr), WATCH_DCL, "CALLOUT end");

            /* script didn't send an EOT, let callable function know now! */
            rqptr->rqCgi.CalloutInProgress = false;

            /* the NULL and zero bytes indicates transaction end */
            rqptr->rqCgi.CalloutOutputPtr = NULL;
            rqptr->rqCgi.CalloutOutputCount = 0;

            /* execute the callout function */
            (*tkptr->CalloutFunction)(rqptr);
         }

         if (rqptr->AgentRequestPtr)
         {
            if (!rqptr->AgentResponsePtr)
            {
               /* agent request without agent response */
               rqptr->rqResponse.HttpStatus = 502;
               ErrorGeneral (rqptr, MsgFor(rqptr,MSG_SCRIPT_RESPONSE_ERROR), FI_LI);
               ErrorNoticed (rqptr, SS$_BUGCHECK, tkptr->ScriptName, FI_LI);
            }
         }
         if (rqptr->AgentResponsePtr)
         {
            if (!rqptr->AgentRequestPtr)
            {
               /* agent response without agent request */
               rqptr->rqResponse.HttpStatus = 502;
               ErrorGeneral (rqptr, MsgFor(rqptr,MSG_SCRIPT_RESPONSE_ERROR), FI_LI);
               ErrorNoticed (rqptr, SS$_BUGCHECK, tkptr->ScriptName, FI_LI);
            }
         }

         return;

      case CGI_OUTPUT_NOT_STRICT :

         /* not strictly CGI compliant, report and terminate processing */
         if (rqptr->AgentRequestPtr)
         {
            if (((void*)tkptr->CalloutFunction == (void*)&AuthAgentCallout))
               AuthAgentCalloutResponseError (rqptr);
         }
         else
         {
            tkptr->RequestPtr->rqResponse.HttpStatus = 502;
            ErrorGeneral (tkptr->RequestPtr,
               MsgFor(tkptr->RequestPtr,MSG_SCRIPT_RESPONSE_ERROR), FI_LI);
         }

         if (WATCHING (tkptr, WATCH_DCL))
         {
            /* continue to conclusion while bit-bucketing the output */
            tkptr->WatchNonCgiCompliant = true;
            /* reset CGI output processing */
            CgiOutput (rqptr, NULL, 0);
            /* just queue the next read */
            DclQioSysOutput (tkptr);
            return;
         }

         tkptr->DeleteProcess = true;
         DclTaskRunDown (tkptr);
         return;

      case CGI_OUTPUT_ESCAPE_BEGIN :

         /* start talking direct to the server */
         if (WATCHING (tkptr, WATCH_DCL))
            WatchThis (WATCHITM(rqptr), WATCH_DCL, "CALLOUT begin");

         rqptr->rqCgi.CalloutInProgress = true;

         /* the NULL and minus one bytes indicates transaction begin */
         rqptr->rqCgi.CalloutOutputPtr = NULL;
         rqptr->rqCgi.CalloutOutputCount = -1;

         /* execute the callout function */
         (*tkptr->CalloutFunction)(rqptr);

         DclQioSysOutput (tkptr);
         return;

      case CGI_OUTPUT_ESCAPE :

         /* the script is talking direct to the server */
         rqptr->rqCgi.CalloutOutputPtr = tkptr->SysOutputPtr;
         rqptr->rqCgi.CalloutOutputCount = tkptr->SysOutputIOsb.Count;

         if (WATCHING (tkptr, WATCH_DCL))
         {
            WatchThis (WATCHITM(rqptr), WATCH_DCL,
                       "CALLOUT !UL bytes",
                       rqptr->rqCgi.CalloutOutputCount);
            if (rqptr->rqCgi.CalloutOutputCount)
               WatchDataDump (rqptr->rqCgi.CalloutOutputPtr,
                              rqptr->rqCgi.CalloutOutputCount);
         }

         /* execute the callout function */
         (*tkptr->CalloutFunction)(rqptr);

         DclQioSysOutput (tkptr);
         return;

      case CGI_OUTPUT_ESCAPE_END :

         if (WATCHING (tkptr, WATCH_DCL))
            WatchThis (WATCHITM(rqptr), WATCH_DCL, "CALLOUT end");

         /* end talking direct to the server */
         rqptr->rqCgi.CalloutInProgress = false;

         /* the NULL and zero bytes indicates transaction end */
         rqptr->rqCgi.CalloutOutputPtr = NULL;
         rqptr->rqCgi.CalloutOutputCount = 0;

         /* execute the callout function */
         (*tkptr->CalloutFunction)(rqptr);

         if (rqptr->rqPathSet.CgiPlusInWriteof)
            DclQioCgiPlusIn (tkptr, NULL, 0);

         DclQioSysOutput (tkptr);
         return;

      case CGI_OUTPUT_RAW :

         /* just write the record */
         tkptr->QueuedClientOutput++;
         NetWrite (rqptr, &DclSysOutputToClientAst, cptr, value);
         return;

      default :

         if (value)
         {
            if (tkptr->NextTaskFunction == &DclScriptProctorAst)
            {
               /* absorb proctored output (saves the invalid network I/O) */
               value = 0;
            }
            else
            if (!rqptr->AgentRequestPtr &&
                rqptr->WebSocketRequest)
            {
               /* WebSocket scripts should provide nothing via <stdout> */
               if (WATCHING (tkptr, WATCH_DCL))
                  WatchThis (WATCHITM(tkptr), WATCH_DCL,
                             "WEBSOCKET any SYS$OUTPUT is an ERROR!!");
               value = 0;
            }
            else
            if (ERROR_REPORTED_BY_SCRIPT(rqptr))
            {
               /* when "Script-Control: x-error..." output nothing */
               value = 0;
            }
         }

         if (tkptr->ClientWriteErrorCount)
         {
            /* no need to REALLY write it if there's been an error! */
            rqptr->NetIoPtr->WriteStatus = rqptr->rqNet.WriteErrorStatus;
            tkptr->QueuedClientOutput++;
            SysDclAst (&DclSysOutputToClientAst, rqptr);
            return;
         }

         if (!value)
         {
            /* output all absorbed, just queue the next read */
            DclQioSysOutput (tkptr);
            return;
         }

         if (rqptr->rqCgi.BufferRecords || rqptr->rqCgi.IsCliDcl)
         {
            /* buffer the record */
            tkptr->QueuedClientOutput++;
            NetWriteBuffered (rqptr, &DclSysOutputToClientAst, cptr, value);
            return;
         }

         /* write the record */
         tkptr->QueuedClientOutput++;
         NetWrite (rqptr, &DclSysOutputToClientAst, cptr, value);
         return;
   }
}

/*****************************************************************************/
/*
************
*** NOTE ***  This function takes a pointer to a request!!!
************  Due to is being an AST from a general network write function.

A queued asynchronous write of script process SYS$OUTPUT (mailbox) to the
client over the network has completed.  When the bit-bucket timeout is set or
do-not-disturb is set this is ignored (at least for the present) and the script
is allowed to continue.  For others just abort the script.
*/ 

DclSysOutputToClientAst (REQUEST_STRUCT *rqptr)

{
   int  status;
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   /* get a pointer to the DCL task from the request structure */
   tkptr = rqptr->DclTaskPtr;

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
"DclSysOutputToClientAst() !&F !8XL !UL !UL !UL !UL !UL !UL !&S !&S",
         &DclSysOutputToClientAst,
         tkptr->ScriptProcessPid, tkptr->QueuedSysCommand,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         tkptr->SysOutputIOsb.Status, rqptr->NetIoPtr->WriteStatus);

   if (tkptr->QueuedClientOutput) tkptr->QueuedClientOutput--;

   if (VMSnok (rqptr->NetIoPtr->WriteStatus))
   {
      /* NETWORK ERROR when writing TO CLIENT */
      if (tkptr->LifeTimeSecond == DCL_DO_NOT_DISTURB)
      {
         /* do not disturb script means DO NOT DISTURB SCRIPT!! */
         if (!tkptr->ClientWriteErrorCount)
            if (WATCHING (tkptr, WATCH_DCL))
               WatchThis (WATCHITM(tkptr), WATCH_DCL,
                          "DO-NOT-DISTURB in effect");
      }
      else
      if (tkptr->BitBucketTimeout)
      {
         if (!tkptr->ClientWriteErrorCount)
         {
            if (WATCHING (tkptr, WATCH_DCL))
               WatchThis (WATCHITM(tkptr), WATCH_DCL,
                          "BIT-BUCKET !UL seconds", tkptr->BitBucketTimeout);

            /* ignore client error, give the script just a little longer */
            HttpdTimerSet (rqptr, TIMER_OUTPUT, tkptr->BitBucketTimeout);
         }
      }
      else
      {
         /* otherwise OK to abort on client issues */
         tkptr->DeleteProcess = true;
         DclTaskRunDown (tkptr);
         return;
      }

      tkptr->ClientWriteErrorCount++;
   }

   /* queue the next read of the script process' SYS$OUTPUT */
   DclQioSysOutput (tkptr);
}

/*****************************************************************************/
/*
Queue up a write of data to the script process "SYS$COMMAND" mailbox.  This is
the  script processes' "SYS$COMMAND", supplying the DCL commands to execute,
CGI information, etc.
*/ 

DclQioSysCommand 
(
DCL_TASK *tkptr,
char *DataPtr,
int DataLength
)
{
   int  status;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclQioSysCommand() !8XL", tkptr->ScriptProcessPid);

   if (!DataPtr)
   {
      /* NULL pointer means write an end-of-file to the channel */

      if (WATCHING (tkptr, WATCH_DCL))
         WatchThis (WATCHITM(tkptr), WATCH_DCL,
                    "WRITE SYS$COMMAND EOF");

      tkptr->QueuedSysCommand++;
      status = sys$qio (EfnNoWait, tkptr->SysCommandChannel,
                        IO$_WRITEOF | IO$M_NORSWAIT,
                        &tkptr->SysCommandIOsb, &DclSysCommandAst, tkptr,
                        0, 0, 0, 0, 0, 0);
      if (VMSok (status)) return;
   }
   else
   {
      if (WATCHING (tkptr, WATCH_DCL))
      {
         WatchThis (WATCHITM(tkptr), WATCH_DCL,
                    "WRITE SYS$COMMAND !UL", DataLength);
         if (DataLength) WatchData (DataPtr, DataLength);
      }

      tkptr->QueuedSysCommand++;
      status = sys$qio (EfnNoWait, tkptr->SysCommandChannel,
                        IO$_WRITELBLK | IO$M_NORSWAIT,
                        &tkptr->SysCommandIOsb, &DclSysCommandAst, tkptr,
                        DataPtr, DataLength, 0, 0, 0, 0);
      if (VMSok (status)) return;
   }

   /* report error via the AST */
   if (status == SS$_MBFULL)
   {
      tkptr->RequestPtr->rqResponse.ErrorTextPtr = "SYS$COMMAND";
      ErrorVmsStatus (tkptr->RequestPtr, status, FI_LI);
   }
   tkptr->SysCommandIOsb.Status = status;
   SysDclAst (&DclSysCommandAst, tkptr);
}

/*****************************************************************************/
/*
A queued write to the script process "SYS$COMMAND" mailbox has completed.  This
is the script processes' "SYS$COMMAND", supplying the DCL commands to execute. 

The first read of the process' CLI command stream indicates it has completed
the full process creation and login cycle.  We can now add the identifier that
marks it as a WASD detached scripting process.  Adding it too early in the
process life cycle can result in LOGINOUT.EXE overriding it with it's own set
of rights identifiers.
*/ 

DclSysCommandAst (DCL_TASK *tkptr)

{
   int  status,
        SetPrvStatus;
   unsigned long  ScriptProcessPid;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
         "DclSysCommandAst() !&F !8XL !UL/!UL !UL !UL !UL !UL !UL !&S",
         &DclSysCommandAst, tkptr->ScriptProcessPid,
         tkptr->QueuedSysCommand, tkptr->QueuedSysCommandAllowed,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         tkptr->SysCommandIOsb.Status);

   if (tkptr->QueuedSysCommand) tkptr->QueuedSysCommand--;

   /* first AST is delivered %x00000000, make %X00000001 */
   if (!tkptr->SysCommandIOsb.Status) tkptr->SysCommandIOsb.Status = 1;

   if (tkptr->DetachedGrantId)
   {
      /****************************************/
      /* grant the detached script process ID */
      /****************************************/

      tkptr->DetachedGrantId = false;

      if (VMSnok (SetPrvStatus = sys$setprv (1, &GrantIdMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

      /* PID needs to be in some sort of scratch space? (most peculiar!) */
      ScriptProcessPid = tkptr->ScriptProcessPid;
      /* note: not sure of what the sixth parameter is - 'segment'? */
      status = sys$grantid (&ScriptProcessPid, 0, &ProcessRightsIdent,
                            0, 0, 0);

      if (VMSnok (SetPrvStatus = sys$setprv (0, &GrantIdMask, 0, 0)))
         ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

      if (WATCHMOD (tkptr, WATCH_MOD_DCL))
         WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                    "sys$grantid() !AZ !&X !&S",
                    ProcessIdentName, ProcessRightsIdent[0], status);

      if (VMSnok (status))
      {
         /* make it a little more obvious */
         if (status == SS$_NOPRIV) status = SS$_NOCMKRNL;
         tkptr->RequestPtr->rqResponse.ErrorTextPtr =
            MsgFor(tkptr->RequestPtr,MSG_SCRIPT_DCL_ENVIRONMENT);
         ErrorVmsStatus (tkptr->RequestPtr, status, FI_LI);
         tkptr->DeleteProcess = true;
         DclTaskRunDown (tkptr);
         return;
      }
   }

   if (WATCHING (tkptr, WATCH_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "WRITE SYS$COMMAND !&S",
                 tkptr->SysCommandIOsb.Status);

   /* if (effectively) no outstanding I/O then conclude the DCL task */
   if (tkptr->QueuedSysCommand <= tkptr->QueuedSysCommandAllowed &&
       !tkptr->QueuedSysOutput &&
       !tkptr->QueuedClientOutput &&
       !tkptr->QueuedCgiPlusIn &&
       !tkptr->QueuedHttpInput &&
       !tkptr->QueuedClientRead)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* if I/O cancelled then just return */
   if (tkptr->SysCommandIOsb.Status == SS$_ABORT ||
       tkptr->SysCommandIOsb.Status == SS$_CANCEL)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* abort if an error writing SYS$COMMAND stream to script process */
   if (VMSnok (tkptr->SysCommandIOsb.Status))
   {
      tkptr->RequestPtr->rqResponse.ErrorTextPtr =
         MsgFor(tkptr->RequestPtr,MSG_SCRIPT_IPC);
      ErrorVmsStatus (tkptr->RequestPtr, tkptr->SysCommandIOsb.Status, FI_LI);
      tkptr->DeleteProcess = true;
      DclTaskRunDown (tkptr);
      return;
   }

   /* allow for the queued post-CGIplus script STOP/id=0 and EOF */
   if (tkptr->QueuedSysCommand > tkptr->QueuedSysCommandAllowed)
      tkptr->ScriptProcessActivated = true;
}

/*****************************************************************************/
/*
Queue up a write of data to the script process "CGIPLUSIN" mailbox.  This is a
CGIplus script processes' CGI variable stream mailbox.             
*/ 

DclQioCgiPlusIn 
(
DCL_TASK *tkptr,
char *DataPtr,
int DataLength
)
{
   int  status;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL, "DclQioCgiPlusIn()");

   if (!DataPtr)
   {
      /* NULL pointer means write an end-of-file to the channel */
      if (WATCHING (tkptr, WATCH_DCL))
         WatchThis (WATCHITM(tkptr), WATCH_DCL,
                    "WRITE CGIPLUSIN EOF");

      tkptr->QueuedCgiPlusIn++;
      status = sys$qio (EfnNoWait, tkptr->CgiPlusInChannel,
                        IO$_WRITEOF | IO$M_NORSWAIT, &tkptr->CgiPlusInIOsb,
                        &DclCgiPlusInAst, tkptr,
                        0, 0, 0, 0, 0, 0);
      if (VMSok (status)) return;
   }
   else
   {
      if (WATCHING (tkptr, WATCH_DCL))
      {
         WatchThis (WATCHITM(tkptr), WATCH_DCL,
                    "WRITE CGIPLUSIN !UL bytes", DataLength);
         if (DataLength) WatchDataDump (DataPtr, DataLength);
      }

      tkptr->QueuedCgiPlusIn++;
      status = sys$qio (EfnNoWait, tkptr->CgiPlusInChannel,
                        IO$_WRITELBLK | IO$M_NORSWAIT, &tkptr->CgiPlusInIOsb,
                        &DclCgiPlusInAst, tkptr,
                        DataPtr, DataLength, 0, 0, 0, 0);
      if (VMSok (status)) return;
   }

   /* report error via the AST */
   if (status == SS$_MBFULL)
   {
      tkptr->RequestPtr->rqResponse.ErrorTextPtr = "CGIPLUSIN";
      ErrorVmsStatus (tkptr->RequestPtr, status, FI_LI);
   }
   tkptr->CgiPlusInIOsb.Status = status;
   SysDclAst (&DclCgiPlusInAst, tkptr);
}

/*****************************************************************************/
/*
A queued write to the script process "CGIPLUSIN" mailbox has completed.  This
is a CGIplus script processes' CGI variable stream mailbox.             
*/ 

DclCgiPlusInAst (DCL_TASK *tkptr)

{
   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
         "DclCgiPlusInAst() !&F !8XL !UL !UL !UL !UL !UL !UL !&S",
         &DclCgiPlusInAst, tkptr->ScriptProcessPid, tkptr->QueuedSysCommand,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         tkptr->CgiPlusInIOsb.Status);

   if (tkptr->QueuedCgiPlusIn) tkptr->QueuedCgiPlusIn--;

   /* at least one CGIPLUSIN variable was read indicating script activation */
   if (tkptr->CgiPlusInIOsb.Status && VMSok(tkptr->CgiPlusInIOsb.Status))
      tkptr->ScriptProcessActivated = true;

   /* first AST is delivered %x00000000, make %X00000001 */
   if (!tkptr->CgiPlusInIOsb.Status) tkptr->CgiPlusInIOsb.Status = SS$_NORMAL;

   if (WATCHING (tkptr, WATCH_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "WRITE CGIPLUSIN !&S",
                 tkptr->CgiPlusInIOsb.Status);

   /* if (effectively) no outstanding I/O then conclude the DCL task */
   if (tkptr->QueuedSysCommand <= tkptr->QueuedSysCommandAllowed &&
       !tkptr->QueuedSysOutput &&
       !tkptr->QueuedClientOutput &&
       !tkptr->QueuedCgiPlusIn &&
       !tkptr->QueuedHttpInput &&
       !tkptr->QueuedClientRead)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* if I/O cancelled then just return */
   if (tkptr->CgiPlusInIOsb.Status == SS$_ABORT ||
       tkptr->CgiPlusInIOsb.Status == SS$_CANCEL)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* abort if an error writing CGIPLUSIN stream to script process */
   if (VMSnok (tkptr->CgiPlusInIOsb.Status))
   {
      tkptr->RequestPtr->rqResponse.ErrorTextPtr =
         MsgFor(tkptr->RequestPtr,MSG_SCRIPT_IPC);
      ErrorVmsStatus (tkptr->RequestPtr, tkptr->CgiPlusInIOsb.Status, FI_LI);
      tkptr->DeleteProcess = true;
      DclTaskRunDown (tkptr);
      return;
   }
}

/*****************************************************************************/
/*
A network read of the request body has completed and BodyReadAst() has called
this function as an AST.  Write it to HTTP$INPUT with a completion AST to
DclHttpInputAst().
*/ 

DclHttpInput (REQUEST_STRUCT *rqptr)

{
   int  status,
        DataCount;
   char  *DataPtr;
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   tkptr = rqptr->DclTaskPtr;

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL,
         "DclHttpInput() !&F !8XL !UL !UL !UL !UL !UL !UL !&S !&X !UL",
         &DclHttpInput,
         tkptr->ScriptProcessPid, tkptr->QueuedSysCommand,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         rqptr->rqBody.DataStatus, rqptr->rqBody.DataPtr,
         rqptr->rqBody.DataCount);

   if (tkptr->QueuedClientRead) tkptr->QueuedClientRead--;

   /* if (effectively) no outstanding I/O then conclude the DCL task */
   if (tkptr->QueuedSysCommand <= tkptr->QueuedSysCommandAllowed &&
       !tkptr->QueuedSysOutput &&
       !tkptr->QueuedClientOutput &&
       !tkptr->QueuedCgiPlusIn &&
       !tkptr->QueuedHttpInput &&
       !tkptr->QueuedClientRead)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   if (rqptr->rqBody.DataStatus == SS$_ABORT ||
       rqptr->rqBody.DataStatus == SS$_CANCEL)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   if (rqptr->rqBody.DataStatus == SS$_ENDOFFILE)
   {
      /* if a CLIENT-READ: callout is in progress ignore the default EOF */
      if (tkptr->ClientReadBufferPtr) return;

      /* end of body */
      tkptr->QueuedHttpInput++;
      status = sys$qio (EfnNoWait, tkptr->HttpInputChannel,
                        IO$_WRITEOF, &tkptr->HttpInputIOsb,
                        &DclHttpInputAst, tkptr, 0, 0, 0, 0, 0, 0);
      if (VMSok (status)) return;
      /* report error via the AST */
      tkptr->HttpInputIOsb.Status = status;
      SysDclAst (&DclHttpInputAst, tkptr);
      return;
   }

   if (VMSnok (rqptr->rqBody.DataStatus))
   {
      DclTaskRunDown (tkptr);
      return;
   }

   if (WATCHING (tkptr, WATCH_DCL))
   {
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "WRITE HTTP$INPUT !UL bytes", rqptr->rqBody.DataCount);
      if (rqptr->rqBody.DataCount)
         WatchDataDump (rqptr->rqBody.DataPtr, rqptr->rqBody.DataCount);
   }

   tkptr->QueuedHttpInput++;
   status = sys$qio (EfnNoWait, tkptr->HttpInputChannel,
                     IO$_WRITELBLK, &tkptr->HttpInputIOsb,
                     &DclHttpInputAst, tkptr,
                     rqptr->rqBody.DataPtr, rqptr->rqBody.DataCount,
                     0, 0, 0, 0);
   if (VMSok (status)) return;

   /* report error via the AST */
   tkptr->HttpInputIOsb.Status = status;
   SysDclAst (&DclHttpInputAst, tkptr);
}

/*****************************************************************************/
/*
A queued write to the script process "HTTP$INPUT" mailbox has completed.
Provide more (possibly first) of the request body, or EOF.
*/ 

DclHttpInputAst (DCL_TASK *tkptr)

{
   int  status,
        Length;
   char  *ContentPtr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
         "DclHttpInputAst() !&F !8XL !UL !UL !UL !UL !UL !UL !&S !UL",
         &DclHttpInputAst, tkptr->ScriptProcessPid, tkptr->QueuedSysCommand,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         tkptr->HttpInputIOsb.Status, tkptr->HttpInputIOsb.Count);

   if (tkptr->QueuedHttpInput) tkptr->QueuedHttpInput--;

   if (WATCHING (tkptr, WATCH_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "WRITE HTTP$INPUT !&S",
                 tkptr->HttpInputIOsb.Status);

   /* if (effectively) no outstanding I/O then conclude the DCL task */
//   if (tkptr->QueuedSysCommand <= tkptr->QueuedSysCommandAllowed &&
   if (!tkptr->QueuedSysCommand &&
       !tkptr->QueuedSysOutput &&
       !tkptr->QueuedClientOutput &&
       !tkptr->QueuedCgiPlusIn &&
       !tkptr->QueuedHttpInput &&
       !tkptr->QueuedClientRead)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* if I/O cancelled then just return */
   if (tkptr->HttpInputIOsb.Status == SS$_ABORT ||
       tkptr->HttpInputIOsb.Status == SS$_CANCEL)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* abort if an error writing HTTP stream to script process */
   if (VMSnok (tkptr->HttpInputIOsb.Status))
   {
      tkptr->RequestPtr->rqResponse.ErrorTextPtr =
         MsgFor(tkptr->RequestPtr,MSG_SCRIPT_IPC);
      ErrorVmsStatus (tkptr->RequestPtr, tkptr->HttpInputIOsb.Status, FI_LI);
      tkptr->DeleteProcess = true;
      DclTaskRunDown (tkptr);
      return;
   }

   /* get more from the client */
   BodyRead (tkptr->RequestPtr);
   tkptr->QueuedClientRead++;
}

/*****************************************************************************/
/*
A CLIENT-READ: callout network read from the client has concluded.  If an error
then just conclude the task.  If OK then queue it to the HTTP$INPUT device so
the script can read it.
*/ 
 
DclClientReadAst (REQUEST_STRUCT *rqptr)

{
   int  status;
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   /* get a pointer to the DCL task from the request structure */
   tkptr = rqptr->DclTaskPtr;

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL,
         "DclClientReadAst() !&F !8XL !UL !UL !UL !UL !UL !UL !&S !UL",
         &DclClientReadAst, tkptr->ScriptProcessPid, tkptr->QueuedSysCommand,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         rqptr->NetIoPtr->ReadStatus, rqptr->NetIoPtr->ReadCount);

   if (tkptr->QueuedClientRead) tkptr->QueuedClientRead--;

   /* if (effectively) no outstanding I/O then conclude the DCL task */
   if (tkptr->QueuedSysCommand <= tkptr->QueuedSysCommandAllowed &&
       !tkptr->QueuedSysOutput &&
       !tkptr->QueuedClientOutput &&
       !tkptr->QueuedCgiPlusIn &&
       !tkptr->QueuedHttpInput &&
       !tkptr->QueuedClientRead)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   if (VMSnok (rqptr->NetIoPtr->ReadStatus))
   {
      DclTaskRunDown (tkptr);
      return;
   }

   if (tkptr->ClientReadStripCrLf)
   {
      if (rqptr->NetIoPtr->ReadCount >= 2 &&
          tkptr->ClientReadBufferPtr[rqptr->NetIoPtr->ReadCount-2] == '\r' &&
          tkptr->ClientReadBufferPtr[rqptr->NetIoPtr->ReadCount-1] == '\n')
         rqptr->NetIoPtr->ReadCount -= 2;
      else
      if (rqptr->NetIoPtr->ReadCount >= 1 &&
          tkptr->ClientReadBufferPtr[rqptr->NetIoPtr->ReadCount-1] == '\n')
         rqptr->NetIoPtr->ReadCount--;
   }

   tkptr->QueuedHttpInput++;
   status = sys$qio (EfnNoWait, tkptr->HttpInputChannel,
                     IO$_WRITELBLK, &tkptr->HttpInputIOsb,
                     &DclClientReadHttpInputAst, tkptr,
                     tkptr->ClientReadBufferPtr, rqptr->NetIoPtr->ReadCount,
                     0, 0, 0, 0);
   if (VMSok (status)) return;
   /* report error via the AST */
   tkptr->HttpInputIOsb.Status = status;
   SysDclAst (&DclClientReadAst, tkptr);
}

/*****************************************************************************/
/*
A CLIENT-READ: callout write of client data to the HTTP$DEVICE has concluded. 
If there was an error writing this to the script then just conclude the task. 
If OK then queue another network read from the client.
*/ 

DclClientReadHttpInputAst (DCL_TASK *tkptr)

{
   int  status,
        Length;
   char  *ContentPtr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
"DclClientReadHttpInputAst() !&F !8XL !UL !UL !UL !UL !UL !UL !&S",
         &DclClientReadHttpInputAst,
         tkptr->ScriptProcessPid, tkptr->QueuedSysCommand,
         tkptr->QueuedSysOutput, tkptr->QueuedClientOutput,
         tkptr->QueuedCgiPlusIn,
         tkptr->QueuedHttpInput, tkptr->QueuedClientRead,
         tkptr->HttpInputIOsb.Status);

   if (tkptr->QueuedHttpInput) tkptr->QueuedHttpInput--;

   if (WATCHING (tkptr, WATCH_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_DCL,
                 "CLIENT-READ !&S",
                 tkptr->HttpInputIOsb.Status);

   /* if (effectively) no outstanding I/O then conclude the DCL task */
   if (tkptr->QueuedSysCommand <= tkptr->QueuedSysCommandAllowed &&
       !tkptr->QueuedSysOutput &&
       !tkptr->QueuedClientOutput &&
       !tkptr->QueuedCgiPlusIn &&
       !tkptr->QueuedHttpInput &&
       !tkptr->QueuedClientRead)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* if I/O cancelled then just return */
   if (tkptr->HttpInputIOsb.Status == SS$_ABORT ||
       tkptr->HttpInputIOsb.Status == SS$_CANCEL)
   {
      DclTaskRunDown (tkptr);
      return;
   }

   /* abort if an error writing HTTP stream to script process */
   if (VMSnok (tkptr->HttpInputIOsb.Status))
   {
      tkptr->RequestPtr->rqResponse.ErrorTextPtr =
         MsgFor(tkptr->RequestPtr,MSG_SCRIPT_IPC);
      ErrorVmsStatus (tkptr->RequestPtr, tkptr->HttpInputIOsb.Status, FI_LI);
      tkptr->DeleteProcess = true;
      DclTaskRunDown (tkptr);
      return;
   }

   /* asynchronous read another record from the client */
   NetRead (tkptr->RequestPtr, &DclClientReadAst,
            tkptr->ClientReadBufferPtr, tkptr->ClientReadBufferSize);
   tkptr->QueuedClientRead++;
}

/*****************************************************************************/
/*
Send DCL commands to the CGI script or DCL command script process' SYS$COMMAND.
This sets up the DCL environment (defines logical names, assigns symbols)
executes the procedure or image.
*/ 

int DclCgiScriptSysCommand (DCL_TASK *tkptr)

{
   static char  DefSysErrNl [] = "DEFINE/USER SYS$ERROR NL:";
   static char  DefSysOutNl [] = "DEFINE/USER SYS$OUTPUT NL:";
   static char  DelSymAll [] = "DELSYMALL=\"DELETE/SYMBOL/ALL\"";
   static char  DelSymAllGlobal[] = "DELSYMALL/GLOBAL";
   static char  DelSymAllLocal[] = "DELSYMALL/LOCAL";

   static char  WasdFileDev [] =
"IF F$TRNLNM(\"WASD_FILE_DEV\").NES.\"\" THEN @WASD_FILE_DEV";
   static $DESCRIPTOR (WasdFileDevFaoDsc,
"IF F$TRNLNM(\"WASD_FILE_DEV_!UL\").NES.\"\" THEN @WASD_FILE_DEV_!UL !UL");

   static char  WasdLogin [] =
"IF F$TRNLNM(\"WASD_LOGIN\").NES.\"\" THEN @WASD_LOGIN";

   static char  HttpdLogin [] =
"IF F$TRNLNM(\"HTTPD$LOGIN\").NES.\"\" THEN @HTTPD$LOGIN";

   static char  WasdVerify1 [] = "DEFINE/NOLOG WASD__VERIFY \"0\"";
   static char  WasdVerify2 [] =
"IF F$TRNLNM(\"WASD_VERIFY\").NES.\"\" THEN DEFINE/NOLOG WASD__VERIFY \"1\"";
   static $DESCRIPTOR (WasdVerify3FaoDsc,
"IF F$LENGTH(F$TRNLNM(\"WASD_VERIFY\")).GE.7.AND.\
F$TRNLNM(\"WASD_VERIFY\").NES.\"!AZ\" THEN DEFINE/NOLOG WASD__VERIFY \"0\"");
   static char  WasdVerify4 [] =
"IF F$TRNLNM(\"WASD__VERIFY\",\"LNM$PROCESS\") THEN \
WRITE SYS$OUTPUT \"Content-Type: text/plain\015\012\015\012\"";
   static char  WasdVerify5 [] =
"!\'F$VERIFY(F$TRNLNM(\"WASD__VERIFY\",\"LNM$PROCESS\"))";

   static char  NetDefSysOut [] = "DEFINE SYS$OUTPUT SYS$NET";
   static char  NetPurgeLog [] = "PURGE/NOLOG/KEEP=3 SYS$LOGIN:"
                                 NETWORK_MODE_LOG_NAME;
   static char  NoVerify [] = "!\'F$VERIFY(0)";
   static char  SetNoOn[] = "SET NOON";
#ifdef ODS_EXTENDED
   static char  SetProcParseExt [] = "SET PROCESS/PARSE=EXTENDED";
   static char  SetProcParseTrad [] = "SET PROCESS/PARSE=TRADITIONAL";
#endif /* ODS_EXTENDED */
   static char  SetProcPriv[] = "SET PROCESS/PRIVILEGE=(NOALL,NETMBX,TMPMBX)";
   static char  StopId [] = "STOP/id=0";
   static char  WriteIsWrite [] = "WRITE=\"WRITE\"";

   static $DESCRIPTOR (SetPrcNamFaoDsc, "SET PROCESS/NAME=\"!AZ\"");

   static $DESCRIPTOR (WriteDclQuoteFaoDsc, "WRITE SYS$OUTPUT \"!AZ\"");

   static $DESCRIPTOR (DefineHttpInputFaoDsc,
                       "DEFINE/NOLOG/SUPER HTTP$INPUT !AZ");
   static $DESCRIPTOR (DefineSysInputFaoDsc,
                       "DEFINE/NOLOG/SUPER SYS$INPUT !AZ");

#if CGIPLUS_CALLOUT_FOR_CGI

   static $DESCRIPTOR (DefineCgiPlusInFaoDsc,
                       "DEFINE/NOLOG/SUPER CGIPLUSIN !AZ");
   static $DESCRIPTOR (DefineCgiPlusEotFaoDsc,
                       "DEFINE/NOLOG/SUPER CGIPLUSEOT \"!AZ\"");
   static $DESCRIPTOR (DefineCgiPlusEscFaoDsc,
                       "DEFINE/NOLOG/SUPER CGIPLUSESC \"!AZ\"");

#endif /* CGIPLUS_CALLOUT_FOR_CGI */

#if STREAMS_FOR_APACHE

   static $DESCRIPTOR (DefineApacheInputFaoDsc,
                       "DEFINE/NOLOG/SUPER APACHE$INPUT !AZ");

#endif /* STREAMS_FOR_APACHE */

#if STREAMS_FOR_PURVEYOR_AND_CERN

   static $DESCRIPTOR (DefineWwwInFaoDsc,
                       "DEFINE/NOLOG/SUPER WWW_IN !AZ");
   static char  DefineWwwOut[] = "DEFINE/NOLOG/SUPER WWW_OUT SYS$OUTPUT";

#endif /* STREAMS_FOR_PURVEYOR_AND_CERN */

   int  status,
        Count;
   unsigned short  Length;
   char  c;
   char  *cptr, *sptr, *zptr,
         *StringPtr;
   char  DclLine [256],
         String [256];
   REQUEST_STRUCT *rqptr;
   $DESCRIPTOR (DclLineDsc, DclLine);

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclCgiScriptSysCommand() !&Z !&Z !&Z",
                 tkptr->DclCommandPtr, tkptr->ScriptFileName,
                 tkptr->ScriptRunTimePtr);

   /* get the pointer to the request structure */
   rqptr = tkptr->RequestPtr;

   DclQioSysCommand (tkptr, NoVerify, sizeof(NoVerify)-1);

   DclQioSysCommand (tkptr, DelSymAll, sizeof(DelSymAll)-1);
   DclQioSysCommand (tkptr, DelSymAllGlobal, sizeof(DelSymAllGlobal)-1);
   DclQioSysCommand (tkptr, DelSymAllLocal, sizeof(DelSymAllLocal)-1);
   DclQioSysCommand (tkptr, SetNoOn, sizeof(SetNoOn)-1);

   if (InstanceEnvNumber == 1)
      DclQioSysCommand (tkptr, WasdFileDev, sizeof(WasdFileDev)-1);
   else
   {
      sys$fao (&WasdFileDevFaoDsc, &Length, &DclLineDsc,
               InstanceEnvNumber, InstanceEnvNumber, InstanceEnvNumber);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);
   }

   if (HttpdNetworkMode)
   {
      DclQioSysCommand (tkptr, NetDefSysOut, sizeof(NetDefSysOut)-1);
      DclQioSysCommand (tkptr, DefSysOutNl, sizeof(DefSysOutNl)-1);
      DclQioSysCommand (tkptr, DefSysErrNl, sizeof(DefSysErrNl)-1);
      DclQioSysCommand (tkptr, NetPurgeLog, sizeof(NetPurgeLog)-1);
   }

   if (tkptr->CrePrcDetachStarting)
   {
      /* indicate any login message, etc. are finished, process is ready */
      sys$fao (&WriteDclQuoteFaoDsc, &Length, &DclLineDsc, tkptr->CgiBel);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);
   }

   DclQioSysCommand (tkptr, WasdVerify1, sizeof(WasdVerify1)-1);
   DclQioSysCommand (tkptr, WasdVerify2, sizeof(WasdVerify2)-1);
   sys$fao (&WasdVerify3FaoDsc, &Length, &DclLineDsc,
            &rqptr->ClientPtr->IpAddressString);
   DclLine[Length] = '\0';
   DclQioSysCommand (tkptr, DclLine, Length);
   DclQioSysCommand (tkptr, WasdVerify4, sizeof(WasdVerify4)-1);
   DclQioSysCommand (tkptr, WasdVerify5, sizeof(WasdVerify5)-1);

   if (!DclScriptDetachProcess && Config.cfScript.SpawnAuthPriv)
      /* kludge to work around spawning authorized privileges with $CREPRC */
      DclQioSysCommand (tkptr, SetProcPriv, sizeof(SetProcPriv)-1);

   if (tkptr->TaskType == DCL_TASK_TYPE_CGI_SCRIPT)
   {
      sys$fao (&DefineSysInputFaoDsc, &Length, &DclLineDsc,
               tkptr->HttpInputDevName);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);

      /* for backward compatibility */
      sys$fao (&DefineHttpInputFaoDsc, &Length, &DclLineDsc,
               tkptr->HttpInputDevName);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);

#if STREAMS_FOR_PURVEYOR_AND_CERN

      /* for Purveyor, Cern backward compatibility */
      sys$fao (&DefineWwwInFaoDsc, &Length, &DclLineDsc,
               tkptr->HttpInputDevName);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);
      DclQioSysCommand (tkptr, DefineWwwOut, sizeof(DefineWwwOut)-1);

#endif /* STREAMS_FOR_PURVEYOR_AND_CERN */

#if STREAMS_FOR_APACHE

      /* for VMS Apache forward compatibility :^) */
      sys$fao (&DefineApacheInputFaoDsc, &Length, &DclLineDsc,
               tkptr->HttpInputDevName);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);

#endif /* STREAMS_FOR_APACHE */

#if CGIPLUS_CALLOUT_FOR_CGI

      sys$fao (&DefineCgiPlusInFaoDsc, &Length, &DclLineDsc,
               tkptr->CgiPlusInDevName);
      DclLine[Length] = '\0';
      status = DclQioSysCommand (tkptr, DclLine, Length);

      sys$fao (&DefineCgiPlusEotFaoDsc, &Length, &DclLineDsc,
               tkptr->CgiEot);
      DclLine[Length] = '\0';
      status = DclQioSysCommand (tkptr, DclLine, Length);

      sys$fao (&DefineCgiPlusEscFaoDsc, &Length, &DclLineDsc,
               tkptr->CgiEsc);
      DclLine[Length] = '\0';
      status = DclQioSysCommand (tkptr, DclLine, Length);

#endif /* CGIPLUS_CALLOUT_FOR_CGI */
   }

   /*****************/
   /* CGI variables */
   /*****************/

   /* as of v12... meta agents and like can result in multiple scripts */
   if (VMSnok (status = CgiGenerateVariables (rqptr, CGI_VARIABLE_DCL)))
      return (status);

   cptr = rqptr->rqCgi.BufferPtr;
   for (;;)
   {
      if (!(Length = *(USHORTPTR)cptr)) break;
      DclQioSysCommand (tkptr, cptr+sizeof(short), Length-1);
      cptr += Length + sizeof(short);
   }

#ifdef ODS_EXTENDED
   if (OdsExtended)
   {
      if (rqptr->PathOds == MAPURL_PATH_ODS_5)
      {
         DclQioSysCommand (tkptr, SetProcParseExt, sizeof(SetProcParseExt)-1);
         /* note that for this script activation the parse has been extended */
         tkptr->ProcessParseExtended = true;
      }
      else
      if (rqptr->PathOds == MAPURL_PATH_ODS_2)
         DclQioSysCommand (tkptr, SetProcParseTrad, sizeof(SetProcParseTrad)-1);
      else
      if (tkptr->ProcessParseExtended)
      {
         /* restore previously extended parse */
         DclQioSysCommand (tkptr, SetProcParseTrad, sizeof(SetProcParseTrad)-1);
         tkptr->ProcessParseExtended = false;
      }
   }
#endif /* ODS_EXTENDED */

   /* httpd$login for backward-compatibility from v10.0 */
   DclQioSysCommand (tkptr, HttpdLogin, sizeof(HttpdLogin)-1);
   DclQioSysCommand (tkptr, WasdLogin, sizeof(WasdLogin)-1);

   /* set default to the script location */
   zptr = (sptr = DclLine) + sizeof(DclLine)-1;
   for (cptr = "SET DEFAULT "; *cptr; *sptr++ = *cptr++);
   if (rqptr->rqPathSet.ScriptDefaultPtr)
   {
      if (rqptr->rqPathSet.ScriptDefaultPtr[0] == '#' ||
          rqptr->rqPathSet.ScriptDefaultPtr[0] == '/')
      {
         /* backward compatible or U**x syntax, do not set default */
         Length = 0;
      }
      else
      {
         /* specified by the mapping rules */
         for (cptr = rqptr->rqPathSet.ScriptDefaultPtr;
              *cptr && sptr < zptr;
              *sptr++ = *cptr++);
         *sptr = '\0';
         Length = sptr - DclLine;
      }
   }
   else
   {
      /* whichever directory the script is located in */
      for (cptr = tkptr->SearchOds.ResFileName;
           *cptr && sptr < zptr;
           *sptr++ = *cptr++);
      sptr--;
      while (sptr > DclLine && *sptr != ']') sptr--;
      if (*sptr == ']') sptr++;
      *sptr = '\0';
      Length = sptr - DclLine;
   }
   if (Length) DclQioSysCommand (tkptr, DclLine, Length);

   /*******************************/
   /* DCL command/procedure/image */
   /*******************************/

   DclNameProcess (tkptr);

   if (tkptr->PrcNamActive[0])
   {
      sys$fao (&SetPrcNamFaoDsc, &Length, &DclLineDsc,
               tkptr->PrcNamActive);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);
   }

   if (tkptr->ScriptFileName[0])
   {
      /**************/
      /* CGI script */
      /**************/

      zptr = (sptr = DclLine) + sizeof(DclLine)-1;
      cptr = tkptr->ScriptRunTimePtr;
      /* this exclamation symbols can be used within RTE-style syntax */
      if (*cptr == '!') cptr++;
      if (SAME2(cptr,'@\0'))
      {
         /* searched-for DCL procedure */
         *sptr++ = '@';
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }
      else
      if (SAME2(cptr,'=\0'))
      {
         /* searched-for command definition */
         memcpy (sptr, "SET COMMAND ", 12);
         sptr += 12;
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         DclQioSysCommand (tkptr, DclLine, sptr-DclLine);

         /* now use the command defintion file name as the verb */
         while (sptr > DclLine && *sptr != ']') sptr--;
         if (*sptr == ']') sptr++;
         cptr = sptr;
         zptr = (sptr = DclLine) + sizeof(DclLine)-1;
         while (*cptr && *cptr != '.' && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }
      else
      if (SAME2(cptr,'$\0'))
      {
         /* searched-for executable */
         memcpy (sptr, "WASDVERB:=$", 11);
         sptr += 11;
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         DclQioSysCommand (tkptr, DclLine, sptr-DclLine);

         /* now use it as a foreign-command */
         zptr = (sptr = DclLine) + sizeof(DclLine)-1;
         memcpy (sptr, "WASDVERB", 8);
         sptr += 8;
         *sptr = '\0';
      }
      else
      if (*cptr == '@' ||
          *cptr == '$')
      {
         /* configured run-time string */
         memcpy (sptr, "WASDVERB:=", 10);
         sptr += 10;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         DclQioSysCommand (tkptr, DclLine, sptr-DclLine);

         /* now place it as the verb before the script file */
         zptr = (sptr = DclLine) + sizeof(DclLine)-1;
         memcpy (sptr, "WASDVERB ", 9);
         sptr += 9;
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }
      else
      {
         /* verb must already exist on site, place before the script file */
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         if (sptr < zptr) *sptr++ = ' ';
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }

      if (rqptr->rqPathSet.ScriptCommandPtr)
      {
         /* add script activation command elements from path SETing */
         StringPtr = rqptr->rqPathSet.ScriptCommandPtr;
         for (;;)
         {
            status = StringParseValue (&StringPtr, String, sizeof(String));
            if (VMSnok (status)) break;
            cptr = String;
            if (*cptr != '*') zptr = (sptr = DclLine) + sizeof(DclLine)-1;
            while (*cptr == '*') cptr++;
            while (*cptr && sptr < zptr) *sptr++ = *cptr++;
            *sptr = '\0';
            DclQioSysCommand (tkptr, DclLine, sptr-DclLine);
         }
         if (status != SS$_ENDOFFILE) ErrorVmsStatus (rqptr, status, FI_LI);
         DclLine[0] = '\0';
      }

      if (DclLine[0]) DclQioSysCommand (tkptr, DclLine, sptr-DclLine);
   }
   else
   {
      /*******/
      /* CLI */
      /*******/

      /* multiple commands may be separated by newlines */
      sptr = tkptr->DclCommandPtr;
      while (*sptr)
      {
         cptr = sptr;
         while (*sptr && *sptr != '\n') sptr++;
         Length = sptr - cptr;
         if (*sptr == '\n')
         {
            zptr = sptr;
            *sptr++ = '\0';
         }
         else
            zptr = NULL;
         DclQioSysCommand (tkptr, cptr, Length);
         if (zptr) *zptr = '\n';
      }
   }

   /*********************/
   /* after script runs */
   /*********************/

   if (DclUseZombies && !rqptr->rqPathSet.ScriptCpuMax)
   {
      DclQioSysCommand (tkptr, NoVerify, sizeof(NoVerify)-1);

      /* reset the process name to the default */
      sys$fao (&SetPrcNamFaoDsc, &Length, &DclLineDsc,
               tkptr->PrcNamDefault);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);

      DclQioSysCommand (tkptr, WriteIsWrite, sizeof(WriteIsWrite)-1);

      sys$fao (&WriteDclQuoteFaoDsc, &Length, &DclLineDsc, tkptr->CgiEof);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);

      /* do not send an end-of-file! */
      return (SS$_NORMAL);
   }
   else
   {
      /* ensure script process terminates! */
      DclQioSysCommand (tkptr, StopId, sizeof(StopId)-1);

      /* send end-of-file */
      DclQioSysCommand (tkptr, NULL, 0);
   }

   return (SS$_NORMAL);
}

/*****************************************************************************/
/*
Send DCL commands to the CGIplus script process' SYS$COMMAND. This sets up the
DCL environment (defines logical names, assigns symbols) executes the procedure
or image.
*/ 

DclCgiPlusScriptSysCommand (DCL_TASK *tkptr)

{
   static char  DefSysErrNl [] = "DEFINE/USER SYS$ERROR NL:";
   static char  DefSysOutNl [] = "DEFINE/USER SYS$OUTPUT NL:";
   static char  DelSymAll [] = "DELSYMALL=\"DELETE/SYMBOL/ALL\"";
   static char  DelSymAllGlobal[] = "DELSYMALL/GLOBAL";
   static char  DelSymAllLocal[] = "DELSYMALL/LOCAL";

   static char  WasdFileDev [] =
"IF F$TRNLNM(\"WASD_FILE_DEV\").NES.\"\" THEN @WASD_FILE_DEV";
   static $DESCRIPTOR (WasdFileDevFaoDsc,
"IF F$TRNLNM(\"WASD_FILE_DEV_!UL\").NES.\"\" THEN @WASD_FILE_DEV_!UL !UL");

   static char  WasdLogin [] =
"IF F$TRNLNM(\"WASD_LOGIN\").NES.\"\" THEN @WASD_LOGIN";

   static char  HttpdLogin [] =
"IF F$TRNLNM(\"HTTPD$LOGIN\").NES.\"\" THEN @HTTPD$LOGIN";

   static char  WasdVerify1 [] = "DEFINE/NOLOG WASD__VERIFY \"0\"";
   static char  WasdVerify2 [] =
"IF F$TRNLNM(\"WASD_VERIFY\").NES.\"\" THEN DEFINE/NOLOG WASD__VERIFY \"1\"";
   static $DESCRIPTOR (WasdVerify3FaoDsc,
"IF F$LENGTH(F$TRNLNM(\"WASD_VERIFY\")).GE.7.AND.\
F$TRNLNM(\"WASD_VERIFY\").NES.\"!AZ\" THEN DEFINE/NOLOG WASD__VERIFY \"0\"");
   static char  WasdVerify4 [] =
"IF F$TRNLNM(\"WASD__VERIFY\",\"LNM$PROCESS\") THEN \
WRITE SYS$OUTPUT \"Content-Type: text/plain\015\012\015\012\"";
   static char  WasdVerify5 [] =
"!\'F$VERIFY(F$TRNLNM(\"WASD__VERIFY\",\"LNM$PROCESS\"))";

   static char  NetDefSysOut [] = "DEFINE SYS$OUTPUT SYS$NET";
   static char  NetPurgeLog [] = "PURGE/NOLOG/KEEP=3 SYS$LOGIN:"
                                 NETWORK_MODE_LOG_NAME;
   static char  NoVerify [] = "!\'F$VERIFY(0)";
   static char  SetNoOn [] = "SET NOON";
#ifdef ODS_EXTENDED
   static char  SetProcParseExt [] = "SET PROCESS/PARSE=EXTENDED";
   static char  SetProcParseTrad [] = "SET PROCESS/PARSE=TRADITIONAL";
#endif /* ODS_EXTENDED */
   static char  SetProcPriv[] = "SET PROCESS/PRIVILEGE=(NOALL,NETMBX,TMPMBX)";
   static char  StopId [] = "STOP/id=0";

   static $DESCRIPTOR (SetPrcNamFaoDsc, "SET PROCESS/NAME=\"!AZ\"");

   static $DESCRIPTOR (DefineCgiPlusInFaoDsc,
                       "DEFINE/NOLOG/SUPER CGIPLUSIN !AZ");
   static $DESCRIPTOR (DefineCgiPlusEofFaoDsc,
                       "DEFINE/NOLOG/SUPER CGIPLUSEOF \"!AZ\"");
   static $DESCRIPTOR (DefineCgiPlusEotFaoDsc,
                       "DEFINE/NOLOG/SUPER CGIPLUSEOT \"!AZ\"");
   static $DESCRIPTOR (DefineCgiPlusEscFaoDsc,
                       "DEFINE/NOLOG/SUPER CGIPLUSESC \"!AZ\"");
   static $DESCRIPTOR (DefineHttpInputFaoDsc,
                       "DEFINE/NOLOG/SUPER HTTP$INPUT !AZ");
   static $DESCRIPTOR (DefineSysInputFaoDsc,
                       "DEFINE/NOLOG/SUPER SYS$INPUT !AZ");

   static $DESCRIPTOR (WriteDclQuoteFaoDsc, "WRITE SYS$OUTPUT \"!AZ\"");

   int  status;
   unsigned short  Length;
   char  *cptr, *sptr, *zptr,
         *StringPtr;
   char  DclLine [256],
         String [256];
   REQUEST_STRUCT *rqptr;
   $DESCRIPTOR (DclLineDsc, DclLine);

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclCgiPlusScriptSysCommand() !&Z", tkptr->ScriptRunTimePtr);

   /* get the pointer to the request structure */
   rqptr = tkptr->RequestPtr;

   DclQioSysCommand (tkptr, NoVerify, sizeof(NoVerify)-1);

   DclQioSysCommand (tkptr, DelSymAll, sizeof(DelSymAll)-1);
   DclQioSysCommand (tkptr, DelSymAllGlobal, sizeof(DelSymAllGlobal)-1);
   DclQioSysCommand (tkptr, DelSymAllLocal, sizeof(DelSymAllLocal)-1);
   DclQioSysCommand (tkptr, SetNoOn, sizeof(SetNoOn)-1);

   sys$fao (&SetPrcNamFaoDsc, &Length, &DclLineDsc,
            tkptr->PrcNamDefault);
   DclLine[Length] = '\0';
   DclQioSysCommand (tkptr, DclLine, Length);

   if (InstanceEnvNumber == 1)
      DclQioSysCommand (tkptr, WasdFileDev, sizeof(WasdFileDev)-1);
   else
   {
      sys$fao (&WasdFileDevFaoDsc, &Length, &DclLineDsc,
               InstanceEnvNumber, InstanceEnvNumber, InstanceEnvNumber);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);
   }

   if (HttpdNetworkMode)
   {
      DclQioSysCommand (tkptr, NetDefSysOut, sizeof(NetDefSysOut)-1);
      DclQioSysCommand (tkptr, DefSysOutNl, sizeof(DefSysOutNl)-1);
      DclQioSysCommand (tkptr, DefSysErrNl, sizeof(DefSysErrNl)-1);
      DclQioSysCommand (tkptr, NetPurgeLog, sizeof(NetPurgeLog)-1);
   }

   if (tkptr->CrePrcDetachStarting)
   {
      /* indicate any login message, etc. are finished, process is ready */
      sys$fao (&WriteDclQuoteFaoDsc, &Length, &DclLineDsc, tkptr->CgiBel);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);
   }

   DclQioSysCommand (tkptr, WasdVerify1, sizeof(WasdVerify1)-1);
   DclQioSysCommand (tkptr, WasdVerify2, sizeof(WasdVerify2)-1);
   sys$fao (&WasdVerify3FaoDsc, &Length, &DclLineDsc,
            &rqptr->ClientPtr->IpAddressString);
   DclLine[Length] = '\0';
   DclQioSysCommand (tkptr, DclLine, Length);
   DclQioSysCommand (tkptr, WasdVerify4, sizeof(WasdVerify4)-1);
   DclQioSysCommand (tkptr, WasdVerify5, sizeof(WasdVerify5)-1);

   if (!DclScriptDetachProcess && Config.cfScript.SpawnAuthPriv)
      /* kludge to work around spawning authorized privileges with $CREPRC */
      DclQioSysCommand (tkptr, SetProcPriv, sizeof(SetProcPriv)-1);

   sys$fao (&DefineSysInputFaoDsc, &Length, &DclLineDsc,
            tkptr->HttpInputDevName);
   DclLine[Length] = '\0';
   DclQioSysCommand (tkptr, DclLine, Length);

   /* for backward compatibility */
   sys$fao (&DefineHttpInputFaoDsc, &Length, &DclLineDsc,
            tkptr->HttpInputDevName);
   DclLine[Length] = '\0';
   DclQioSysCommand (tkptr, DclLine, Length);

   sys$fao (&DefineCgiPlusInFaoDsc, &Length, &DclLineDsc,
            tkptr->CgiPlusInDevName);
   DclLine[Length] = '\0';
   status = DclQioSysCommand (tkptr, DclLine, Length);

   sys$fao (&DefineCgiPlusEofFaoDsc, &Length, &DclLineDsc,
            tkptr->CgiEof);
   DclLine[Length] = '\0';
   status = DclQioSysCommand (tkptr, DclLine, Length);

   sys$fao (&DefineCgiPlusEotFaoDsc, &Length, &DclLineDsc,
            tkptr->CgiEot);
   DclLine[Length] = '\0';
   status = DclQioSysCommand (tkptr, DclLine, Length);

   sys$fao (&DefineCgiPlusEscFaoDsc, &Length, &DclLineDsc,
            tkptr->CgiEsc);
   DclLine[Length] = '\0';
   status = DclQioSysCommand (tkptr, DclLine, Length);

#ifdef ODS_EXTENDED
   /* no need to keep track of the parse style, only activated once! */
   if (rqptr->PathOds == MAPURL_PATH_ODS_5)
      DclQioSysCommand (tkptr, SetProcParseExt, sizeof(SetProcParseExt)-1);
   else
   if (rqptr->PathOds == MAPURL_PATH_ODS_2)
      DclQioSysCommand (tkptr, SetProcParseTrad, sizeof(SetProcParseTrad)-1);
#endif /* ODS_EXTENDED */

   /* httpd$login for backward-compatibility from v10.0 */
   DclQioSysCommand (tkptr, HttpdLogin, sizeof(HttpdLogin)-1);
   DclQioSysCommand (tkptr, WasdLogin, sizeof(WasdLogin)-1);

   /* set default to the script location */
   zptr = (sptr = DclLine) + sizeof(DclLine)-1;
   for (cptr = "SET DEFAULT "; *cptr; *sptr++ = *cptr++);
   if (rqptr->rqPathSet.ScriptDefaultPtr)
   {
      if (rqptr->rqPathSet.ScriptDefaultPtr[0] == '#' ||
          rqptr->rqPathSet.ScriptDefaultPtr[0] == '/')
      {
         /* backward compatible or U**x syntax, do not set default */
         Length = 0;
      }
      else
      {
         /* specified by the mapping rules */
         for (cptr = rqptr->rqPathSet.ScriptDefaultPtr;
              *cptr && sptr < zptr;
              *sptr++ = *cptr++);
         *sptr = '\0';
         Length = sptr - DclLine;
      }
   }
   else
   {
      /* whichever directory the script is located in */
      for (cptr = tkptr->SearchOds.ResFileName;
           *cptr && sptr < zptr;
           *sptr++ = *cptr++);
      sptr--;
      while (sptr > DclLine && *sptr != ']') sptr--;
      if (*sptr == ']') sptr++;
      *sptr = '\0';
      Length = sptr - DclLine;
   }
   if (Length) DclQioSysCommand (tkptr, DclLine, Length);

   /***********************/
   /* DCL procedure/image */
   /***********************/

   DclNameProcess (tkptr);

   if (tkptr->PrcNamActive[0])
   {
      sys$fao (&SetPrcNamFaoDsc, &Length, &DclLineDsc,
               tkptr->PrcNamActive);
      DclLine[Length] = '\0';
      DclQioSysCommand (tkptr, DclLine, Length);
   }

   if (tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
   {
      /*******/
      /* RTE */
      /*******/

      zptr = (sptr = DclLine) + sizeof(DclLine)-1;
      cptr = tkptr->ScriptRunTimePtr;
      if (*cptr != '@')
      {
         if (*cptr == '$') cptr++;
         memcpy (sptr, "RUN ", 4);
         sptr += 4;
      }
      while (*cptr && sptr < zptr) *sptr++ = *cptr++;
      *sptr = '\0';
   }
   else
   {
      /******************/
      /* CGIplus script */
      /******************/

      zptr = (sptr = DclLine) + sizeof(DclLine)-1;
      cptr = tkptr->ScriptRunTimePtr;
      if (SAME2(cptr,'@\0'))
      {
         /* searched-for DCL procedure */
         *sptr++ = '@';
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }
      else
      if (SAME2(cptr,'=\0'))
      {
         /* searched-for command definition */
         memcpy (sptr, "SET COMMAND ", 12);
         sptr += 12;
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         DclQioSysCommand (tkptr, DclLine, sptr-DclLine);

         /* now use the command defintion file name as the verb */
         while (sptr > DclLine && *sptr != ']') sptr--;
         if (*sptr == ']') sptr++;
         cptr = sptr;
         zptr = (sptr = DclLine) + sizeof(DclLine)-1;
         while (*cptr && *cptr != '.' && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }
      else
      if (SAME2(cptr,'$\0'))
      {
         /* searched-for executable */
         memcpy (sptr, "WASDVERB:=$", 11);
         sptr += 11;
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         DclQioSysCommand (tkptr, DclLine, sptr-DclLine);

         /* now use it as a foreign-command */
         zptr = (sptr = DclLine) + sizeof(DclLine)-1;
         memcpy (sptr, "WASDVERB", 8);
         sptr += 8;
         *sptr = '\0';
      }
      else
      if (*cptr == '@' ||
          *cptr == '$')
      {
         /* configured run-time string */
         memcpy (sptr, "WASDVERB:=", 10);
         sptr += 10;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         DclQioSysCommand (tkptr, DclLine, sptr-DclLine);

         /* now place it as the verb before the script file */
         zptr = (sptr = DclLine) + sizeof(DclLine)-1;
         memcpy (sptr, "WASDVERB ", 9);
         sptr += 9;
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }
      else
      {
         /* verb must already exist on site, place before the script file */
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         if (sptr < zptr) *sptr++ = ' ';
         cptr = tkptr->SearchOds.ResFileName;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
      }

      if (rqptr->rqPathSet.ScriptCommandPtr)
      {
         /* add script activation command elements from path SETing */
         StringPtr = rqptr->rqPathSet.ScriptCommandPtr;
         for (;;)
         {
            status = StringParseValue (&StringPtr, String, sizeof(String));
            if (VMSnok (status)) break;
            cptr = String;
            if (*cptr != '*') zptr = (sptr = DclLine) + sizeof(DclLine)-1;
            while (*cptr == '*') cptr++;
            while (*cptr && sptr < zptr) *sptr++ = *cptr++;
            *sptr = '\0';
            DclQioSysCommand (tkptr, DclLine, sptr-DclLine);
         }
         if (status != SS$_ENDOFFILE) ErrorVmsStatus (rqptr, status, FI_LI);
         DclLine[0] = '\0';
      }
   }

   if (DclLine[0]) DclQioSysCommand (tkptr, DclLine, sptr-DclLine);

   /* ensure script process terminates! */
   DclQioSysCommand (tkptr, StopId, sizeof(StopId)-1);

   /* send end-of-file */
   DclQioSysCommand (tkptr, NULL, 0);
}

/*****************************************************************************/
/*
Send CGI variables to the script process' CGIPLUSIN input stream.  This is
either done with each CGI variable "name=value" as an individual record, or
with the entire CGI variable being provided in a single I/O.  See CGI.C for an
explanation on the structure of this data.

Transfering the CGIplus variables as a single structure (rather than as
per-variable records) can double the throughput!!  Demonstrated using the
[SRC.CGIPLUS]CGIPLUSTEST.C program.  This indicates that there is much less
than half the overhead for performing this using the 'struct' method!
*/ 

int DclCgiPlusScriptCgiPlusIn (DCL_TASK *tkptr)

{
   static char  CCString [] = "!\0\0";
   static char  StructString [32];
   static $DESCRIPTOR (StructFaoDsc, "!!!!!UL!AZ");
   static $DESCRIPTOR (StructStringDsc, StructString);

   int  status,
        StructLength;
   unsigned short  Length;
   char  *cptr;
   REQUEST_STRUCT *rqptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (tkptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(tkptr), WATCH_MOD_DCL,
                 "DclCgiPlusScriptCgiPlusIn()");

   /* get the pointer to the request structure */
   rqptr = tkptr->RequestPtr;

   if (VMSnok (status = CgiGenerateVariables (rqptr, CGI_VARIABLE_STREAM)))
      return (status);

   if (tkptr->CgiPlusVarStruct)
   {
      StructLength = rqptr->rqCgi.BufferCurrentPtr - rqptr->rqCgi.BufferPtr;
      sys$fao (&StructFaoDsc, &Length, &StructStringDsc,
               StructLength, rqptr->rqPathSet.CgiPlusInCC);
      StructString[Length] = '\0';

      /* just a line for "start-of-request" that can always be discarded */
      DclQioCgiPlusIn (tkptr, StructString, Length);

      /* provide all the CGI variables in one structure and I/O */
      DclQioCgiPlusIn (tkptr, rqptr->rqCgi.BufferPtr, StructLength);
   }
   else
   {
      /* just a line for "start-of-request" that can always be discarded */
      if (rqptr->rqPathSet.CgiPlusInCC[0])
      {
         CCString[1] = rqptr->rqPathSet.CgiPlusInCC[0];
         if (rqptr->rqPathSet.CgiPlusInCC[1])
         {
            CCString[2] = rqptr->rqPathSet.CgiPlusInCC[1];
            DclQioCgiPlusIn (tkptr, CCString, 3);
         }
         else
            DclQioCgiPlusIn (tkptr, CCString, 2);
      }
      else
         DclQioCgiPlusIn (tkptr, CCString, 1);

      /* provide each variable as a separate record */
      cptr = rqptr->rqCgi.BufferPtr;
      for (;;)
      {
         if (!(Length = *(USHORTPTR)cptr)) break;        
         DclQioCgiPlusIn (tkptr, cptr+sizeof(short), Length-1);
         cptr += Length + sizeof(short);
      }
      /* empty record/line terminates CGI variables */
      if (rqptr->rqPathSet.CgiPlusInCC[0])
         if (rqptr->rqPathSet.CgiPlusInCC[1])
            DclQioCgiPlusIn (tkptr, rqptr->rqPathSet.CgiPlusInCC, 2);
         else
            DclQioCgiPlusIn (tkptr, rqptr->rqPathSet.CgiPlusInCC, 1);
      else
         DclQioCgiPlusIn (tkptr, "", 0);
   }

   if (rqptr->rqPathSet.CgiPlusInWriteof) DclQioCgiPlusIn (tkptr, NULL, 0);

   return (SS$_NORMAL);
}

/*****************************************************************************/
/*
This function is available for an agent callout to write output to the agent's
CGIplus input mailbox.  It may be called one or more times from a single
callout (the only thing to be mindful of is BYTLM and the capacity of the
CGIPLUSIN mailbox.
*/ 

DclCalloutQio
(
REQUEST_STRUCT *rqptr,
char *DataPtr,
int DataLength
)
{
   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL, "DclCalloutQio() !&Z", DataPtr);

   if (!rqptr->DclTaskPtr)
      ErrorExitVmsStatus (SS$_BUGCHECK, ErrorSanityCheck, FI_LI);

   DclQioCgiPlusIn (rqptr->DclTaskPtr, DataPtr, DataLength);
}

/*****************************************************************************/
/*
Default callout for CGIplus scripting.  In other words; ask the the server to
do something for a CGIplus script.  See prologue to this module for description
of currently support functionality.
*/ 

DclCalloutDefault (REQUEST_STRUCT *rqptr)

{
   static char  RspBadParam [] = "400 Bad parameter",
                RspMustRequire [] = "400 Must require a response",
                RspUnauthorized [] = "401 Unauthorized",
                RspForbidden [] = "403 Forbidden",
                RspSuccess [] = "200 Success",
                RspUnknown [] = "400 Unknown request";

   BOOL  ProvideResponse;
   int  status,
        length,
        number,
        OutputCount;
   char  *cptr, *sptr, *zptr, 
         *ContentPtr,
         *FileNamePtr,
         *OutputPtr;
   char  Scratch [1024+4];
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   if (WATCHMOD (rqptr, WATCH_MOD_DCL))
      WatchThis (WATCHITM(rqptr), WATCH_MOD_DCL, "DclCalloutDefault() !&Z",
                 rqptr->rqCgi.CalloutOutputPtr);

   /* get a local pointer to the DCL task structure */
   tkptr = rqptr->DclTaskPtr;

   OutputPtr = rqptr->rqCgi.CalloutOutputPtr;
   OutputCount = rqptr->rqCgi.CalloutOutputCount;

   if (!OutputPtr && (OutputCount == 0 || OutputCount== -1))
   {
      /* indicates the script has sent a begin or end escape sequence */
      return;
   }

   if (OutputPtr[0] == '!' || OutputPtr[0] == '#')
   {
      ProvideResponse = false;
      OutputPtr++;
      OutputCount--;
   }
   else
      ProvideResponse = true;

   if (TOUP(OutputPtr[0]) == 'R' &&
       strsame (OutputPtr, "REDACT:", 7))
   {
      /***********/
      /* REDACT: */
      /***********/

      /* process redact data *before* expunging 'nasties' */
      RequestRedact (rqptr, OutputPtr, OutputCount, ProvideResponse);
      return;
   }

   /* for the rest make sure there are no potential nasties lurking */
   for (cptr = OutputPtr; *cptr && !iscntrl(*(unsigned char*)cptr); cptr++);
   *cptr = '\0';

   if (TOUP(OutputPtr[0]) == '1' &&
       TOUP(OutputPtr[4]) == 'A' &&
       TOUP(OutputPtr[14]) == 'C' &&
       strsame (OutputPtr, "100 AUTHAGENT-CALLOUT", 21))
   {
      /*********************/
      /* AUTHAGENT-CALLOUT */
      /*********************/

      rqptr->rqResponse.HttpStatus = 403;
      tkptr->DeleteProcess = true;
      DclTaskRunDown (tkptr);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'A')
   {
      if (TOUP(OutputPtr[6]) == 'B' &&
          strsame (OutputPtr, "AGENT-BEGIN:", 12))
      {
         /****************/
         /* AGENT-BEGIN: */
         /****************/

         if (cptr = rqptr->AgentRequestPtr)
         {
            while (*cptr && isspace(*cptr)) cptr++;
            if (*cptr == '[')
            {
               /* span over any internal [server directive] */
               while (*cptr && *cptr != ']' && *(USHORTPTR)cptr != '\]') cptr++;
               if (*cptr == ']') for (cptr++; *cptr && isspace(*cptr); cptr++);
            }
            zptr = (sptr = Scratch) + sizeof(Scratch)-1;
            if (*cptr)
            {
               for (cptr = "200 "; *cptr; *sptr++ = *cptr++);
               for (cptr = rqptr->AgentRequestPtr; *cptr; *sptr++ = *cptr++);
            }
            else
               for (cptr = "204"; *cptr; *sptr++ = *cptr++);
            *sptr = '\0';
            if (ProvideResponse)
               DclCalloutQio (rqptr, Scratch, sptr - Scratch);
            else
               DclCalloutQio (rqptr, RspMustRequire, sizeof(RspMustRequire)-1);
         }
         else
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspForbidden, sizeof(RspForbidden)-1);
         return;
      }

      if (TOUP(OutputPtr[6]) == 'E' &&
          strsame (OutputPtr, "AGENT-END:", 10))
      {
         /**************/
         /* AGENT-END: */
         /**************/

         if (cptr = rqptr->AgentRequestPtr)
         {
            /* receive the result as a string */
            for (cptr = OutputPtr + 10; *cptr && isspace(*cptr); cptr++);
            if (*cptr)
            {
               for (sptr = cptr; *sptr; sptr++);
               rqptr->AgentResponsePtr = VmGetHeap (rqptr, sptr - cptr);
               for (sptr = rqptr->AgentResponsePtr; *cptr; *sptr++ = *cptr++);
               if (ProvideResponse)
                  DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
            }
            else
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         }
         else
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspForbidden, sizeof(RspForbidden)-1);
         return;
      }

      if (TOUP(OutputPtr[5]) == 'F' &&
          strsame (OutputPtr, "AUTH-FILE:", 10))
      {
         /**************/
         /* AUTH-FILE: */
         /**************/

         /* authorize access to a particular file */
         for (cptr = OutputPtr+10; *cptr && isspace(*cptr); cptr++);
         if (!*cptr)
         {
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
            return;
         }
         FileNamePtr = cptr;
         while (*cptr && !isspace(*cptr)) cptr++;
         if (rqptr->rqAuth.VmsUserProfileLength)
         {
            status = AuthAccessReadCheck (rqptr, FileNamePtr, cptr-FileNamePtr);
            if (ProvideResponse)
            {
               if (status == SS$_NOPRIV)
                  DclCalloutQio (rqptr, RspForbidden, sizeof(RspForbidden)-1);
               else
               if (VMSok (status))
                  DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
               else
               {
                  /* error reported by access check */
                  FaoToBuffer (Scratch, sizeof(Scratch), NULL,
                               "400 %!&M", status);
                  DclCalloutQio (rqptr, Scratch, strlen(Scratch));
               }
            }
         }
         else
         if (ProvideResponse)
         {
            /* i.e. request does not have a VMS profile associated */
            DclCalloutQio (rqptr, RspUnauthorized, sizeof(RspUnauthorized)-1);
         }
         return;
      }
   }

   if (TOUP(OutputPtr[0]) == 'B')
   {
      if (TOUP(OutputPtr[7]) == 'B' &&
          strsame (OutputPtr, "BUFFER-BEGIN:", 13))
      {
         /******************/
         /* BUFFER-BEGIN: */
         /*****************/

         if (ProvideResponse)
         {
            cptr = DclMemBufBegin (tkptr, OutputPtr+13);
            DclCalloutQio (rqptr, cptr, strlen(cptr));
         }
         else
            DclCalloutQio (rqptr, RspMustRequire, sizeof(RspMustRequire)-1);

         return;
      }
      else
      if (TOUP(OutputPtr[7]) == 'E' &&
          strsame (OutputPtr, "BUFFER-END:", 11))
      {
         /***************/
         /* BUFFER-END: */
         /***************/

         cptr = DclMemBufEnd (tkptr, OutputPtr+11);

         if (ProvideResponse)
            DclCalloutQio (rqptr, cptr, strlen(cptr));

         return;
      }
      else
      if (TOUP(OutputPtr[7]) == 'W' &&
          strsame (OutputPtr, "BUFFER-WRITE:", 13))
      {
         /*****************/
         /* BUFFER-WRITE: */
         /*****************/

         if (ProvideResponse)
         {
            cptr = DclMemBufWrite (tkptr, OutputPtr+13);
            /* DclMemBufReady() can send the response asynchronously */
            if (cptr) DclCalloutQio (rqptr, cptr, strlen(cptr));
         }
         else
            DclCalloutQio (rqptr, RspMustRequire, sizeof(RspMustRequire)-1);

         return;
      }

      if (ProvideResponse)
         DclCalloutQio (rqptr, RspUnknown, sizeof(RspUnknown)-1);

      return;
   }

   if (TOUP(OutputPtr[0]) == 'C')
   {
      if (TOUP(OutputPtr[3]) == 'P' && 
          strsame (OutputPtr, "CGIPLUS:", 8))
      {
         /************/
         /* CGIPLUS: */
         /************/

         for (cptr = OutputPtr+8; *cptr && isspace(*cptr); cptr++);
         if (strsame (cptr, "STRUCT", 6))
            tkptr->CgiPlusVarStruct = true;
         else
         if (strsame (cptr, "RECORD", 6))
            tkptr->CgiPlusVarStruct = false;
         else
         {
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
            return;
         }

         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);

         return;
      }

      if (TOUP(OutputPtr[7]) == 'R' && 
          strsame (OutputPtr, "CLIENT-READ:", 12))
      {
         /***************/
         /* CLIENT-READ */
         /***************/

         tkptr->ClientReadStripCrLf = false;
         for (cptr = OutputPtr+12; *cptr && isspace(*cptr); cptr++);
         if (*cptr)
         {
            if (strsame (cptr, "STRIPCRLF", 9))
               tkptr->ClientReadStripCrLf = true;
            else
            {
               if (ProvideResponse)
                  DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
               return;
            }
         }

         /* allocate some storage for buffering this I/O */
         tkptr->ClientReadBufferPtr =
            VmGetHeap (rqptr, tkptr->ClientReadBufferSize = NetReadBufferSize);

         /* once we start reading into the buffer the request header is kaput */
         rqptr->rqHeader.RequestHeaderPtrInvalid = true;

         /* queue the first read from the client */
         NetRead (rqptr, &DclClientReadAst,
                  tkptr->ClientReadBufferPtr, tkptr->ClientReadBufferSize);
         tkptr->QueuedClientRead++;

         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);

         return;
      }

      if (TOUP(OutputPtr[2]) == 'P' && 
          strsame (OutputPtr, "CSP:", 4))
      {
         /*************************************/
         /* CSP: ("content-security-policy:") */
         /*************************************/

         REQUEST_PATHSET  *rqpsptr = &rqptr->rqPathSet;

         for (cptr = OutputPtr+4; *cptr && isspace(*cptr); cptr++);
         for (sptr = cptr; *sptr; sptr++);
         length = sptr - cptr;

         if (!length || strsame (cptr, "NONE", -1))
         {
            rqpsptr->ResponseCspPtr = NULL;
            rqpsptr->ResponseCspLength = 0;
         }
         else
         {
            rqpsptr->ResponseCspPtr = sptr =
               VmReallocHeap (rqptr, rqpsptr->ResponseCspPtr,
                              rqpsptr->ResponseCspLength + length+2, FI_LI);
            if (rqpsptr->ResponseCspLength)
            {
               sptr += rqpsptr->ResponseCspLength;
               *sptr++ = ' ';
            }
            memcpy (sptr, cptr, length);
            sptr += length;
            rqpsptr->ResponseCspLength = sptr - rqpsptr->ResponseCspPtr;
         }

         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);

         return;
      }

      if (TOUP(OutputPtr[4]) == 'O' && 
          strsame (OutputPtr, "CSPRO:", 6))
      {
         /************************************/
         /* CSPRO: ("..policy-report-only:") */
         /************************************/

         REQUEST_PATHSET  *rqpsptr = &rqptr->rqPathSet;

         for (cptr = OutputPtr+6; *cptr && isspace(*cptr); cptr++);
         for (sptr = cptr; *sptr; sptr++);
         length = sptr - cptr;

         if (!length || strsame (cptr, "NONE", -1))
         {
            rqpsptr->ResponseCsproPtr = NULL;
            rqpsptr->ResponseCsproLength = 0;
         }
         else
         {
            rqpsptr->ResponseCsproPtr = sptr =
               VmReallocHeap (rqptr, rqpsptr->ResponseCsproPtr,
                              rqpsptr->ResponseCsproLength + length+2, FI_LI);
            if (rqpsptr->ResponseCsproLength)
            {
               sptr += rqpsptr->ResponseCsproLength;
               *sptr++ = ' ';
            }
            memcpy (sptr, cptr, length);
            sptr += length;
            rqpsptr->ResponseCsproLength = sptr - rqpsptr->ResponseCsproPtr;
         }

         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);

         return;
      }

      if (TOUP(OutputPtr[8]) == 'T' && 
          strsame (OutputPtr, "CONTENT-TYPE:", 13))
      {
         /*****************/
         /* CONTENT-TYPE: */
         /*****************/

         for (cptr = OutputPtr+13; *cptr && isspace(*cptr); cptr++);
         if (!*cptr)
         {
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
            return;
         }
         while (*cptr) cptr++;
         while (cptr > OutputPtr+13 && *cptr != '.' && *cptr != ']') cptr--;
         cptr = ConfigContentType (NULL, cptr);
         zptr = (sptr = Scratch) + sizeof(Scratch)-1;
         memcpy (sptr, "200 ", 4);
         sptr += 4;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         if (ProvideResponse) DclCalloutQio (rqptr, Scratch, sptr - Scratch);
         return;
      }
   }

   cptr = NULL;
   if (TOUP(OutputPtr[0]) == 'C' &&
       strsame (OutputPtr, "CGI:", 4))
   {
      /********/
      /* CGI: */
      /********/

      zptr = (sptr = Scratch) + sizeof(Scratch)-1;
      *sptr++ = DICT_TYPE_CONFIG[0];
      for (cptr = OutputPtr+4; *cptr && isspace(*cptr); cptr++);
      if (*cptr == '!') *sptr++ = '!';
      for (cptr = "cgi_"; *cptr; *sptr++ = *cptr++);
      for (cptr = OutputPtr+4; *cptr && isspace(*cptr); cptr++);
      if (*cptr == '!') cptr++;
   }
   else
   if (TOUP(OutputPtr[0]) == 'D' &&
       strsame (OutputPtr, "DICT:", 5))
   {
      /*********/
      /* DICT: */
      /*********/

      zptr = (sptr = Scratch) + sizeof(Scratch)-1;
      *sptr++ = DICT_TYPE_CONFIG[0];
      for (cptr = OutputPtr+5; *cptr && isspace(*cptr); cptr++);
   }
   if (cptr)
   {
      /*****************/
      /* DICT: or CGI: */
      /*****************/

      /* bit too clever, or prudent, I wonder? */
      if (!*cptr)
      {
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         return;
      }
      while (*cptr && sptr < zptr) *sptr++ = *cptr++;
      *sptr = '\0';

      MetaConDictionary (rqptr, Scratch);
      if (WATCHPNT(rqptr) && (WATCH_CATEGORY(WATCH_CGI) &&
                              WATCH_CATEGORY(WATCH_INTERNAL)))
         DictWatch (rqptr->rqDictPtr, DICT_TYPE_CONFIG, "*");
      if (ProvideResponse)
      {
         zptr = (sptr = Scratch) + sizeof(Scratch)-1;
         for (cptr = "200 "; *cptr; *sptr++ = *cptr++);
         for (cptr = Scratch; *cptr; *sptr++ = *cptr++);
         *sptr = '\0';
         DclCalloutQio (rqptr, Scratch, sptr - Scratch);
      }
      return;
   }

   if (Config.cfScript.GatewayBg)
   {
      if (TOUP(OutputPtr[0]) == 'G' &&
          strsame (OutputPtr, "GATEWAY-BEGIN:", 14))
      {
         /* HTTP status code of response directly to the BG (socket) device */
         for (cptr = OutputPtr+14; *cptr && isspace(*cptr); cptr++);
         if (isdigit(*cptr))
         {
            number = atoi(cptr);
            rqptr->rqResponse.HttpStatus = number;
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
         }               
         else
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);

         /* flush any network header already provided */
         NetWrite (rqptr, NULL, NULL, 0);

         return;
      }
      else
      if (TOUP(OutputPtr[0]) == 'G' &&
          strsame (OutputPtr, "GATEWAY-CCL:", 12))
      {
         /* directly control the BG device carriage-control bit */
         for (cptr = OutputPtr+12; *cptr && isspace(*cptr); cptr++);
         if (HTTP2_REQUEST(rqptr))
            status = SS$_BADPARAM;
         else
         if (isdigit(*cptr))
         {
            number = atoi(cptr);
            if (number == 1)
               status = NetClientSocketCcl (rqptr->NetIoPtr, 1);
            else
            if (number == 0)
               status = NetClientSocketCcl (rqptr->NetIoPtr, 0);
            else
               status = SS$_BADPARAM;
         }               
         else
            status = SS$_BADPARAM;

         if (ProvideResponse)
            if (VMSok(status))
               DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
            else
               DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         return;
      }
      else
      if (TOUP(OutputPtr[0]) == 'G' &&
          strsame (OutputPtr, "GATEWAY-END:", 12))
      {
         /* count of bytes output directly to the BG (socket) device */
         for (cptr = OutputPtr+12; *cptr && isspace(*cptr); cptr++);
         if (isdigit(*cptr))
         {
            number = atoi(cptr);
            rqptr->NetIoPtr->BytesRawTx64 += number;
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
         }               
         else
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         return;
      }
   }

   if (TOUP(OutputPtr[0]) == 'H' &&
       strsame (OutputPtr, "HTTP-STATUS:", 12))
   {
      /****************/
      /* HTTP-STATUS: */
      /****************/

      if (ProvideResponse)
      {
         length = sprintf (Scratch, "200 %d", rqptr->rqResponse.HttpStatus);
         DclCalloutQio (rqptr, Scratch, length);
      }
      return;
   }

   if (TOUP(OutputPtr[0]) == 'I' &&
       strsame (OutputPtr, "ICON-TYPE:", 10))
   {
      /**************/
      /* ICON-TYPE: */
      /**************/

      for (cptr = OutputPtr+10; *cptr && isspace(*cptr); cptr++);
      if (!*cptr)
      {
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         return;
      }
      sptr = cptr;
      while (*cptr) cptr++;
      while (cptr > OutputPtr+10 && *cptr != '.' &&
             *cptr != ']' && *cptr != '/') cptr--;
      if (*cptr == '.')
         cptr = ConfigContentType (NULL, cptr);
      else
         cptr = sptr;
      cptr = ConfigIconFor (cptr, NULL, NULL);
      zptr = (sptr = Scratch) + sizeof(Scratch)-1;
      memcpy (sptr, "200 ", 4);
      sptr += 4;
      while (*cptr && sptr < zptr) *sptr++ = *cptr++;
      *sptr = '\0';
      if (ProvideResponse) DclCalloutQio (rqptr, Scratch, sptr - Scratch);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'L' &&
       strsame (OutputPtr, "LIFETIME:", 9))
   {
      /*************/
      /* LIFETIME: */
      /*************/

      /* let a CGIplus script set/reset its own lifetime */
      for (cptr = OutputPtr+9; *cptr && isspace(*cptr); cptr++);
      if ((TOUP(*cptr) == 'D' && strsame (cptr, "DO-NOT-DISTURB", 4)) ||
          (TOUP(*cptr) == 'N' && strsame (cptr, "NONE", 4)))
         tkptr->LifeTimeSecond = DCL_DO_NOT_DISTURB;
      else
      if (!isdigit(*cptr))
      {
         /* anything other than a valid number reverts to config values */
         if (tkptr->TaskType == DCL_TASK_TYPE_CGI_SCRIPT)
            tkptr->LifeTimeSecond = HttpdTickSecond +
                                    Config.cfScript.ZombieLifeTime;
         else
            tkptr->LifeTimeSecond = HttpdTickSecond +
                                    Config.cfScript.CgiPlusLifeTime;
      }
      else
         tkptr->LifeTimeSecond = HttpdTickSecond +
                                 MetaConSetSeconds (NULL, cptr, 60);

      if (ProvideResponse)
         DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'M' &&
       TOUP(OutputPtr[4]) == 'F' && 
       strsame (OutputPtr, "MAP-FILE:", 9))
   {
      /*************/
      /* MAP-FILE: */
      /*************/

      Scratch[4] = '\0';
      for (cptr = OutputPtr+9; *cptr && isspace(*cptr); cptr++);
      if (!*cptr)
      {
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         return;
      }
      cptr = MapUrl_Map (Scratch+4, sizeof(Scratch)-4, cptr, 0,
                         NULL, 0, NULL, 0, NULL, 0, NULL, rqptr, NULL);
      if (!cptr[0] && cptr[1])
      {
         memcpy (Scratch, "400 ", 4);
         strcpy (Scratch+4, cptr+1);
         if (ProvideResponse)
            DclCalloutQio (rqptr, Scratch, strlen(Scratch));
      }
      else
      {
         memcpy (Scratch, "200 ", 4);
         /* for backward comptibility (pre8.1) URL-encode the supplied path */
         length = StringUrlEncode (cptr, Scratch+4, sizeof(Scratch)-4);
         if (ProvideResponse)
            DclCalloutQio (rqptr, Scratch, length+4);
      }
      return;
   }

   if (TOUP(OutputPtr[0]) == 'M' &&
       TOUP(OutputPtr[4]) == 'P' && 
       strsame (OutputPtr, "MAP-PATH:", 9))
   {
      /*************/
      /* MAP-PATH: */
      /*************/

      Scratch[4] = '\0';
      for (cptr = OutputPtr+9; *cptr && isspace(*cptr); cptr++);
      if (!*cptr)
      {
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         return;
      }
      cptr = MapUrl_Map (cptr, 0, Scratch+4, sizeof(Scratch)-4,
                         NULL, 0, NULL, 0, NULL, 0, NULL, rqptr, NULL);
      if (!cptr[0] && cptr[1])
      {
         memcpy (Scratch, "400 ", 4);
         strcpy (Scratch+4, cptr+1);
         if (ProvideResponse)
            DclCalloutQio (rqptr, Scratch, strlen(Scratch));
      }
      else
      {
         if (strsame (Scratch+4, MAPURL_NO_REVERSE_PATH, -1))
            memcpy (Scratch, "400 ", 4);
         else
            memcpy (Scratch, "200 ", 4);
         if (ProvideResponse)
            DclCalloutQio (rqptr, Scratch, strlen(Scratch));
      }
      return;
   }

   if (TOUP(OutputPtr[0]) == 'N')
   {
      if (strsame (OutputPtr, "NOTICED:", 8))
      {
         /************/
         /* NOTICED: */
         /************/

         /* 'error' noticed by agent */
         for (cptr = OutputPtr+8; *cptr && ISLWS(*cptr); cptr++);
         for (sptr = cptr; *sptr && NOTEOL(*sptr); sptr++);
         *sptr = '\0';
         ErrorNoticed (rqptr, 0, cptr, FI_LI);
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
         return;
      }

      if (strsame (OutputPtr, "NOOP:", 5))
      {
         /*********/
         /* NOOP: */
         /*********/

         /* used for WATCHable debugging information, comments, etc. */
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
         return;
      }
   }

   if (TOUP(OutputPtr[0]) == 'O' &&
       strsame (OutputPtr, "OPCOM:", 6))
   {
      for (cptr = OutputPtr+6; *cptr && ISLWS(*cptr); cptr++);
      for (sptr = cptr; *sptr && NOTEOL(*sptr); sptr++);
      *sptr = '\0';

      FaoToStdout (
"%HTTPD-W-DCLOPCOM, !20%D, !AZ\n\
-DCLOPCOM-I-SERVICE, !AZ//!AZ\n\
-DCLOPCOM-I-CLIENT, !AZ\n\
-DCLOPCOM-I-USERNAME, \"!AZ\" in \"!AZ\"\n\
-DCLOPCOM-I-URI, !AZ !AZ\n",
         0, cptr,
         rqptr->ServicePtr->RequestSchemeNamePtr,
         rqptr->ServicePtr->ServerHostPort,
         ClientHostString(rqptr),
         rqptr->rqAuth.RemoteUser[0] ? rqptr->rqAuth.RemoteUser : "-",
         rqptr->rqAuth.RealmDescrPtr[0] ? rqptr->rqAuth.RealmDescrPtr : "-",
         rqptr->rqHeader.MethodName, rqptr->rqHeader.RequestUriPtr);

      if (OpcomMessages & OPCOM_HTTPD)
         FaoToOpcom (
"%HTTPD-W-DCLOPCOM, !AZ\r\n\
-DCLOPCOM-I-SERVICE, !AZ//!AZ\r\n\
-DCLOPCOM-I-CLIENT, !AZ\r\n\
-DCLOPCOM-I-USERNAME, \"!AZ\" in \"!AZ\"\r\n\
-DCLOPCOM-I-URI, !AZ !AZ",
            cptr,
            rqptr->ServicePtr->RequestSchemeNamePtr,
            rqptr->ServicePtr->ServerHostPort,
            ClientHostString(rqptr),
            rqptr->rqAuth.RemoteUser[0] ? rqptr->rqAuth.RemoteUser : "-",
            rqptr->rqAuth.RealmDescrPtr[0] ? rqptr->rqAuth.RealmDescrPtr : "-",
            rqptr->rqHeader.MethodName, rqptr->rqHeader.RequestUriPtr);

      if (ProvideResponse)
         DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);

      return;
   }

   if (TOUP(OutputPtr[0]) == 'R' &&
       TOUP(OutputPtr[7]) == 'S' && 
       strsame (OutputPtr, "REDACT-SIZE:", 12))
   {
      /****************/
      /* REDACT-SIZE: */
      /****************/

      RequestRedact (rqptr, OutputPtr, OutputCount, ProvideResponse);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'S' &&
       TOUP(OutputPtr[7]) == 'C' && 
       strsame (OutputPtr, "SCRIPT-CONTROL:", 15))
   {
      /*******************/
      /* SCRIPT-CONTROL: */
      /*******************/

      for (cptr = OutputPtr+15; *cptr && ISLWS(*cptr); cptr++);
      length = CgiScriptControlField (rqptr, cptr);
      if (ProvideResponse)
         if (length)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
         else
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'T' &&
       TOUP(OutputPtr[8]) == 'B' && 
       strsame (OutputPtr, "TIMEOUT-BIT-BUCKET:", 19))
   {
      /***********************/
      /* TIMEOUT-BIT-BUCKET: */
      /***********************/

      /* let a script SPECIFY it's own per-task bit-bucket timeout */
      for (cptr = OutputPtr+19; *cptr && isspace(*cptr); cptr++);
      if (isdigit(*cptr))
      {
         if (strsame (cptr, "none", 4))
            number = 0;
         else
            number = atoi(cptr);
         tkptr->BitBucketTimeout = number;
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
      }               
      else
      if (ProvideResponse)
         DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'T' &&
       TOUP(OutputPtr[8]) == 'N' && 
       strsame (OutputPtr, "TIMEOUT-NOPROGRESS:", 19))
   {
      /***********************/
      /* TIMEOUT-NOPROGRESS: */
      /***********************/

      /* let a script set/reset it's own per-request no-progress timeout */
      for (cptr = OutputPtr+19; *cptr && isspace(*cptr); cptr++);
      if (isdigit(*cptr))
      {
         if (strsame (cptr, "none", 4))
            number = -1;
         else
            number = atoi(cptr);
         HttpdTimerSet (rqptr, TIMER_NOPROGRESS, number);
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
      }               
      else
      if (ProvideResponse)
         DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'T' &&
       TOUP(OutputPtr[8]) == 'O' && 
       strsame (OutputPtr, "TIMEOUT-OUTPUT:", 15))
   {
      /*******************/
      /* TIMEOUT-OUTPUT: */
      /*******************/

      /* let a script set/reset its own per-request output timeout */
      for (cptr = OutputPtr+15; *cptr && isspace(*cptr); cptr++);
      if (strsame (cptr, "none", 4))
      {
         HttpdTimerSet (rqptr, TIMER_OUTPUT, -1);
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
      }
      else
      if (isdigit(*cptr))
      {
         number = atoi(cptr);
         HttpdTimerSet (rqptr, TIMER_OUTPUT, number);
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
      }               
      else
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
      return;
   }

   if (TOUP(OutputPtr[0]) == 'W')
   {
      if (strsame (OutputPtr, "WATCH:", 6))
      {
         /**********/
         /* WATCH: */
         /**********/

         /* WATCHing script */
         for (cptr = OutputPtr+6; *cptr && isspace(*cptr); cptr++);
         if (WATCHING (rqptr, WATCH_SCRIPT))
         {
            /* request is being WATCHed and [x]Script is checked */
            WatchThis (WATCHITM(rqptr), WATCH_SCRIPT, "!AZ", cptr);
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
         }
         else
         if ((Watch.Category & WATCH_SCRIPT) &&
             !(Watch.Category & ~WATCH_SCRIPT))
         {
            /* only [x]Script is checked (e.g. WATCH proctored script) */
            WatchThis (WATCHALL, WATCH_SCRIPT, "!AZ", cptr);
            if (ProvideResponse)
               DclCalloutQio (rqptr, RspSuccess, sizeof(RspSuccess)-1);
         }
         else
         if (ProvideResponse)
            DclCalloutQio (rqptr, RspBadParam, sizeof(RspBadParam)-1);
         return;
      }
   }

   if (ProvideResponse)
      DclCalloutQio (rqptr, RspUnknown, sizeof(RspUnknown)-1);
}

/*****************************************************************************/
/*
Whenever there is an active script process (not necessarily processing a
request) this function is called every second by HttpdTick().  It only scans
the list of script tasks every so-many seconds.  This can be varied to provide
greater or lesser granularity depending on requirements (some events benfit
from closer observation).  Periodically scan the list of DCL script processes
looking for those whose lifetimes have expired.  Run those script processes
down!  A lifetime count of DCL_DO_NOT_DISTURB (-1) indicates the script process
has requested that it be immune to supervisor purging (and some other other
proactive administration).  Return true to indicate that the HTTPd should
continue to tick.
*/

BOOL DclSupervisor (int PeriodSeconds)

{
   static int  CleanupSecond = 0,
               TaskScanSeconds = 0;

   BOOL  ContinueTicking;
   int  idx, status,
        MinSeconds;
   LIST_ENTRY  *leptr, *nxtptr;
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL) && PeriodSeconds != -1)
      WatchThis (WATCHALL, WATCH_MOD_DCL,
                 "DclSupervisor() !SL !UL", PeriodSeconds, HttpdTickSecond);

   if (PeriodSeconds >= 0)
   {
      /* initiate or reset the task supervisor ticking */
      if (PeriodSeconds)
      {
         if (HttpdTickSecond + PeriodSeconds < TaskScanSeconds &&
             PeriodSeconds >= DCL_SUPERVISOR_TICK_MIN &&
             PeriodSeconds <= DCL_SUPERVISOR_TICK_MAX)
            TaskScanSeconds = HttpdTickSecond + PeriodSeconds;
      }
      else
      if (!TaskScanSeconds)
         TaskScanSeconds = HttpdTickSecond + DCL_SUPERVISOR_TICK_MAX;

      return (false);
   }

   /*******************/
   /* task supervisor */
   /*******************/

   /* no script process is currently executing */
   if (!TaskScanSeconds) return (false);

   /* no need to do a scan just yet */
   if (TaskScanSeconds > HttpdTickSecond) return (true);

   /* if there is no cleanup expiry set then generate one */
   if (DclCleanupMinutesMax && !CleanupSecond)
      CleanupSecond = HttpdTickSecond + DclCleanupMinutesMax * 60;

   ContinueTicking = false;
   MinSeconds = DCL_SUPERVISOR_TICK_MAX;

   for (leptr = DclTaskList.HeadPtr; leptr; leptr = nxtptr)
   {
      /* get the next in the list in case this task is removed */
      nxtptr = leptr->NextPtr;
      tkptr = (DCL_TASK*)leptr;
 
      /* don't want to go deleting process 00000000 (ourselves!) */
      if (!tkptr->ScriptProcessPid) continue;

      ContinueTicking = true;

      /* if no WebSocket attached requests then put a lifetime back on it */
      if (tkptr->LifeTimeSecond == DCL_WEBSOCKET_DND)
         if (!WebSockCount (tkptr->ScriptProcessPid))
             tkptr->LifeTimeSecond = HttpdTickSecond +
                                     Config.cfScript.CgiPlusLifeTime;

      /* proctored process must be independently stable for a short period */
      if (tkptr->ProctorProcess && !tkptr->RequestPtr)
      {
         if (!--tkptr->ProctorProcess) tkptr->ProctorPtr = NULL;
         MinSeconds = 1;
      }

      if (tkptr->RequestPtr)
      {
         if (tkptr->RequestPtr->RequestState >= REQUEST_STATE_ABORT)
         {
            /* if the script is not outputting then this will shake it up */
            DclTaskRunDown (tkptr);
            continue;
         }
      }

      if (tkptr->RequestPtr ||
          (tkptr->LifeTimeSecond > HttpdTickSecond ||
           tkptr->LifeTimeSecond == DCL_DO_NOT_DISTURB ||
           tkptr->LifeTimeSecond == DCL_WEBSOCKET_DND))
      {
         if (!(tkptr->ForceImageExitGetJpi ||
               tkptr->ForceImageExitIssued))
         {
            if (tkptr->ScriptCpuMax)
            {
               /* we're keeping an eye on CPU consumption */
               DclScriptCpuTim (tkptr);
               if (tkptr->ScriptCpuMax < MinSeconds)
                  MinSeconds = tkptr->ScriptCpuMax;
            }
            else
            if (tkptr->LifeTimeSecond - HttpdTickSecond < MinSeconds)
               MinSeconds = tkptr->LifeTimeSecond - HttpdTickSecond;
            continue;
         }
      }

      /* process timer has expired, exterminate ... exxterrminnaattte */
      tkptr->LifeTimeSecond = 0;
      tkptr->DeleteProcess = true;
      DclTaskRunDown (tkptr);

      /* if we're still waiting for image exit then it's not over yet */
      if (tkptr->ForceImageExit) continue;

      if (tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
          tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
         DclCgiPlusLifeTimePurgeCount++;
      else
         DclZombieLifeTimePurgeCount++;
   }

   /* see algorithm description with function DclScriptProctor() */
   for (idx = 0; idx < Config.cfScript.ProctorCount; idx++)
      if (Config.cfScript.Proctor[idx].FailWeight)
         if ((Config.cfScript.Proctor[idx].FailWeight -= MinSeconds) < 0)
            Config.cfScript.Proctor[idx].FailWeight = 0;

   if (CleanupSecond && (CleanupSecond <= HttpdTickSecond || !ContinueTicking))
   {
      /***********/
      /* cleanup */
      /***********/

      /* either the cleanup timer expired or no more scripts */
      if (WATCH_MODULE(WATCH_MOD_DCL))
         WatchThis (WATCHALL, WATCH_MOD_DCL,
                    "CLEANUP !AZ", DclHttpdScratch);

      /* kick off an independent thread of cleanup I/O */
      SysDclAst (&DclCleanupScratch, NULL);

      /* periodically cleanup the script name cache */
      DclPurgeScriptNameCache ();

      CleanupSecond = 0;
   }

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL,
                 "SUPERVISOR !&B !SL", ContinueTicking, MinSeconds);

   if (ContinueTicking)
   {
      /* at least one item in the connect list is still counting down */
      if (MinSeconds < 0) MinSeconds = 0;
      TaskScanSeconds = HttpdTickSecond + MinSeconds;
      return (true);
   }

   /* purge the script name cache when there are no more zombies/CGIplus */
   DclPurgeScriptNameCache ();

   /* reinitialize the supervisor timings */
   CleanupSecond = TaskScanSeconds = 0;

   return (false);
}

/*****************************************************************************/
/*
In an independent thread of execution search the script working/scratch
directory (HT_SCRATCH) checking for files that are older than the limit (based
on their RDT).  This thread is initiated by being called with a NULL as the
parameter.  This initializes the RMS structures and begins an AST-driven
search, calling this function for each search call with the search FAB as the
parameter.  Files found have the revision date/time compared to a date/time the
required number of minutes earlier than the current time.  Those exceeding that
are deleted.  File names beginning with a dollar are never deleted in this way.
*/

void DclCleanupScratch (struct FAB *FabPtr)

{
   BOOL  CleanupUnderway = false;
   static int  FileCount,
               FileDeletedCount,
               FileDollarCount,
               FileHiddenCount;
   static int64  OlderThanTime64;
   static ODS_STRUCT  SearchOds;

   int  status;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL,
                 "DclCleanupScratch() !&F", &DclCleanupScratch);

   if (!FabPtr)
   {
      if (CleanupUnderway) return;
      CleanupUnderway = true;

      FileCount = FileDeletedCount = FileDollarCount = FileHiddenCount = 0;

      /* add the (negative) delta to the current getting an earlier time */
      OlderThanTime64 = HttpdTime64 + (DELTA64_ONE_MIN * DclCleanupMinutesOld);

      OdsStructInit (&SearchOds, true);
      status = OdsParse (&SearchOds, DclHttpdScratch, strlen(DclHttpdScratch),
                         "[...]*.*;*", 10, 0, NULL, 0);
      if (VMSnok (status))
      {
         ErrorNoticed (NULL, status, NULL, FI_LI);
         CleanupUnderway = false;
         return;
      }
   }
   else
   {
      if (VMSnok (status = SearchOds.Fab.fab$l_sts))
      {
         if (status == RMS$_FNF || status == RMS$_NMF)
         {
            if (FileDeletedCount)
               FaoToStdout (
"%HTTPD-I-DCL, !20%D, cleanup !AZ, !UL file!%s, !UL deleted ($!UL/.!UL)\n",
                  0, DclHttpdScratch,
                  FileCount, FileDeletedCount,
                  FileDollarCount, FileHiddenCount);
         }
         else
            ErrorNoticed (NULL, status, NULL, FI_LI);
         CleanupUnderway = false;
         OdsParseRelease (&SearchOds);
         return;
      }

      FileCount++;
      if (SearchOds.NamNamePtr[0] == '$')
         FileDollarCount++;
      else
      if (SearchOds.NamNamePtr[0] == '.')
         FileHiddenCount++;
      else
      {
         status = OdsFileAcpInfo (&SearchOds, NULL, 0); 
         if (VMSnok (status))
         {
            ErrorNoticed (NULL, status, NULL, FI_LI);
            CleanupUnderway = false;
            OdsParseRelease (&SearchOds);
            return;
         }
         if (SearchOds.FileQio.RdtTime64 < OlderThanTime64)
         {
            /* use SYSPRV to ensure the file is deleted */
            sys$setprv (1, &SysPrvMask, 0, 0);
            SearchOds.Fab.fab$l_fop = FAB$M_NAM;
            status = sys$erase (&SearchOds.Fab, 0, 0);
            sys$setprv (0, &SysPrvMask, 0, 0);
            if (VMSok (status)) FileDeletedCount++;
         }
      }
   }

   OdsSearch (&SearchOds, &DclCleanupScratch, &SearchOds.Fab);
}

/*****************************************************************************/
/*
Scan all detached processes on the system looking for those with a mailbox
'terminal' with the server's 'special' identifier in an ACL.  Delete these
processes. This function is called to clean-up detached script processes that
may have been left on the system if a server is sys$delprc()ed in some way
(e.g. STOP/id=).  Normally the image exit handler will delete these during
user-mode image rundown.  This function obviously must be called during server
startup prior to actually beginning to process requests.
*/

/* seems a lot but I recall some site having a HUGE number of IDs */
#define JPI_PROCESS_RIGHTS_MAX 1024

#define PSCAN$_GETJPI_BUFFER_SIZE 24
#define PSCAN$_TERMINAL 21 
#define PSCAN$M_PREFIX_MATCH 0x80
#define PSCAN$M_EQL 0x400

DclCleanupScriptProcesses ()

{
   static $DESCRIPTOR (ProcessIdentNameDsc, "");
   static unsigned long  GetJpiControlFlags = JPI$M_IGNORE_TARGET_STATUS;

   static unsigned long  JpiPid,
                         JpiRightsSize;
   static char  JpiPrcNam [16],
                JpiUserName [13];

   static struct
   {
      unsigned short  buf_len;
      unsigned short  item;
      unsigned char   *buf_addr;
      unsigned long   *short_ret_len;
   }
      JpiItems [] =
   {
      { sizeof(GetJpiControlFlags), JPI$_GETJPI_CONTROL_FLAGS,
        &GetJpiControlFlags, 0 },
      { sizeof(JpiPid), JPI$_PID, &JpiPid, 0 },
      { sizeof(JpiPrcNam), JPI$_PRCNAM, &JpiPrcNam, 0 },
      { sizeof(JpiUserName), JPI$_USERNAME, &JpiUserName, 0 },
      { sizeof(JpiRightsSize), JPI$_RIGHTS_SIZE, &JpiRightsSize, 0 },
#define JPI_PROCESS_RIGHTS_ITEM 5
      { 0, JPI$_PROCESS_RIGHTS, 0, 0 },
      { 0,0,0,0 }
   },
      ScanItems [] =
   {
      { 0, PSCAN$_GETJPI_BUFFER_SIZE, 2048, 0 },
      { 0,0,0,0 }
   };

   int  idx, status,
        Context,
        IdentCount,
        ProcessCount,
        SetPrvStatus;
   unsigned long  ProcessContext;
   unsigned long  JpiProcessRights [JPI_PROCESS_RIGHTS_MAX*2];
   char  *cptr;
   IO_SB  IOsb;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclCleanupScriptProcesses()");

   /* create the identifier if it does not already exist */
   ProcessIdentNameDsc.dsc$a_pointer = ProcessIdentName;
   ProcessIdentNameDsc.dsc$w_length = strlen(ProcessIdentName);
   status = sys$asctoid (&ProcessIdentNameDsc, &ProcessRightsIdent, 0);
   if (VMSnok (status))
   {
      /* use SYSPRV to allow access to the rights database */
      sys$setprv (1, &SysPrvMask, 0, 0);
      status = sys$add_ident (&ProcessIdentNameDsc, 0, 0,
                              &ProcessRightsIdent);
      sys$setprv (0, &SysPrvMask, 0, 0);
      if (VMSok (status))
         FaoToStdout (
"%HTTPD-I-RDBADDMSG, identifier !AZ value !&S added to rights database\n",
            ProcessIdentName, ProcessRightsIdent[0]);
      else
      {
         FaoToStdout (
"%HTTPD-W-RDBADDERRU, unable to add !AZ to rights database\n-!&M\n",
            ProcessIdentName, status);
         ErrorExitVmsStatus (status, "sys$add_ident", FI_LI);
      }
   }
   ProcessRightsIdent[1] = KGB$M_NOACCESS;

   JpiItems[JPI_PROCESS_RIGHTS_ITEM].buf_len = sizeof(JpiProcessRights);
   JpiItems[JPI_PROCESS_RIGHTS_ITEM].buf_addr = &JpiProcessRights;

   ProcessContext = 0;
   status = sys$process_scan (&ProcessContext, &ScanItems);
   if (VMSnok (status))
   {
      ErrorNoticed (NULL, status, NULL, FI_LI);
      return;
   }

   /* enable WORLD so we can access *all* processes */
   if (VMSnok (SetPrvStatus = sys$setprv (1, &MailboxMask, 0, 0)))
      ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   ProcessCount = 0;
   for (;;)
   {
      status = sys$getjpiw (EfnWait, &ProcessContext, 0,  &JpiItems,
                            &IOsb, 0, 0);
      if (VMSok (status)) status = IOsb.Status;
      if (VMSnok (status)) break;

      ProcessCount++;

      JpiUserName[12] = '\0';
      for (cptr = JpiUserName; *cptr && *cptr != ' '; cptr++);
      *cptr = '\0';

      JpiPrcNam[15] = '\0';
      for (cptr = JpiPrcNam; *cptr && *cptr != ' '; cptr++);
      *cptr = '\0';

      if (WATCH_MODULE(WATCH_MOD_DCL))
         WatchThis (WATCHALL, WATCH_MOD_DCL, "!8XL !&Z !&Z !UL",
                    JpiPid, JpiUserName, JpiPrcNam, JpiRightsSize);

      if (JpiRightsSize > sizeof(JpiProcessRights))
      {
         char  Buffer [32];
         sprintf (Buffer, "sys$getjpiw() %08.08X", JpiPid);
         ErrorNoticed (NULL, SS$_BUFFEROVF, Buffer, FI_LI);
      }

      /* look through each of the identifiers in the list */
      idx = 0;
      for (IdentCount = JpiRightsSize / 8;
           IdentCount && JpiProcessRights[idx] != ProcessRightsIdent[0];
           IdentCount--) idx += 2;

      /* if we didn't find the identifier then continue */
      if (!IdentCount) continue;

      /* I've seen this happen once and couldn't work out why!! */
      if (JpiPid == HttpdProcess.Pid) continue;

      FaoToStdout (
"%HTTPD-I-DCL, cleanup detached script process; !8XL !AZ \'!AZ\'\n",
         JpiPid, JpiUserName, JpiPrcNam);
      status = sys$delprc (&JpiPid, 0);
      if (VMSnok (status)) ErrorNoticed (NULL, status, NULL, FI_LI); 
   }

   if (VMSnok (SetPrvStatus = sys$setprv (0, &MailboxMask, 0, 0)))
      ErrorExitVmsStatus (SetPrvStatus, "sys$setprv()", FI_LI);

   if (status != SS$_NOMOREPROC)
   {
      ErrorNoticed (NULL, status, NULL, FI_LI);
      return;
   }
}

/*****************************************************************************/
/*
Create an ACL comprising an ACE allowing full access for the 'AllowName'
identifier and apply it to the specified mailbox.  If $PARSE_ACL fails on
SS$_NOSUCHID then try an ACE using the UIC of the supplied name.  This will
support scenarios where multiple usernames (accounts) share the same UIC and
only the one account rights identifier is available.
*/

#define OSS$M_RELCTX 0x2
#define OSS$_ACL_ADD_ENTRY 3
#define OSS$_ACL_POSITION_TOP 14
#define OSS$_ACL_READ_ENTRY 16
#define PSL$C_USER 3

#ifdef GET_SET_SECURITY_STUB

int DclMailboxAcl
(
char *MailboxName,
char *AllowName
)
{
   /* sys$get/set_security() not supported for this VMS version */
   ErrorNoticed (rqptr, 0, "feature not supported on this platform", FI_LI);
   return (SS$_ABORT);
}

#else /* GET_SET_SECURITY_STUB */

int DclMailboxAcl
(
char *MailboxName,
char *AllowName
)
{
   static $DESCRIPTOR (AclAllowFaoDsc, "(IDENT=!AZ,ACCESS=R+W+E+D)\0");
   static $DESCRIPTOR (AclAllowUicFaoDsc, "(IDENT=!%U,ACCESS=R+W+E+D)\0");
   static $DESCRIPTOR (ClassNameDsc, "DEVICE");

   static unsigned long  AccessMode = PSL$C_USER,
                         SecFlags = OSS$M_RELCTX,
                         UaiContext = -1,
                         UaiUic;
   static unsigned short  Length;
   static unsigned char  AclAllowEntry [32],
                         AclReadEntry [32];
   static char  AclString [64],
                PrevAllowName [32];
   static $DESCRIPTOR (AclAllowEntryDsc, AclAllowEntry);
   static $DESCRIPTOR (AclStringDsc, AclString);
   static $DESCRIPTOR (AllowNameDsc, "");
   static $DESCRIPTOR (MailboxNameDsc, "");
   static struct {
      unsigned short  buf_len;
      unsigned short  item;
      unsigned char  *buf_addr;
      unsigned long  *long_ret_len;
   }
   SetSecItems [] =
   {
      { 0, OSS$_ACL_ADD_ENTRY, AclAllowEntry, 0 },
      {0,0,0,0}
   },
   GetSecItems [] =
   {
      { 0, OSS$_ACL_POSITION_TOP, 0, 0 },
      { sizeof(AclReadEntry), OSS$_ACL_READ_ENTRY, AclReadEntry, &Length },
      {0,0,0,0}
   },
   UaiItems [] = 
   {
      { sizeof(UaiUic), UAI$_UIC, &UaiUic, 0 },
      { 0,0,0,0 }
   };

   int  status;
   unsigned long  Context;
   unsigned short  ErrorPos;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclMailboxAcl() !&Z !&Z !&Z",
                 MailboxName, AllowName, PrevAllowName);

   MailboxNameDsc.dsc$a_pointer = MailboxName;
   MailboxNameDsc.dsc$w_length = strlen(MailboxName);

   if (strcmp (AllowName, PrevAllowName))
   {
      /****************************/
      /* new name to allow access */
      /****************************/

      PrevAllowName[0] = '\0';

      status = sys$fao (&AclAllowFaoDsc, 0, &AclStringDsc, AllowName);
      if (VMSnok (status)) return (status);

      strzcpy (PrevAllowName, AllowName, sizeof(PrevAllowName));

      /* parse the ACE */
      AclStringDsc.dsc$a_pointer = AclString;
      AclStringDsc.dsc$w_length = strlen(AclString);
      status = sys$parse_acl (&AclStringDsc, &AclAllowEntryDsc,
                              &ErrorPos, 0, 0);
      AclStringDsc.dsc$w_length = sizeof(AclString)-1;
   }
   else
      status = SS$_NORMAL;

   UaiUic = 0;
   for (;;)
   {
      if (VMSok (status))
      {
         /*******************************/
         /* apply ACL to mailbox device */
         /*******************************/

         if (WATCH_MODULE(WATCH_MOD_DCL))
            WatchThis (WATCHALL, WATCH_MOD_DCL, "!AZ", AclString);

         SetSecItems[0].buf_len = AclAllowEntry[0];
         Context = 0;
         status = sys$set_security (&ClassNameDsc, &MailboxNameDsc, 0, SecFlags,
                                    &SetSecItems, &Context, &AccessMode);
         /* if successful */
         if (VMSok(status)) return (status);
      }

      /* if some other error or already had a go at this */
      if (status != SS$_NOSUCHID || UaiUic) break;

      /***************************/
      /* try a UIC specification */
      /***************************/

      AllowNameDsc.dsc$a_pointer = AllowName;
      AllowNameDsc.dsc$w_length = strlen(AllowName);

      sys$setprv (1, &SysPrvMask, 0, 0);
      status = sys$getuai (0, &UaiContext, &AllowNameDsc, &UaiItems,
                           0, 0, 0);
      sys$setprv (0, &SysPrvMask, 0, 0);

      if (WATCH_MODULE(WATCH_MOD_DCL))
         WatchThis (WATCHALL, WATCH_MOD_DCL, "sys$getuai() !&S", status);

      if (VMSnok(status)) break;

      status = sys$fao (&AclAllowUicFaoDsc, 0, &AclStringDsc, UaiUic);
      if (VMSnok (status)) break;

      /* parse the ACE */
      AclStringDsc.dsc$a_pointer = AclString;
      AclStringDsc.dsc$w_length = strlen(AclString);
      status = sys$parse_acl (&AclStringDsc, &AclAllowEntryDsc,
                              &ErrorPos, 0, 0);
      AclStringDsc.dsc$w_length = sizeof(AclString)-1;
   }

   /* failure */
   PrevAllowName[0] = '\0';
   return (status);
}

#endif /* GET_SET_SECURITY_STUB */

/*****************************************************************************/
/*
************
*** NOTE ***  This function takes a pointer to a request!!!
************  Due to it being a general report processing function.

Return a report on the DCL task structure.  This function blocks while
executing.
*/ 

void DclScriptingReport (REQUEST_STRUCT *rqptr)

{
   static char  PageBeginFao [] =
"<p><table class=\"ctgry\">\n\
<tr><td>\n\
\
<table class=\"rghtlft\">\n\
<tr><th class=\"sbttl\">Statistics</th></tr>\n\
<tr><th>CGI:</th><td>!&L</td></tr>\n\
<tr><th>CGIplus&nbsp;&nbsp;/All:</th><td>!&L</td></tr>\n\
<tr><th>/Reused:</th><td>!&L</td><td class=\"targht\">(!UL%)</td></tr>\n\
<tr><th>RTE&nbsp;&nbsp;/All:</th><td>!&L</td></tr>\n\
<tr><th>/Reused:</th><td>!&L</td><td class=\"targht\">(!UL%)</td></tr>\n\
<tr><th>&nbsp;&nbsp;Autoscript:</th><td>!&L</td></tr>\n\
<tr><th>CLI:</th><td>!&L</td></tr>\n\
<tr><th>Proctor:</th><td>!&L</td></tr>\n\
<tr><th>WebSocket:</th><td>!&L</td></tr>\n\
<tr><th>/Raw:</th><td>!&L</td><td class=\"targht\">(!UL%)</td></tr>\n\
</table>\n\
\
</td><td>\n\
\
<table class=\"rghtlft\">\n\
<tr><th class=\"sbttl\">Processes</th></tr>\n\
<tr><th>Current:</th><td>!&L</td></tr>\n\
<tr><th>$CREPRC:</th><td>!&L</td></tr>\n\
<tr><th>$PERSONA!&?_MACRO\r\r&nbsp;&nbsp;/All:</th><td>!&L</td></tr>\n\
<tr><th>/Default:</th><td>!&L</td></tr>\n\
<tr><th>/Invalid:</th><td>!&L</td></tr>\n\
<tr><th>/Privileged:</th><td>!&L</td></tr>\n\
<tr><th>$FORCEX:</th><td>!&L</td></tr>\n\
<tr><th>$DELPRC:</th><td>!&L</td></tr>\n\
<tr><td colspan=\"2\"><b>As:</b>&nbsp;!AZ</td></tr>\n\
</table>\n\
\
</td><td>\n\
\
<table class=\"rghtlft\">\n\
<tr><th class=\"sbttl\">Memory-Buffer</th></tr>\n\
<tr><th>Current:</th><td>!&L</td></tr>\n\
<tr><th>Total:</th><td>!&L</td></tr>\n\
<tr><th>Failed:</th><td>!&L</td></tr>\n\
<tr><th>Buffer&nbsp;&nbsp;/Current:</th><td>!&L</td>\
<td class=\"targht\">(!&L)</td></tr>\n\
<tr><th>/Min:</th><td>!&L</td><td class=\"targht\">(!&L)</td></tr>\n\
<tr><th>/Max:</th><td>!&L</td><td class=\"targht\">(!&L)</td></tr>\n\
<tr><th>Size&nbsp;&nbsp;/Default:</th><td>!&L</td></tr>\n\
<tr><th>/Min:</th><td>!&L</td></tr>\n\
<tr><th>/Max:</th><td>!&L</td></tr>\n\
<tr><td colspan=\"3\" class=\"targht\" style=\"font-size:85%\">\
<sup>*</sup><i>per-startup only (for this release)</i></td></tr>\n\
</table>\n\
\
</td><td>\n\
\
<table class=\"rghtlft\">\n\
<tr><th class=\"sbttl\">Limits</th></tr>\n\
<tr><th>Soft&nbsp;&nbsp;/Value:</th><td>!&L</td></tr>\n\
<tr><th>/Purged-at:</th><td>!&L</td></tr>\n\
<tr><th>Hard&nbsp;&nbsp;/Value:</th><td>!&L</td></tr>\n\
<tr><th>/Purged-at:</th><td>!&L</td></tr>\n\
<tr><th>&nbsp;&nbsp;Purged&nbsp;&nbsp;/Soft-Limit:</th><td>!&L</td></tr>\n\
<tr><th>/Explicit:</th><td>!&L</td></tr>\n\
<tr><th>Zombie&nbsp;&nbsp;/Lifetime:</th><td colspan=\"2\">!AZ</td></tr>\n\
<tr><th>/Purged-at:</th><td>!&L</td></tr>\n\
<tr><th>CGIplus&nbsp;&nbsp;/Lifetime:</th><td colspan=\"2\">!AZ</td></tr>\n\
<tr><th>/Purged-at:</th><td>!&L</td></tr>\n\
</table>\n\
\
</td></tr>\n\
</table>\n\
\
<p><h3><u>DCL Task List</u></h3>\n\
<p><table class=\"lftlft\">\n\
<tr>\
<th></th>\n\
<th class=\"sbttl\">Script&nbsp;/&nbsp;Client</th>\
<th class=\"sbttl\">PID&nbsp;/&nbsp;Request</th>\
<th class=\"sbttl\">User</th>\
<th class=\"sbttl\">Name</th>\
<th class=\"sbttl\">WebSock</th>\
<th class=\"sbttl\">Type</th>\
<th class=\"sbttl\">Lifetime</th>\
<th class=\"sbttl targht\">Zombie</th>\
<th class=\"sbttl targht\">CGIplus</th>\
<th class=\"sbttl targht\">RTE</th>\
<th class=\"sbttl targht\">Total</th>\
<th class=\"sbttl\">Last</th>\
</tr>\n";

   static char  TaskFao [] =
"<tr><td><b>!&@</b></td>\
!&@\
<td>!8XL</td>\
<td>!AZ</td>\
<td>!AZ</td>\
<td class=\"targht\">!UL</td>\
<td>!AZ</td>\
<td>!AZ</td>\
<td class=\"targht\">!&@</td>\
<td class=\"targht\">!&@</td>\
<td class=\"targht\">!&@</td>\
<td class=\"targht\">!&L</td>\
<td>!20%D</td>\
</tr>\n\
!&@\
!&@";

   static char EmptyTaskListFao [] =
"<tr class=\"hlght\"><th>000</th>\
<td colspan=\"11\"><i>empty</i></td><tr>\n";

   static char  ProctorListFao [] =
"</table>\n\
<p><h3><u>Proctor List</u></h3>\n\
<p><table class=\"lftlft\">\n\
<tr>\
<th></th>\
<th class=\"sbttl\">Min+Idle</th>\
<th class=\"sbttl\">Identification</th>\
<th class=\"sbttl\">Activation</th>\
<th class=\"sbttl\">Notepad</th>\
<th class=\"sbttl\">Min</th>\
<th class=\"sbttl\">Idle</th>\
<th class=\"sbttl\">Last</th>\
<th class=\"sbttl\">Fail</th>\
<th class=\"sbttl\">Last</th>\
</tr>\n";

   static char  ProctorItemFao [] =
"!&@<tr!AZ!AZ><td>!3ZL</td>\
<td>!UL+!UL</td>\
<td>!AZ!AZ!AZ!AZ</td>\
<td>!AZ</td>\
<td>!AZ</td>\
<td>!UL</td>\
<td>!UL</td>\
<td>!20%D</td>\
<td>!UL</td>\
<td>!20%D</td>\
!&@\
</tr>\n";

   static char EmptyProctorListFao [] =
"<tr class=\"hlght\"><th>000</th><td colspan=\"10\"><i>empty</i></td><tr>\n";

   static char ProctorFailFao [] =
"<tr class=\"hlght\"><th>Problem:</th><td colspan=\"10\">!AZ</td><tr>\n";

   static char  ScriptNameCacheFao [] =
"</table>\n\
<p><h3><u>Script Name Cache</u></h3>\n\
<p><table class=\"lftlft\">\n\
<tr>\
<th></th>\
<th class=\"sbttl\">Mapped&nbsp;File</th>\
<th class=\"sbttl\">File&nbsp;Name</th>\
<th class=\"sbttl\">Hits</th>\
<th class=\"sbttl\">Last</th>\
</tr>\n";

   static char  NameCacheFao [] =
"<tr!AZ><th>!3ZL</th>\
<td><tt>!AZ</tt></td>\
<td><tt>!AZ</tt></td>\
<td class=\"targht\">!&L</td>\
<td>!20%D</td>\
</tr>\n";

   static char EmptyScriptNameCacheFao [] =
"<tr class=\"hlght\"><th>000</th><td colspan=\"4\"><i>empty</i></td><tr>\n";

   static char  PersonaCacheFao [] =
"</table>\n\
<p><h3><u>Persona Cache</u></h3>\n\
<p><table class=\"lftlft\">\n\
<tr>\
<th></th>\
<th class=\"sbttl\">User</u></th>\
<th class=\"sbttl targht\">Hits</th>\
<th class=\"sbttl\">Last</th>\
<th class=\"sbttl targht\">Reuse</th>\n\
</tr>\n";

   static char  PersonaEntryFao [] =
"<tr!AZ><th>!3ZL</th>\
<td>!AZ</td>\
<td class=\"targht\">!&L</td>\
<td>!20%D</td>\
<td class=\"targht\">!&L</td>\n\
</tr>\n";

   static char EmptyPersonaCacheFao [] =
"<tr class=\"hlght\"><th>000</th><td colspan=\"4\"><i>empty</i></td><tr>\n";

   static char  ButtonsFao [] =
"</table>\n\
<p><table class=\"lftlft\">\n\
<tr><td>\n\
<form method=\"GET\" action=\"!AZ\">\n\
<input type=\"submit\" value=\" Purge Idle \">\n\
</form>\n\
</td><td>\n\
<form method=\"GET\" action=\"!AZ\">\n\
<input type=\"submit\" value=\" Force Delete \">\n\
</form>\n\
</td></tr>\n\
</table>\n\
!AZ\
</div>\n\
</body>\n\
</html>\n";

   int  idx, status,
        Count;
   unsigned long  FaoVector [64];
   unsigned long  *vecptr;
   char  *cptr;
   DCL_SCRIPT_NAME_ENTRY  *captr;
   DCL_TASK  *tkptr;
   LIST_ENTRY  *leptr;
   PERSONA_ENTRY  *pcptr;
   struct ConfigProctorStruct  *prptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclScriptingReport()");

   if (rqptr->rqHeader.QueryStringLength &&
       strsame(rqptr->rqHeader.QueryStringPtr, "at=", 3))
   {
      DclPeekReport (rqptr);
      AdminEnd (rqptr);
      return;
   }

   if (DclScriptDetachProcess)
      AdminPageTitle (rqptr, "Detached Process CGI/DCL Scripting");
   else
      AdminPageTitle (rqptr, "Subprocess CGI/DCL Scripting");

   vecptr = FaoVector;

   InstanceMutexLock (INSTANCE_MUTEX_HTTPD);

   /* statistics */
   *vecptr++ = AccountingPtr->DoScriptCount;
   *vecptr++ = AccountingPtr->DoCgiPlusScriptCount;
   *vecptr++ = AccountingPtr->DclCgiPlusReusedCount;
   *vecptr++ = PercentOf32(AccountingPtr->DclCgiPlusReusedCount,
                         AccountingPtr->DoCgiPlusScriptCount);
   *vecptr++ = AccountingPtr->DoRteScriptCount;
   *vecptr++ = AccountingPtr->DclRteReusedCount;
   *vecptr++ = PercentOf32(AccountingPtr->DclRteReusedCount,
                         AccountingPtr->DoRteScriptCount);
   *vecptr++ = AccountingPtr->DoAutoScriptCount;
   *vecptr++ = AccountingPtr->DoDclCommandCount;
   *vecptr++ = AccountingPtr->DclProctorCount;
   *vecptr++ = AccountingPtr->DclWebSocketCount;
   *vecptr++ = AccountingPtr->DclWebSocketRawCount;
   *vecptr++ = PercentOf32(AccountingPtr->DclWebSocketRawCount,
                         AccountingPtr->DclWebSocketCount);

   /* processes */
   *vecptr++ = DclCurrentScriptProcess;
   *vecptr++ = AccountingPtr->DclCrePrcCount;
   *vecptr++ = PersonaMacro;
   *vecptr++ = AccountingPtr->DclCrePrcPersonaCount;
   *vecptr++ = AccountingPtr->DclCrePrcPersonaDefaultCount;
   *vecptr++ = AccountingPtr->DclCrePrcPersonaInvUserCount;
   *vecptr++ = AccountingPtr->DclCrePrcPersonaPrvUserCount;
   *vecptr++ = AccountingPtr->DclForceXCount;
   *vecptr++ = AccountingPtr->DclDelPrcCount;
   if (HttpdScriptAsUserName[0])
      *vecptr++ = HttpdScriptAsUserName;
   else
      *vecptr++ = HttpdProcess.UserName;

   /* memory buffer */
   *vecptr++ = DclMemBufGblSectionCount;
   *vecptr++ = DclMemBufCount64;
   *vecptr++ = DclMemBufFailCount;
   *vecptr++ = (DclMemBufGblPageCount * 512) / 1048576;
   *vecptr++ = DclMemBufGblPageCount;
   *vecptr++ = (DclMemBufGblPageCountMin * 512) / 1048576;
   *vecptr++ = DclMemBufGblPageCountMin;
   *vecptr++ = (DclMemBufGblPageCountMax * 512) / 1048576;
   *vecptr++ = DclMemBufGblPageCountMax;
   *vecptr++ = DclMemBufSizeDefault;
   *vecptr++ = DclMemBufSizeMin;
   *vecptr++ = DclMemBufSizeMax;

   /* limits */
   *vecptr++ = DclScriptProcessSoftLimit;
   *vecptr++ = DclSoftLimitPurgeCount;
   *vecptr++ = DclScriptProcessHardLimit;
   *vecptr++ = DclHitHardLimitCount;
   *vecptr++ = DclPurgeCount;
   *vecptr++ = DclPurgeScriptProcessesCount;
   if (DclUseZombies && Config.cfScript.ZombieLifeTime)
      *vecptr++ = MetaConShowSeconds (rqptr, Config.cfScript.ZombieLifeTime);
   else
      *vecptr++ = "[disabled]";
   *vecptr++ = DclZombieLifeTimePurgeCount;
   if (Config.cfScript.CgiPlusLifeTime)
      *vecptr++ = MetaConShowSeconds (rqptr, Config.cfScript.CgiPlusLifeTime);
   else
      *vecptr++ = "<i>none</i>";
   *vecptr++ = DclCgiPlusLifeTimePurgeCount;

   InstanceMutexUnLock (INSTANCE_MUTEX_HTTPD);

   status = FaolToNet (rqptr, PageBeginFao, &FaoVector);
   if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);

   /*********************/
   /* task list entries */
   /*********************/

   Count = 0;
   for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      tkptr = (DCL_TASK*)leptr;

      vecptr = FaoVector;

      if (tkptr->ScriptProcessPid)
      {
         *vecptr++ = "<a href=\"!AZ?pid=!8XL&puser=!AZ\">!3ZL</a>";
         *vecptr++ = ADMIN_REPORT_SHOW_PROCESS;
         *vecptr++ = tkptr->ScriptProcessPid;
         *vecptr++ = tkptr->CrePrcUserName;
         *vecptr++ = ++Count;
      }
      else
      {
         *vecptr++ = "!3ZL"; 
         *vecptr++ = ++Count;
      }

      if (tkptr->TaskType == DCL_TASK_TYPE_CLI)
      {
         for (cptr = tkptr->DclCommandPtr; *cptr && *cptr != '\n'; cptr++);
         if (*cptr || cptr - tkptr->DclCommandPtr > 24)
            *vecptr++ = "<td class=\"hlght\"></td>";
         else
         {
            *vecptr++ = "<td class=\"talft\" hlght><tt>!AZ</tt></td>";
            *vecptr++ = tkptr->DclCommandPtr;
         }
      }
      else
      {
         if (tkptr->ScriptRunTime[0])
         {
            *vecptr++ = "<td class=\"talft\">(!AZ)!&;AZ</td>";
            *vecptr++ = tkptr->ScriptRunTime;
         }
         else
            *vecptr++ = "<td class=\"talft\">!&;AZ</td>";
         *vecptr++ = tkptr->ScriptName;
      }

      *vecptr++ = tkptr->ScriptProcessPid;
      if (tkptr->CrePrcUserName[0])
         *vecptr++ = tkptr->CrePrcUserName;
      else
         *vecptr++ = "<i>none</i>";
      *vecptr++ = DclGetPrcNam (tkptr->ScriptProcessPid);

      *vecptr++ = WebSockCount (tkptr->ScriptProcessPid);

      if (tkptr->ProctorPtr)
         *vecptr++ = "proctor";
      else
      {
         switch (tkptr->TaskType)
         {
            case DCL_TASK_TYPE_CGI_SCRIPT :
                 *vecptr++ = "CGI"; break;
            case DCL_TASK_TYPE_CGIPLUS_SCRIPT :
                *vecptr++ = "CGIplus"; break;
            case DCL_TASK_TYPE_RTE_SCRIPT :
                 *vecptr++ = "RTE"; break;
            case DCL_TASK_TYPE_CLI :
                 *vecptr++ = "CLI"; break;
            default :
                 *vecptr++ = "?";
         }
      }

      *vecptr++ = MetaConShowSeconds (rqptr,
                                      tkptr->LifeTimeSecond < 0 ?
                                      tkptr->LifeTimeSecond :
                                      tkptr->LifeTimeSecond - HttpdTickSecond);

      if (tkptr->ZombieCount)
      {
         *vecptr++ = "!&L";
         *vecptr++ = tkptr->ZombieCount;
      }
      else
         *vecptr++ = "";

      if (tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT)
      {
         *vecptr++ = "!&L";
         *vecptr++ = tkptr->CgiPlusUsageCount;
      }
      else
         *vecptr++ = "";

      if (tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT)
      {
         *vecptr++ = "!&L";
         *vecptr++ = tkptr->CgiPlusUsageCount;
      }
      else
         *vecptr++ = "";

      *vecptr++ = tkptr->TotalUsageCount;
      *vecptr++ = &tkptr->LastUsedTime64;

      if (tkptr->TaskType == DCL_TASK_TYPE_CLI)
      {
         for (cptr = tkptr->DclCommandPtr; *cptr && *cptr != '\n'; cptr++);
         if (*cptr || cptr - tkptr->DclCommandPtr > 24)
         {
            *vecptr++ = "<tr><td></td>\
<td class=\"talft hlght\" colspan=\"12\">\
<pre style=\"white-space:pre-wrap;\">!&;AZ</pre></td></tr>\n";
            *vecptr++ = tkptr->DclCommandPtr;
         }
         else
            *vecptr++ = "";
      }
      else
         *vecptr++ = "";

      if (tkptr->RequestPtr)
      {
         *vecptr++ =
"<tr class=\"hlght\"><td></td>\
<td class=\"talft\">!&@!AZ</td>\
<td class=\"talft\" colspan=\"11\"><tt>!&;AZ</tt></td>\
</tr>\n";

         if (tkptr->RequestPtr->RemoteUser[0])
         {
            *vecptr++ = "!&;AZ@";
            *vecptr++ = tkptr->RequestPtr->RemoteUser;
         }
         else
            *vecptr++ = "";
         *vecptr++ = tkptr->RequestPtr->ClientPtr->Lookup.HostName;
         *vecptr++ = tkptr->RequestPtr->rqHeader.RequestUriPtr;
      }
      else
      if (tkptr->ScriptProcessPid)
         *vecptr++ =
"<tr class=\"hlght\"><td></td><td colspan=\"12\"><i>idle</i></td></tr>";
      else
         *vecptr++ =
"<tr class=\"hlght\"><td></td><td colspan=\"12\"><i>none</i></td></tr>";

      status = FaolToNet (rqptr, TaskFao, &FaoVector);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }
   if (!Count)
   {
      status = FaolToNet (rqptr, EmptyTaskListFao, NULL);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }

   /****************/
   /* proctor list */
   /****************/

   status = FaolToNet (rqptr, ProctorListFao, NULL);
   if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);

   Count = 0;
   for (idx = 0; idx < Config.cfScript.ProctorCount; idx++)
   {
      prptr = &Config.cfScript.Proctor[idx];
      if (prptr->Problem) continue;
      Count++;

      vecptr = FaoVector;
      if (prptr->FailWeight)
      {
         *vecptr++ = "<!!-- !UL -->";
         *vecptr++ = prptr->FailWeight;
      }
      else
         *vecptr++ = "";
      if (Count % 2)
         *vecptr++ = "";
      else
         *vecptr++ = " class=\"hlght\"";
      if (prptr->LastFailTime64) 
         *vecptr++ = " class=\"struck\"";
      else
         *vecptr++ = "";
      *vecptr++ = Count;
      *vecptr++ = prptr->NumberMin;
      *vecptr++ = prptr->NumberIdle;
      *vecptr++ = *prptr->RunTimePtr ? "(" : "";
      *vecptr++ = *prptr->RunTimePtr ? prptr->RunTimePtr : "";
      *vecptr++ = *prptr->RunTimePtr ? ")" : "";
      *vecptr++ = *prptr->ScriptPtr ? prptr->ScriptPtr : "";
      *vecptr++ = *prptr->ActivatePtr ? prptr->ActivatePtr : "";
      *vecptr++ = *prptr->NotePadPtr ? prptr->NotePadPtr : "";
      *vecptr++ = prptr->TotalMin;
      *vecptr++ = prptr->TotalIdle;
      *vecptr++ = &prptr->LastTime64;
      *vecptr++ = prptr->TotalFail;
      *vecptr++ = &prptr->LastFailTime64;
      *vecptr++ = prptr->FailReason[0] ? "<td>&nbsp;&nbsp;!AZ</td>" : "";
      *vecptr++ = prptr->FailReason;

      status = FaolToNet (rqptr, ProctorItemFao, &FaoVector);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }
   if (!Count)
   {
      status = FaoToNet (rqptr, EmptyProctorListFao, NULL);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }

   /*****************************/
   /* script name cache entries */
   /*****************************/

   status = FaolToNet (rqptr, ScriptNameCacheFao, NULL);
   if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);

   Count = 0;
   for (leptr = DclScriptNameCacheList.HeadPtr;
        leptr;
        leptr = leptr->NextPtr)
   {
      captr = (DCL_SCRIPT_NAME_ENTRY*)leptr;
      if (!captr->ResFileName[0]) continue;
      Count++;

      vecptr = FaoVector;
      if (Count % 2)
         *vecptr++ = "";
      else
         *vecptr++ = " class=\"hlght\"";
      *vecptr++ = Count;
      *vecptr++ = captr->ScriptFileName;
      *vecptr++ = captr->ResFileName;
      *vecptr++ = captr->HitCount;
      *vecptr++ = &captr->LastTime64;

      status = FaolToNet (rqptr, NameCacheFao, &FaoVector);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }
   if (!Count)
   {
      status = FaolToNet (rqptr, EmptyScriptNameCacheFao, NULL);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }

   /*************************/
   /* persona cache entries */
   /*************************/

   status = FaoToNet (rqptr, PersonaCacheFao, PersonaCacheEntries);
   if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);

   Count = 0;
   for (leptr = PersonaCacheList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      pcptr = (PERSONA_ENTRY*)leptr;
      Count++;

      vecptr = FaoVector;
      if (Count % 2)
         *vecptr++ = "";
      else
         *vecptr++ = " class=\"hlght\"";
      *vecptr++ = Count;
      *vecptr++ = pcptr->UserName;
      *vecptr++ = pcptr->HitCount;
      *vecptr++ = &pcptr->LastTime64;
      *vecptr++ = pcptr->ReuseCount;

      status = FaolToNet (rqptr, PersonaEntryFao, &FaoVector);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }
   if (!Count)
   {
      status = FaolToNet (rqptr, EmptyPersonaCacheFao, NULL);
      if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);
   }

   vecptr = FaoVector;
   *vecptr++ = ADMIN_CONTROL_DCL_PURGE;
   *vecptr++ = ADMIN_CONTROL_DCL_DELETE;
   *vecptr++ = AdminRefresh();

   status = FaolToNet (rqptr, ButtonsFao, &FaoVector);
   if (VMSnok (status)) ErrorNoticed (rqptr, status, NULL, FI_LI);

   rqptr->rqResponse.PreExpired = PRE_EXPIRE_ADMIN;
   ResponseHeader200 (rqptr, "text/html", &rqptr->NetWriteBufferDsc);

   AdminEnd (rqptr);
}

/*****************************************************************************/
/*
Ad hoc report down in the weeds of DCL structures.  Development/troubleshooting
only.  Add query string "at=*" to the regular scripting report URI to list all
script entries.  Add a "at=<integer>" to peek at a particular entry.
*/

void DclPeekReport (REQUEST_STRUCT *rqptr)

{
   int  cnt;
   char  *cptr;
   LIST_ENTRY  *leptr;
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclPeekReport()");

   for (cptr = rqptr->rqHeader.QueryStringPtr;
        *cptr && !isdigit(*cptr);
        cptr++);
   cnt = atoi(cptr);

   ResponseHeader200 (rqptr, "text/plain", NULL);
   FaoToNet (rqptr, "DCL Structure Report\n\n", NULL);
   NetWriteFullFlush (rqptr, NULL);
   for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      if (*cptr && --cnt > 0) continue;
      tkptr = (DCL_TASK*)leptr;
      WatchPeekDcl (rqptr, tkptr);
      if (*cptr) break;
   }
}

/*****************************************************************************/
/*
*/

char* DclGetPrcNam (ulong Pid)

{
   static char  JpiPrcNam [16];
   static struct
   {
      unsigned short  buf_len;
      unsigned short  item;
      unsigned char   *buf_addr;
      unsigned long   *short_ret_len;
   }
   JpiItems [] =
   {
      { sizeof(JpiPrcNam), JPI$_PRCNAM, &JpiPrcNam, 0 },
      { 0,0,0,0 }
   };

   int  status;
   char  *cptr;
   IO_SB  IOsb;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclGetPrcNam() !8XL", Pid);

   if (!Pid) return ("<i>none</i>");

   sys$setprv (1, &WorldMask, 0, 0);
   status = sys$getjpiw (EfnWait, &Pid, 0,  &JpiItems, &IOsb, 0, 0);
   sys$setprv (0, &WorldMask, 0, 0);
   if (VMSok (status)) status = IOsb.Status;
   if (VMSok (status))
   {
      JpiPrcNam[15] = '\0';
      for (cptr = JpiPrcNam; *cptr && *cptr != ' '; cptr++);
      *cptr = '\0';
   }
   else
      sprintf (JpiPrcNam, "%%X%08.08X", status);

   return (JpiPrcNam);
}

/*****************************************************************************/
/*
Purge the DCL process task list, either allowing request processing completion
(if applicable) or immediately ('with extreme prejudice').  The 'UserName'
parameter, if supplied' slects only those scripting as that account. 
'ScriptName' is a wildcard pattern (if necessary) that selects only those tasks
having a script path that matches.  'ScriptFileName' is the same except matches
on the VMS file specification of the script.
*/

char* DclControlPurgeScriptProcesses
(
BOOL WithExtremePrejudice,
char *UserName,
char *ScriptName,
char *ScriptFileName
)
{
   static char  Response [64];
   static $DESCRIPTOR (ResponseFaoDsc, "!UL deleted, !UL marked for delete");
   static $DESCRIPTOR (ResponseDsc, Response);

   int  idx, status,
        DeletedCount,
        MarkedCount;
   unsigned short  Length;
   LIST_ENTRY  *leptr;
   DCL_TASK  *tkptr;

   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL,
                 "DclControlPurgeScriptProcesses() !&B !&Z !&Z !&Z",
                 WithExtremePrejudice, UserName, ScriptName, ScriptFileName);

   /* purge any proctored script failures */
   for (idx = 0; idx < Config.cfScript.ProctorCount; idx++)
      Config.cfScript.Proctor[idx].FailWeight = 0;

   PersonaCache (NULL, 0);

   DclPurgeScriptNameCache ();

   DclPurgeScriptProcessesCount++;

   DeletedCount = MarkedCount = 0;

   for (leptr = DclTaskList.HeadPtr; leptr; leptr = leptr->NextPtr)
   {
      tkptr = (DCL_TASK*)leptr;

      if (!tkptr->ScriptProcessPid) continue;

      /* if only purging scripts running as a specific VMS user */
      if (UserName && UserName[0])
         if (!strsame (tkptr->CrePrcUserName, UserName, -1))
            continue;

      /* if only purging matching scripts */
      if (ScriptName && ScriptName[0])
         if (!StringMatch (NULL, tkptr->ScriptName, ScriptName))
            continue;

      /* if only purging matching script file names */
      if (ScriptFileName && ScriptFileName[0])
         if (!StringMatch (NULL, tkptr->ScriptFileName, ScriptFileName))
            continue;

      if (WithExtremePrejudice ||
          (tkptr->QueuedSysCommand <= tkptr->QueuedSysCommandAllowed &&
           !tkptr->QueuedSysOutput &&
           !tkptr->QueuedClientOutput &&
           !tkptr->QueuedCgiPlusIn &&
           !tkptr->QueuedHttpInput &&
           !tkptr->QueuedClientRead &&
           !tkptr->FindScript &&
           !tkptr->RequestPtr) &&
           !((tkptr->TaskType == DCL_TASK_TYPE_CGIPLUS_SCRIPT ||
              tkptr->TaskType == DCL_TASK_TYPE_RTE_SCRIPT) &&
             WebSockCount(tkptr->ScriptProcessPid)))
      {
         /* forced delete or script process not currently active, abort task */
         tkptr->DeleteProcess = true;
         /* don't bother running down any image if it's a delete */
         if (WithExtremePrejudice) tkptr->ForceImageExit = false;
         DclTaskRunDown (tkptr);
         DeletedCount++;
      }
      else
      {
         /* script process is currently active, just leave marked for delete */
         tkptr->DeleteProcess = true;
         MarkedCount++;
      }
   }

   sys$fao (&ResponseFaoDsc, &Length, &ResponseDsc,
            DeletedCount, MarkedCount);
   Response[Length] = '\0';

   DclScriptProctor (); 

   return (Response);
}

/*****************************************************************************/
/*
A mapping rule reload is a particularly "dangerous" time for scripting as
confusion could ensure about which CGIplus script is which and which script
name in the cache is which.  Hence at a mapping rule reload purge DCL process
tasks and the script name cache.
*/

void DclLoadedMappingRules ()

{
   /*********/
   /* begin */
   /*********/

   if (WATCH_MODULE(WATCH_MOD_DCL))
      WatchThis (WATCHALL, WATCH_MOD_DCL, "DclLoadedMappingRules()");

   DclPurgeScriptNameCache ();

   DclControlPurgeScriptProcesses (false, NULL, NULL, NULL);
}

/*****************************************************************************/