[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]
/*****************************************************************************/
#ifdef COMMENTS_WITH_COMMENTS
/*
                               qdLogStats.c

Quick & Dirty LOG STATisticS.

Utility to extract very elementary statistics from Web server common/combined
format log files.  A number of filters allow subsets of the log contents to be
selected.

If a filter pattern does not begin with the '^' character then it is considered
to be a wildcard pattern.  If the pattern begins with the '^' character then it
is considered to be regular expression.  A filter pattern result can be negated
by the use of a leading '!' character.  If the negation is used then the target
string cannot be empty.  If it's empty it always treated as no match (and
filtered out). 


WILDCARD EXPRESSIONS
--------------------
A wildcard expression uses the '*' to match any zero or more characters, the
'%' to match any one character, the '?' to match any zero or one character. 
The '*', '%' and '?' are translated into an appropriate regular expression,
with the start and end of the string anchored.  This should act much the same
as previous versions of QDLOGSTATS.  If you want to do anything more complex
than simple wildcard matching you will need to use a regular expression.

The following expression would match all requests with a path that was rooted
at "/wasd_root/".

  /wasd_root/*

This expression matches all paths that accessed the Alpha object files in the
WASD source (and build) tree.

  /wasd_root/*/obj_axp/*


REGULAR EXPRESSIONS
-------------------
Are provided using the GNU extended regular expression matching and search
library, version 0.12 (from RX1.5 kit).  Copyright (C) 1993 Free Software
Foundation, Inc.  Although a full explanation of regular expression matching is
well beyond the scope of this source code description here's a quick mnemonic.

  \         Quote the next metacharacter
  ^         Match the beginning of the line
  .         Match any character (except newline)
  $         Match the end of the line
  |         Alternation (or)
  [abc]     Match only a, b or c
  [^abc]    Match anything except a, b and c
  [a-z0-9]  Match any character in the range a to z or 0 to 9
 
  *         Match 0 or more times
  +         Match 1 or more times
  ?         Match 1 or 0 times
  {n}       Match exactly n times
  {n,}      Match at least n times
  {n,m}     Match at least n but not more than m times
 
  Match-self Operator                 Ordinary characters.
  Match-any-character Operator        .
  Concatenation Operator              Juxtaposition.
  Repetition Operators                *  +  ? {}
  Alternation Operator                |
  List Operators                      [...]  [^...]
  Grouping Operators                  (...)
  Back-reference Operator             \digit
  Anchoring Operators                 ^  $

More detailed explanations abound.  Keep in mind that this program uses the
library in case-insensitive, extended Posix mode (basically EGREP look-alike).

The following expression would match all requests with a path that was rooted
at "/wasd_root/".

  ^^/wasd_root/.*

This expression matches all paths that accessed the Alpha object files in the
WASD source (and build) tree.

  ^^/wasd_root/.*/obj_axp/.*

Note the leading '^' which directs the program that this is a regular
expression.


OTHER CONSIDERATIONS
--------------------
Matching log file records can be viewed as processed using the
/VIEW=[type] qualifier, where <type> is ALL, MATCH (default) or NOMATCH.

For fields that are commonly URL-encoded (or for any field that can usefully be
URL-encoded to disguise the actual path) the /DECODE qualifier specifies that
the field should be URL-decoded before filter matching.  If the /DECODE
qualifier is used without keywords all three of these fields are decoded,
otherwise any combination of PATH, QUERY and REFERER may be used to selectively
decode that field.  For example /DECODE=(PATH,QUERY).  Remember that decoding
uses CPU cycles and adds processing time.

A progress indicator can be displayed using the /PROGRESS qualifier.  With this
a "+" is output for each file processed and a "." for each 1000 records in any
file.  An optional integer can be provides as /PROGRESS=integer to change this
record value.

Note that all selections are based on string matching.  Files and/or records
cannot be selected on the basis of being before or after a particular date for
instance.  Also that records are accepted or rejected in the order in which the
results are displayed, that is if a record is rejected against method it will
never be assessed against user-agent ... UNLESS then /ALL qualifier is applied. 
When /ALL is used comparison continues against all filter strings even if one
or more do not match.  This is useful for displaying the totals that match each
of multiple filter critera (not much use against a single one).

If /LOOKUP[=<integer>] is enabled then literal client host addresses have their
names resolved (if possible).  This name is displayed when log line is output. 
When enabled the resolved name is also used when matching against client hosts.

Although part of the WASD package there is no reason why this shouldn't be of
use with other packages if desired.


EXAMPLES
--------
Requires a foreign verb or such (shorter version might save keystrokes :^)

  $ QDLOG == "$CGI-BIN:[000000]QDLOGSTATS"
  $ QDLOGSTATS == "$CGI-BIN:[000000]QDLOGSTATS"

1)  Records from September 1999.

    $ QDLOGSTATS WASD_LOGS:*1999*.LOG /DATE="*/SEP/1999*"

2)  Records where the browser was an X-based Netscape Navigator

    $ QDLOGSTATS WASD_LOGS:*.LOG /USERAGENT=*MOZILLA*X11*

3)  Records of POST method requests

    $ QDLOGSTATS WASD_LOGS:*.LOG /METHOD=POST

4)  Records requesting a particular path

    $ QDLOGSTATS WASD_LOGS:*.LOG /PATH="/cgi-bin/*"

5)  Records with a query string 

    $ QDLOGSTATS WASD_LOGS:*.LOG /QUERY="%*"
    $ QDLOGSTATS WASD_LOGS:*.LOG /QUERY="^^.+$"

6) Records without a query string (or without a specific query string)

    $ QDLOGSTATS WASD_LOGS:*.LOG /QUERY="^^$"
    $ QDLOGSTATS WASD_LOGS:*.LOG /QUERY="!*grotty*"
    $ QDLOGSTATS WASD_LOGS:*.LOG /QUERY="!^grotty"

7)  Records requesting a particular path

    $ QDLOGSTATS WASD_LOGS:*.LOG /PATH="/cgi-bin/*"

8)  Select proxy records requesting (a) particular site(s)

    $ QDLOGSTATS WASD_LOGS:*8080*.LOG /PATH="http://*.compaq.com*"
    $ QDLOGSTATS WASD_LOGS:*8080*.LOG /METHOD=POST /PATH="^http://.*sex.*/.*"

9)  Records where the request was authenticated

    $ QDLOGSTATS WASD_LOGS:*.LOG /AUTHUSER="%*"
    $ QDLOGSTATS WASD_LOGS:*.LOG /AUTHUSER="^.+"
    $ QDLOGSTATS WASD_LOGS:*.LOG /AUTHUSER="DANIEL"

10) Records where the request was authenticated, excluding DANIEL

    $ QDLOGSTATS WASD_LOGS:*.LOG /AUTHUSER="!DANIEL"

11) Records with requests originating from (a) particular host(s)

    $ QDLOGSTATS WASD_LOGS:*.LOG /CLIENT=131.185.250.1
    $ QDLOGSTATS WASD_LOGS:*.LOG /LOOKUP /CLIENT="*.vsm.com.au"

12) All requests between 26th September 2006 10:30 and midnight that same day

    $ QDLOGSTATS WASD_LOGS:*.LOG /DTSINCE=26-SEP-2006:10:30 -
                                 /DTBEFORE=26-SEP-2006:23:59

13) All requests during the previous day

    $ QDLOGSTATS WASD_LOGS:*.LOG /DTSINCE=YESTERDAY /DTBEFORE=TODAY


CGI INTERFACE
-------------
A CGI interface is available.  It basically parallels the CLI behaviour
described above. 

  http://the.host.name/cgi-bin/qdlogstats

So that it's not available for uncontrolled use the script *must* be subject to
authorization (i.e. have a non-empty REMOTE_USER).  For the WASD package this
may be enabled using the following HTTPD$AUTH rule.

  [whatever-realm]
  /cgi-bin/qdlogstats r+w,~siteadmin

For VMS Apache (CSWS) using SYSUAF authentication this might be configured
using the following entries in [CONF]HTTPD.CONF

  LoadModule auth_openvms_module
  /apache$common/modules/mod_auth_openvms.exe_alpha

  <Location /cgi-bin/qdlogstats>
  AuthType Basic
  AuthName "OpenVMS authentication"
  AuthUserOpenVMS On
  require valid-user
  </Location>

If there seems to be no relevant CGI variables the script displays a request
form that allows the entering of strings against the various fields of the log
file entries.  This form uses the GET method (putting form elements into the
query string) and so searches commonly or periodically made can be saved as
bookmarks if desired.

The account processing the script must have access to the log directory and
files.  This may be provided by the server account itself (i.e. the logs are
normally accessable) or the scripting account itself has access.  For instance,
with WASD on VMS V6.2 or later this could be provided using the /PERSONA
functionality and a HTTPD$MAP rule such as

  set /cgi-bin/qdlogstats script=as=SYSTEM

An alternative is to install the script executable with sufficient privileges
to access the files.  Normally this would only be SYSPRV but as the script
attempts to enable READALL as well so it *could* be installed with that if
necessary.  The following example DCL executed during server startup would
ensure such access.

  $ INSTALL ADD /PRIVILEGE=READALL CGI-BIN:[000000]QDLOGSTATS.EXE

For WASD 8.1 and later access control should not need to be changed.  For
non-WASD and WASD earlier than 8.1 the following should be applied.  If this is
provided it would also be prudent to control access to the executable from
arbitrary accounts at the CLI, and restricting it to the scripting account
using an ACL.  For example

  $ SET SECURITY CGI-BIN:[000000]QDLOGSTATS.EXE -
        /ACL=((IDENT=HTTP$SERVER,ACCESS=R+E),(IDENT=*,ACCESS=NONE)

The CGI version REQUIRES the following system-level logical name to locate the
log files for it.  If this name does not exist the CGI interface will not work. 
All log files must be available via this logical.  The logical name is defined
/SYSTEM to limit a possibly READALL privilege being used against arbitrary
paths.

  $ DEFINE /SYSTEM QDLOGSTATS_LOGS "WASD_LOGS:"


GEOLOCATION
-----------
QdLogStats provides optional geolocation data, included between curly braces,
following the client address/name.  This is JavaScript enabled and performed by
the client browser and so is only accessible with CGI usage.  It also adds some
latency to each lookup.

The logical name QDLOGSTATS_GEOLOCATE provides a local URI or fully specified
URL for a JavaScript resource (file) to perform the geolocation processing. 
This URI/URL is loaded into the browser when QdLogStats is activated.

The file QDLOGSTATS_GEOLOCATION_GEOIPDB.JS provides a free service not
requiring registration as well as a template for provding other services.
Example basic geolocation is enabled using:

   $ DEFINE /SYSTEM QDLOGSTATS_GEOLOCATE -
            "/wasd_root/src/utils/qdlogstats_geolocate_geoipdb.js"


QUALIFIERS
----------
/ALL                  compare all records to all filters
/AUTHUSER=            pattern (any authenticated username)
/BEFORE=              files (not records!) modified before VMS time
/CLIENT=              pattern (client host name or IP address)
/DATETIME=            pattern ("11/Jun/1999:14:08:49 +0930")
/DBUG                 turns on all "if (Debug)" statements
/DECODE[=keyword]     URL-decode PATH, QUERY and/or REFERER before filtering
/DTBEFORE=            before date/time (VMS format) for filtering records
/DTSINCE=             since date/time (VMS format) for filtering records
/IP=<integer>         4 or 6 to select either IPv4 or IPv6 records
/LOG                  show the name of the log file the records come from
/LOOKUP[=<integer>]   lookup host name from literal address
/METHOD=              HTTP method ("GET", "POST", "HEAD", "(WebDAV)", etc.)
/NOWASD               remove likes of "POST /WASD::HTTPd:80-BEGIN-00000001"
/OUTPUT=              file specification
/PATH=                pattern (URL path component only)
/PROGRESS[=integer]   show progress during processing
/PROTOCOL=            HTTP protocol ("HTTP/2" or "HTTP/1.1", etc.) as a string
/QUERY=               pattern (URL query component only)
/REFERER=             pattern (HTTP "Referer:" field, COMBINED only)
/REMOTEID=            pattern (anything in the RFC819 remote ident field)
/RESOLVE              displays (name) if address and (address) if name
/RESPONSE=            HTTP response status code pattern
/SINCE=               files (not records!) modified since VMS time
/SIZE=([MIN=|MAX=])   minimum and/or maximum response size  
/SOFTWAREID           (and /VERSION) display QDLOGSTATS and CGILIB versions
/USERAGENT=           pattern (HTTP "User-Agent:", COMBINED only)
/VIEW[=type]          display matching records, where <type> can be
                      ALL, MATCH (default) or NOMATCH


BUILD DETAILS
-------------
See BUILD_QDLOGSTATS.COM procedure.


COPYRIGHT
---------
Copyright (C) 2000-2021 Mark G.Daniel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright (C) 1993 Free Software Foundation, Inc.
Extended regular expression matching and search library, version 0.12.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.


VERSION HISTORY (update SOFTWAREVN as well!)
---------------
09-MAY-2021  MGD  v2.0.0, TcpIpLookup() refactor IP name/address resolution
                            using getnameinfo() and getaddrinfo()
                          FORM_RESOLVE and /RESOLVE
                            displays (name) if address and (address) if name
                          cosmetic refinements (perhaps just modifications)
18-MAY-2020  MGD  v1.17.2, bugfix; protocol filter
18-JAN-2019  MGD  v1.17.1, CgiForm() add HTTP status 418 to selector list
27-NOV-2018  MGD  v1.17.0, refactor geolocation (see above for requirements)
                           as well as general refactor and maintenance
09-NOV-2016  MGD  v1.16.0, view (only) the first record for each client
                             (allows close-enough assessment of unique access)
                           JavaScript driven geolocation (with CGI interface)
                             using the freegeoip.net or ip-api.com services
                           HT_LOGS to WASD_LOGS (per WASD v10 and later :-)
06-SEP-2016  MGD  v1.15.1, update to include HTTP/2 (of course this comes via
                           the WASD 'RQ' logging directive, not standard)
04-JAN-2014  MGD  v1.15.0, "interesting" response status codes option
                           MATCHn() macros for improved efficiency
                           text [pre-]wrap (more for printing)
                           method and status percentages (of matched requests)
                           bugfix; POST and PROP.. results transposition
10-AUG-2013  MGD  v1.14.0, StatTimer() statistics
17-NOV-2011  MGD  v1.13.3, 1nn response filter option
12-JUN-2010  MGD  v1.13.2, bugfix; TcpIpLookupHostName() unresolved cache
                           entry indicated by IP address with leading '?'
10-MAY-2010  MGD  v1.13.1, NoWasdEntries test for "POST /*::WASD%:*-*-*"
01-NOV-2009  MGD  v1.13.0, WebDAV methods
                           view suspect records
                           increase MAX_LINE_LENGTH to 16384
30-DEC-2008  MGD  v1.12.0, bugfix; "error (no status)" response selector
                           needs to be "0" not "000" (at least for WASD)
30-SEP-2006  MGD  v1.11.0, access log date/time as since/before filter
                           /DTBEFORE=<time-string> for date/time filter
                           /DTSINCE=<time-string> for date/time filter
                           selectors for log last modified and record date/time
                           accumulate OPTIONS, TRACE and ? (unknown) methods
01-JUN-2005  MGD  v1.10.3, update CgiForm() response statuses for HTTP/1.1,
                           /NOWASD and equivalent checkbox,
                           bugfix; date with leading space (ta Stuart Symonds)
10-MAY-2005  MGD  v1.10.2, SWS 2.0 ignore query string components supplied as
                           command-line parameters differently to CSWS 1.2/3
13-APR-2005  MGD  v1.10.1, bugfix; missing assignments in GetParameters()
11-MAY-2004  MGD  v1.10.0, IPv6 modifications
                           /IP=<integer> to select either IPv4 or IPv6 records
23-DEC-2003  MGD  v1.9.2, minor conditional mods to support IA64
02-DEC-2003  MGD  v1.9.1, 206 partial content
12-AUG-2003  MGD  v1.9.0, HTTP protocol filter
17-MAY-2003  MGD  v1.8.0, use regular expression matching (GNU RX1.5 source)
                          (this fundamentally changes some previous behaviours)
                          allow for protocol in URL ("method path protocol")
02-JAN-2003  MGD  v1.7.0, filtering on HTTP response status and response size
24-NOV-2002  MGD  v1.6.0, URL-decoding path/query/referer before filtering,
                          check for account SYSPRV before CLI activating
05-NOV-2002  MGD  v1.5.1, extend CGI log search to check for QDLOGSTATS_LOGS
                          then to fallback to HTTPD$LOG and HT_LOGS logicals
26-SEP-2002  MGD  v1.5.0, make CGI log search dependent on the QDLOGSTATS_LOGS
                          logical name being defined and log files within that
16-AUG-2002  MGD  v1.4.0, add log file last modification before/since,
                          some accomodations for CSWS 1.2,
                          bugfix; silly boy - what about HEAD method!
30-MAR-2002  MGD  v1.3.0, accumulate request methods
01-JUL-2001  MGD  v1.2.2, add 'SkipParameters' for direct OSU support
30-JAN-2001  MGD  v1.2.1, small improvement to lookup cache for noting
                          addresses that never resolve (and do it slowly)
10-JAN-2001  MGD  v1.2.0, lookup client host name
23-DEC-2000  MGD  v1.1.0, CGI interface (still pretty q&d)
14-NOV-2000  MGD  v1.0.0, initial development
*/
#endif /* COMMENTS_WITH_COMMENTS */
/*****************************************************************************/

#define COPYRIGHT_DATE "2000-2021"
#define SOFTWAREVN "2.0.0"
#define SOFTWARENM "QDLOGSTATS"
#ifdef __ALPHA
#  define SOFTWAREID SOFTWARENM " AXP-" SOFTWAREVN
#endif
#ifdef __ia64
#  define SOFTWAREID SOFTWARENM " IA64-" SOFTWAREVN
#endif
#ifdef __VAX
#  error VAX no longer implemented
#endif
#ifdef __x86_64
#  define SOFTWAREID SOFTWARENM " X86-" SOFTWAREVN
#endif

/* standard C header files */
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unixio.h>
#include <unixlib.h>

/* VMS-related header files */
#include <descrip.h>
#include <iodef.h>
#include <jpidef.h>
#include <libdef.h>
#include <lnmdef.h>
#include <lib$routines.h>
#include <prvdef.h>
#include <rms.h>
#include <ssdef.h>
#include <starlet.h>
#include <stsdef.h>
#include <syidef.h>

/* require this for TCP/IP Services IPv6 */
#define _SOCKADDR_LEN
/* BUT MultiNet BG driver does not support BSD 4.4 AF_INET addresses */
#define NO_SOCKADDR_LEN_4

/* TCP/IP-related header files */
#include <in.h>
#include <netdb.h>
#include <inet.h>

/* application related header files */
#include <cgilib.h>
#include <regex.h>

/* regular expression processing */
#define REGEX_CHAR '^'
/* compile flags, case-insensitive extended GREP */
#define REGEX_C_FLAGS (REG_EXTENDED | REG_ICASE)
/* execution flags */
#define REGEX_E_FLAGS (0)
/* one for each of the possible unique FilterThisOut()s */
#define REGEX_PATTERN_MAX 15
/* retry this many times (at a second interval) */
#define TCPIP_LOOKUP_HOST_NAME_RETRY 3

#define BOOL int
#define true 1
#define false 0

typedef struct _IO_SB
{
   unsigned short  Status;
   unsigned short  Count;
   unsigned long  Unused;
} IO_SB;

#define VMSok(x) ((x) & STS$M_SUCCESS)
#define VMSnok(x) (!((x) & STS$M_SUCCESS))
 
/* mainly to allow easy use of the __unaligned directive */
#define UINTPTR __unaligned unsigned int*
#define ULONGPTR __unaligned unsigned long*
#define USHORTPTR __unaligned unsigned short*
#define INT64PTR __unaligned __int64*

/* demonstrated to be an order of magnitude faster than memcmp() */

#define MATCH0(ptr1,ptr2,len) (memcmp(ptr1,ptr2,len) == 0)
#define MATCH1(ptr1,ptr2) (*(char*)(ptr1) == *(char*)(ptr2))
#define MATCH2(ptr1,ptr2) (*(USHORTPTR)(ptr1) == *(USHORTPTR)(ptr2))
#define MATCH3(ptr1,ptr2) ((*(ULONGPTR)(ptr1) & 0x00ffffff) == \
                           (*(ULONGPTR)(ptr2) & 0x00ffffff))
#define MATCH4(ptr1,ptr2) (*(ULONGPTR)(ptr1) == *(ULONGPTR)(ptr2))

#define MATCH5(ptr1,ptr2) ((*(INT64PTR)(ptr1) & 0x000000ffffffffff) == \
                           (*(INT64PTR)(ptr2) & 0x000000ffffffffff))
#define MATCH6(ptr1,ptr2) ((*(INT64PTR)(ptr1) & 0x0000ffffffffffff) == \
                           (*(INT64PTR)(ptr2) & 0x0000ffffffffffff))
#define MATCH7(ptr1,ptr2) ((*(INT64PTR)(ptr1) & 0x00ffffffffffffff) == \
                           (*(INT64PTR)(ptr2) & 0x00ffffffffffffff))
#define MATCH8(ptr1,ptr2) (*(INT64PTR)(ptr1) == *(INT64PTR)(ptr2))

#define FI_LI "QDLOGSTATS",__LINE__

/* used in modulus for every so many records progress */
#define PROGRESS_RECORDS 1000
/* wrap every so many characters */
#define PROGRESS_WRAP_CLI 80
#define PROGRESS_WRAP_CGI 60

/* maximum log line/record length */
#define MAX_LINE_LENGTH 16384

#define DEFAULT_LOGS_LOGICAL "QDLOGSTATS_LOGS"
#define DEFAULT_LOGS2_LOGICAL "HTTPD$LOG"
#define DEFAULT_LOGS3_LOGICAL "WASD_LOGS"
#define DEFAULT_LOGS_FILESPEC "*.LOG*;"
#define DEFAULT_LOGS_DIR_APACHE "APACHE$SPECIFIC:[LOGS]"
#define DEFAULT_LOGS_APACHE "*ACCESS_LOG*.;"
#define DEFAULT_LOGS_DIR_OSU  "WWW_ROOT:[SYSTEM]"
#define DEFAULT_LOGS_OSU "ACCESS*.LOG;"
#define DEFAULT_LOGS_DIR_WASD "WASD_LOGS:"
#define DEFAULT_LOGS_WASD "*ACCESS*.LOG*;"

#define VIEW_NONE     0
#define VIEW_LOG      1
#define VIEW_ALL      2
#define VIEW_MATCH    3
#define VIEW_NOMATCH  4
#define VIEW_SUSPECT  5
#define VIEW_UNIQUE   6  /* client */

char  CopyrightInfo [] =
"Copyright (C) " COPYRIGHT_DATE " Mark G.Daniel.\n\
This program, comes with ABSOLUTELY NO WARRANTY.\n\
This is free software, and you are welcome to redistribute it under the\n\
conditions of the GNU GENERAL PUBLIC LICENSE, version 3, or any later version.\n\
http://www.gnu.org/licenses/gpl.txt";

char  CopyrightMeta [] = "Copyright (C) " COPYRIGHT_DATE
                         " Mark G.Daniel - GPL licensed";

char  Utility [] = "QDLOGSTATS";

BOOL  Addr2Name,
      Debug,
      DoCgiStats,
      DoCliStats,
      FilterOnAll,
      GeoLocateForm,
      NoWasdEntries,
      ShowLogFile,
      UrlDecodePath,
      UrlDecodeQuery,
      UrlDecodeReferer;

int  AccessProblemCount,
     AuthUserFilterAcceptCount,
     AuthUserFilterRejectCount,
     ClientFilterAcceptCount,
     ClientFilterRejectCount,
     CombinedLogRecordCount,
     CommonLogRecordCount,
     DateTimeFilterRejectCount,
     DateTimeFilterAcceptCount,
     DateTimeProblemCount,
     DtBeforeFilterAcceptCount,
     DtBeforeFilterRejectCount,
     FileCountTotal,
     GeoLocateCodeLength,
     GeoLocateId,
     Ip4FilterAcceptCount,
     Ip4FilterRejectCount,
     Ip6FilterAcceptCount,
     Ip6FilterRejectCount,
     IpVersionFilter,
     LastModifiedIgnoredCount,
     LookupRetry,
     MethodFilterAcceptCount,
     MethodFilterRejectCount,
     MethodConnectCount,
     MethodConnectPercent,
     MethodCopyCount,
     MethodCopyPercent,
     MethodDeleteCount,
     MethodDeletePercent,
     MethodGetCount,
     MethodGetPercent,
     MethodHeadCount,
     MethodHeadPercent,
     MethodLockCount,
     MethodLockPercent,
     MethodMkColCount,
     MethodMkColPercent,
     MethodMoveCount,
     MethodMovePercent,
     MethodOptionsCount,
     MethodOptionsPercent,
     MethodPostCount,
     MethodPostPercent,
     MethodPropFindCount,
     MethodPropFindPercent,
     MethodPropPatchCount,
     MethodPropPatchPercent,
     MethodPutCount,
     MethodPutPercent,
     MethodTraceCount,
     MethodTracePercent,
     MethodUnknownCount,
     MethodUnknownPercent,
     MethodUnLockCount,
     MethodUnLockPercent,
     PathFilterAcceptCount,
     PathFilterRejectCount,
     ProgressCount,
     ProgressWrap,
     ProtocolFilterAcceptCount,
     ProtocolFilterRejectCount,
     QueryFilterAcceptCount,
     QueryFilterRejectCount,
     RecordCount,
     RecordCountTotal,
     SuspectRecordCountTotal,
     RequestCountTotal,
     RefererFilterAcceptCount,
     RefererFilterRejectCount,
     RemoteIdentFilterAcceptCount,
     RemoteIdentFilterRejectCount,
     ResponseMaxSize,
     ResponseMaxSizeAcceptCount,
     ResponseMaxSizeRejectCount,
     ResponseMinSize,
     ResponseMinSizeAcceptCount,
     ResponseMinSizeRejectCount,
     ShowProgress,
     DtSinceFilterAcceptCount,
     DtSinceFilterRejectCount,
     StatusFilterAcceptCount,
     StatusFilterRejectCount,
     UserAgentFilterAcceptCount,
     UserAgentFilterRejectCount,
     ViewRecords;

int  StatusCodeCount [6],
     StatusCodePercent [6];

unsigned long  BinTime [2],
               DtBeforeFilterBinTime [2],
               DtSinceFilterBinTime [2],
               LmBeforeBinTime [2],
               LmSinceBinTime [2];
unsigned short  NumTime [7];

float  ByteCountTotal;

char  *AuthUserFilterPtr,
      *CgiFormLogFileSpecPtr,
      *CgiLibEnvironmentPtr,
      *CgiRequestUriPtr,
      *CgiScriptNamePtr,
      *CgiServerNamePtr,
      *ClientFilterPtr,
      *DateTimeFilterPtr,
      *GeoLocatePtr,
      *IpVersionFilterPtr,
      *MethodFilterPtr,
      *OutputPtr,
      *PathFilterPtr,
      *ProtocolFilterPtr,
      *QueryFilterPtr,
      *RegCompPatternPtr,
      *RefererFilterPtr,
      *RemoteIdentFilterPtr,
      *SearchDna,
      *ResponseFilterPtr,
      *UserAgentFilterPtr;

char  LogFileSpec [256],
      DtBeforeFilterString [32],
      DtSinceFilterString [32],
      LmBeforeString [32],
      LmSinceString [32],
      RegCompErrorString [64],
      SoftwareID [64],
      StartDateTime [32];

$DESCRIPTOR (DateTime20FaoDsc, "!20%D\0");
$DESCRIPTOR (DtBeforeFilterStringDsc, DtBeforeFilterString);
$DESCRIPTOR (DtSinceFilterStringDsc, DtSinceFilterString);
$DESCRIPTOR (FarEnoughBackDsc, "01-JAN-1970 00:00:00.00");
$DESCRIPTOR (FarEnoughForwardDsc, "31-DEC-2100 23:59:59.99");
$DESCRIPTOR (LmBeforeStringDsc, LmBeforeString);
$DESCRIPTOR (LmSinceStringDsc, LmSinceString);
$DESCRIPTOR (StartDateTimeFaoDsc, "!17%D\0");
$DESCRIPTOR (StartDateTimeDsc, StartDateTime);

const uchar  Ip4AddrZero [4],
             Ip6AddrZero [16];

#define INETACP$C_TRANS 2
#define INETACP_FUNC$C_GETHOSTBYNAME 1
#define INETACP_FUNC$C_GETHOSTBYADDR 2
$DESCRIPTOR (TcpIpDeviceDsc, "UCX$DEVICE");

/* required function prototypes */
void CgiForm ();
void CgiStats ();
void CliStats ();
BOOL CompileFilters ();
void DateTimeSelector ();
void DateTimeCgi ();
char* DateTimeFilter (char*);
BOOL FilterBinDateTime (char*);
BOOL FilterThisOut (char*, char*);
int GetParameters ();
void LogModifiedCgi ();
void LogModifiedSelector ();
void NeedsPrivilegedAccount ();
void OutputLogRecord (char*);
int ProcessLogFile (char*);
int ProcessLogRecord (char*);
int SearchFileSpec (char*);
int ShowHelp ();
int strsame (char*, char*, int);
char* StatTimer ();
char* SysGetMsg (int);
char* SysTrnLnmSystem (char*);
BOOL TcpIpIsAddress (char*);
char* TcpIpLookup (char*, char*, uchar*, uchar*);
BOOL UniqueClient (char*);

/*****************************************************************************/
/*
'argc' and 'argv' are only required to support CgiLibEnvironmentInit(), in
particular the OSU environment.
*/

main
(
int argc,
char *argv[]
)
{
   /*********/
   /* begin */
   /*********/

   sprintf (SoftwareID, "%s (%s)", SOFTWAREID, CGILIB_SOFTWAREID);

   sys$gettim (&BinTime);
   sys$numtim (&NumTime, &BinTime);

   /* always initialize the CGILIB so we can at least determine the mode */
   if (getenv ("QDLOGSTATS$DBUG")) Debug = true;
   CgiLibEnvironmentSetDebug (Debug);
   if (Debug) fprintf (stdout, "Content-Type: text/plain\n\n");

   CgiLibEnvironmentInit (argc, argv, false);

   GetParameters ();

   /* determine if we're at the command line or being used as a script */
   if (!CgiLibVarNull ("WWW_GATEWAY_INTERFACE"))
   {
      DoCliStats = true;
      CliStats ();
   }
   else
   {
      DoCgiStats = true;
      CgiStats ();
   }

   exit (SS$_NORMAL);
}

/*****************************************************************************/
/*
Generate command-line output containing the statistics.
*/

void CliStats ()

{
   int  status;
   char  *cptr;
   char  AccessProblemString [64],
         AuthUserString [256],
         ByteString [256],
         ClientString [256],
         DateTimeString [256],
         DateTimeProblemString [64],
         IgnoredString [256],
         LastModifiedString [128],
         IpVersionString [128],
         MethodString [256],
         PathString [256],
         ProtocolString [256],
         QueryString [256],
         RefererString [256],
         RemoteIdentString [256],
         ResponseMaxSizeString [128],
         ResponseMinSizeString [128],
         ResponseString [128],
         UserAgentString [256];
   unsigned long  ResultBinTime [2];

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

   NeedsPrivilegedAccount ();

   if (OutputPtr)
      if (!(stdout = freopen (OutputPtr, "w", stdout)))
         exit (vaxc$errno);

   if (!LogFileSpec[0])
   {
      ShowHelp ();
      exit (SS$_NORMAL);
   }

   sys$fao (&StartDateTimeFaoDsc, NULL, &StartDateTimeDsc, 0);
   if (StartDateTime[0] == ' ') StartDateTime[0] = '0';
   fprintf (stdout, "%s, %s\n", SoftwareID, StartDateTime);
   StatTimer ();

   if (LmBeforeBinTime[0])
   {
      sys$fao (&DateTime20FaoDsc, NULL, &LmBeforeStringDsc, &LmBeforeBinTime);
      if (!LmSinceBinTime[0])
      {
         /* create a time far enough in the past */
         status = sys$bintim (&FarEnoughBackDsc, &LmSinceBinTime);
         if (VMSnok (status)) exit (status);
      }
   }
   if (LmSinceBinTime[0])
   {
      sys$fao (&DateTime20FaoDsc, NULL, &LmSinceStringDsc, &LmSinceBinTime);
      if (!LmBeforeBinTime[0])
      {
         /* create a time far enough in the future */
         status = sys$bintim (&FarEnoughForwardDsc, &LmBeforeBinTime);
         if (VMSnok (status)) exit (status);
      }
   }
   if (LmSinceBinTime[0] || LmBeforeBinTime[0])
   {
      /* sanity check on the filter window */
      status = lib$sub_times (&LmBeforeBinTime, &LmSinceBinTime,
                              &ResultBinTime);
      if (Debug) fprintf (stdout, "lib$sub_times() %%X%08.08X\n", status);
      if (status == LIB$_NEGTIM) exit (LIB$_NEGTIM);
   }

   if (LmSinceString[0] || LmBeforeString[0])
   {
      LastModifiedString[0] = '\0';
      if (LmSinceString[0])
         sprintf (LastModifiedString, "since %s", LmSinceString);
      if (LmBeforeString[0])
      {
         for (cptr = LastModifiedString; *cptr; cptr++);
         sprintf (cptr, "%sbefore %s",
                  LastModifiedString[0] ? "\n" : "", LmBeforeString);
      }
   }
   else
      strcpy (LastModifiedString, "<none>");

   if (DtBeforeFilterBinTime[0])
   {
      sys$fao (&DateTime20FaoDsc, NULL, &DtBeforeFilterStringDsc,
               &DtBeforeFilterBinTime);
      if (!DtSinceFilterBinTime[0])
      {
         /* create a time far enough in the past */
         status = sys$bintim (&FarEnoughBackDsc, &DtSinceFilterBinTime);
         if (VMSnok (status)) exit (status);
      }
   }
   if (DtSinceFilterBinTime[0])
   {
      sys$fao (&DateTime20FaoDsc, NULL, &DtSinceFilterStringDsc,
               &DtSinceFilterBinTime);
      if (!DtBeforeFilterBinTime[0])
      {
         /* create a time far enough in the future */
         status = sys$bintim (&FarEnoughForwardDsc, &DtBeforeFilterBinTime);
         if (VMSnok (status)) exit (status);
      }
   }
   if (DtSinceFilterBinTime[0] || DtBeforeFilterBinTime[0])
   {
      /* sanity check on the filter window */
      status = lib$sub_times (&DtBeforeFilterBinTime, &DtSinceFilterBinTime,
                              &ResultBinTime);
      if (Debug) fprintf (stdout, "lib$sub_times() %%X%08.08X\n", status);
      if (status == LIB$_NEGTIM) exit (LIB$_NEGTIM);
   }

   if (!CompileFilters ())
   {
      fprintf (stdout, "%%%s-E-REGEX, expression \'%s\' has %s",
               Utility, RegCompPatternPtr, RegCompErrorString);
      exit (STS$K_ERROR | STS$M_INHIB_MSG);
   }

   ProgressWrap = PROGRESS_WRAP_CLI;

   /* make a guess at the log file defaults */
   if (getenv("WASD_ROOT") || getenv("HT_ROOT"))
   {
      SearchDna = DEFAULT_LOGS_DIR_WASD;
      cptr = DEFAULT_LOGS_WASD;
   }
   else
   if (getenv("WWW_ROOT"))
   {
      SearchDna = DEFAULT_LOGS_DIR_OSU ;
      cptr = DEFAULT_LOGS_OSU;
   }
   else
   if (getenv("APACHE$SPECIFIC"))
   {
      SearchDna = DEFAULT_LOGS_DIR_APACHE;
      cptr = DEFAULT_LOGS_APACHE;
   }
   else
   {
      SearchDna = DEFAULT_LOGS_FILESPEC;
      cptr = DEFAULT_LOGS_FILESPEC;
   }

   if (LogFileSpec[0]) cptr = LogFileSpec;

   status = SearchFileSpec (cptr);

   if (ShowProgress && FileCountTotal) fputs ("\n", stdout);

   if (VMSnok (status) && status != RMS$_NMF) exit (status);

   if (AccessProblemCount)
      sprintf (AccessProblemString, ", %d access failed", AccessProblemCount);
   else
      AccessProblemString[0] = '\0';

   if (LastModifiedIgnoredCount)
      sprintf (IgnoredString, ", %d ignored", LastModifiedIgnoredCount);
   else
      IgnoredString[0] = '\0';

   if (ByteCountTotal > 1000000000.0)
   {
      ByteCountTotal /= 1000000000.0;
      sprintf (ByteString, "GBytes ....... %.3f", ByteCountTotal);
   }
   else
   if (ByteCountTotal > 1000000.0)
   {
      ByteCountTotal /= 1000000.0;
      sprintf (ByteString, "MBytes ........ %.3f", ByteCountTotal);
   }
   else
   if (ByteCountTotal > 1000.0)
   {
      ByteCountTotal /= 1000.0;
      sprintf (ByteString, "KBytes ........ %.3f", ByteCountTotal);
   }
   else
      sprintf (ByteString, "Bytes ......... %.0f", ByteCountTotal);

   if (!ResponseMinSize)
      strcpy (ResponseMinSizeString, "<none>");
   else
   if (ResponseMinSize < 1000)
      sprintf (ResponseMinSizeString, "%d", ResponseMinSize); 
   else
   if (ResponseMinSize < 1000000)
      sprintf (ResponseMinSizeString, "%dk", ResponseMinSize / 1000); 
   else
      sprintf (ResponseMinSizeString, "%dM", ResponseMinSize / 1000000); 

   if (!ResponseMaxSize)
      strcpy (ResponseMaxSizeString, "<none>");
   else
   if (ResponseMaxSize < 1000)
      sprintf (ResponseMaxSizeString, "%d", ResponseMaxSize); 
   else
   if (ResponseMaxSize < 1000000)
      sprintf (ResponseMaxSizeString, "%dk", ResponseMaxSize / 1000); 
   else
      sprintf (ResponseMaxSizeString, "%dM", ResponseMaxSize / 1000000); 

   if (FilterOnAll)
   {
      if (!ClientFilterPtr)
         strcpy (ClientString, "<none>");
      else
         sprintf (ClientString, "%s  (%d nomatch, %d match)",
                  ClientFilterPtr, ClientFilterRejectCount,
                                   ClientFilterAcceptCount);
      if (!IpVersionFilter)
         strcpy (IpVersionString, "<none>");
      else
      if (IpVersionFilter == 4)
         sprintf (IpVersionString, "4  (%d nomatch, %d match)",
                  Ip4FilterRejectCount, Ip4FilterAcceptCount);
      else
      if (IpVersionFilter == 6)
         sprintf (IpVersionString, "6  (%d nomatch, %d match)",
                  Ip6FilterRejectCount, Ip6FilterAcceptCount);
      if (!AuthUserFilterPtr)
         strcpy (AuthUserString, "<none>");
      else
         sprintf (AuthUserString, "%s  (%d nomatch, %d match)",
                  AuthUserFilterPtr, AuthUserFilterRejectCount,
                                     AuthUserFilterAcceptCount);
      if (DtSinceFilterString[0] || DtBeforeFilterString[0])
      {
         DateTimeString[0] = '\0';
         if (DtSinceFilterString[0])
            sprintf (DateTimeString, "%ssince %s  (%d nomatch, %d match)",
                     DtBeforeFilterString[0] ? " " : "",
                     DtSinceFilterString, DtSinceFilterRejectCount,
                                          DtSinceFilterAcceptCount);
         if (DtBeforeFilterString[0])
         {
            if (DateTimeString[0])
               strcat (DateTimeString, "\n                ");
            for (cptr = DateTimeString; *cptr; cptr++);
            sprintf (cptr, "before %s  (%d nomatch, %d match)",
                     DtBeforeFilterString, DtBeforeFilterRejectCount,
                                           DtBeforeFilterAcceptCount);
         }
      }
      else
      if (!DateTimeFilterPtr)
         strcpy (DateTimeString, "<none>");
      else
         sprintf (DateTimeString, "%s  (%d nomatch, %d match)",
                  DateTimeFilterPtr, DateTimeFilterRejectCount,
                                     DateTimeFilterAcceptCount);
      if (!MethodFilterPtr)
         strcpy (MethodString, "<none>");
      else
         sprintf (MethodString, "%s  (%d nomatch, %d match)",
                  MethodFilterPtr, MethodFilterRejectCount,
                                   MethodFilterAcceptCount);
      if (!PathFilterPtr)
         strcpy (PathString, "<none>");
      else
         sprintf (PathString, "%s  (%d nomatch, %d match)",
                  PathFilterPtr, PathFilterRejectCount,
                                 PathFilterAcceptCount);
      if (!QueryFilterPtr)
         strcpy (QueryString, "<none>");
      else
         sprintf (QueryString, "  (%d nomatch, %d match)",
                  QueryFilterRejectCount, QueryFilterAcceptCount);
      if (!RefererFilterPtr)
         strcpy (RefererString, "<none>");
      else
         sprintf (RefererString, "%s  (%d nomatch, %d match)",
                  RefererFilterPtr, RefererFilterRejectCount,
                                    RefererFilterAcceptCount);
      if (!ProtocolFilterPtr)
         strcpy (ProtocolString, "<none>");
      else
         sprintf (ProtocolString, "  (%d nomatch, %d match)",
                  ProtocolFilterRejectCount, ProtocolFilterAcceptCount);
      if (!RefererFilterPtr)
         strcpy (RefererString, "<none>");
      else
         sprintf (RefererString, "%s  (%d nomatch, %d match)",
                  RefererFilterPtr, RefererFilterRejectCount,
                                    RefererFilterAcceptCount);
      if (!RemoteIdentFilterPtr)
         strcpy (RemoteIdentString, "<none>");
      else
         sprintf (RemoteIdentString, "%s  (%d nomatch, %d match)",
                  RemoteIdentFilterPtr, RemoteIdentFilterRejectCount,
                                        RemoteIdentFilterAcceptCount);
      if (!UserAgentFilterPtr)
         strcpy (UserAgentString, "<none>");
      else
         sprintf (UserAgentString, "%s  (%d nomatch, %d match)",
                  UserAgentFilterPtr, UserAgentFilterRejectCount,
                                      UserAgentFilterAcceptCount);
      if (!ResponseFilterPtr)
         strcpy (ResponseString, "<none>");
      else
         sprintf (ResponseString, "%s  (%d nomatch, %d match)",
                  ResponseFilterPtr, StatusFilterRejectCount,
                                     StatusFilterAcceptCount);
      if (ResponseMinSize)
      {
         for (cptr = ResponseMinSizeString; *cptr; cptr++);
         sprintf (cptr, "  (%d nomatch, %d match)",
                  ResponseMinSizeRejectCount, ResponseMinSizeAcceptCount);
      }
      if (ResponseMaxSize)
      {
         for (cptr = ResponseMaxSizeString; *cptr; cptr++);
         sprintf (cptr, "  (%d nomatch, %d match)",
                  ResponseMaxSizeRejectCount, ResponseMaxSizeAcceptCount);
      }
   }
   else
   {
      if (!ClientFilterPtr)
         strcpy (ClientString, "<none>");
      else
         sprintf (ClientString, "%s  (%d nomatch)",
                  ClientFilterPtr, ClientFilterRejectCount);
      if (!IpVersionFilter)
         strcpy (IpVersionString, "<none>");
      else
      if (IpVersionFilter == 4)
         sprintf (IpVersionString, "4  (%d nomatch)",
                  Ip4FilterRejectCount);
      else
      if (IpVersionFilter == 6)
         sprintf (IpVersionString, "6  (%d nomatch)",
                  Ip6FilterRejectCount);
      if (!AuthUserFilterPtr)
         strcpy (AuthUserString, "<none>");
      else
         sprintf (AuthUserString, "%s  (%d nomatch)",
                  AuthUserFilterPtr, AuthUserFilterRejectCount);

      if (DtSinceFilterString[0] || DtBeforeFilterString[0])
      {
         DateTimeString[0] = '\0';
         if (DtSinceFilterString[0])
            sprintf (DateTimeString, "%ssince %s  (%d nomatch)",
                     DtBeforeFilterString[0] ? " " : "",
                     DtSinceFilterString, DtSinceFilterRejectCount);
         if (DtBeforeFilterString[0])
         {
            if (DateTimeString[0])
               strcat (DateTimeString, "\n                ");
            for (cptr = DateTimeString; *cptr; cptr++);
            sprintf (cptr, "before %s  (%d nomatch)",
                     DtBeforeFilterString, DtBeforeFilterRejectCount);
         }
      }
      else
      if (!DateTimeFilterPtr)
         strcpy (DateTimeString, "<none>");
      else
         sprintf (DateTimeString, "%s  (%d nomatch)",
                  DateTimeFilterPtr, DateTimeFilterRejectCount);

      if (!MethodFilterPtr)
         strcpy (MethodString, "<none>");
      else
         sprintf (MethodString, "%s  (%d nomatch)",
                  MethodFilterPtr, MethodFilterRejectCount);
      if (!PathFilterPtr)
         strcpy (PathString, "<none>");
      else
         sprintf (PathString, "%s  (%d nomatch)",
                  PathFilterPtr, PathFilterRejectCount);
      if (!QueryFilterPtr)
         strcpy (QueryString, "<none>");
      else
         sprintf (QueryString, "%s  (%d nomatch)",
                  QueryFilterPtr, QueryFilterRejectCount);
      if (!ProtocolFilterPtr)
         strcpy (ProtocolString, "<none>");
      else
         sprintf (ProtocolString, "%s  (%d nomatch)",
                  ProtocolFilterPtr, ProtocolFilterRejectCount);
      if (!RefererFilterPtr)
         strcpy (RefererString, "<none>");
      else
         sprintf (RefererString, "%s  (%d nomatch)",
                  RefererFilterPtr, RefererFilterRejectCount);
      if (!RemoteIdentFilterPtr)
         strcpy (RemoteIdentString, "<none>");
      else
         sprintf (RemoteIdentString, "%s  (%d nomatch)",
                  RemoteIdentFilterPtr, RemoteIdentFilterRejectCount);
      if (!UserAgentFilterPtr)
         strcpy (UserAgentString, "<none>");
      else
         sprintf (UserAgentString, "%s  (%d nomatch)",
                  UserAgentFilterPtr, UserAgentFilterRejectCount);
      if (!ResponseFilterPtr)
         strcpy (ResponseString, "<none>");
      else
         sprintf (ResponseString, "%s  (%d nomatch)",
                  ResponseFilterPtr, StatusFilterRejectCount);
      if (ResponseMinSize)
      {
         for (cptr = ResponseMinSizeString; *cptr; cptr++);
         sprintf (cptr, "  (%d nomatch)",
                  ResponseMinSizeRejectCount);
      }
      if (ResponseMaxSize)
      {
         for (cptr = ResponseMaxSizeString; *cptr; cptr++);
         sprintf (cptr, "  (%d nomatch)",
                  ResponseMaxSizeRejectCount);
      }
   }

   if (DateTimeProblemCount)
      sprintf (DateTimeProblemString, "  (%d format problems)",
               DateTimeProblemCount);
   else
      DateTimeProblemString[0] = '\0';

   fprintf (stdout,
"\n\
Log ........... %s  (%d matched%s%s)\n\
Modified ...... %s\n\
Client ........ %s\n\
IP Version .... %s\n\
Remote ID ..... %s\n\
Auth User ..... %s\n\
Date/Time ..... %s%s\n\
Method ........ %s\n\
Path .......... %s\n\
Query ......... %s\n\
Protocol ...... %s\n\
Referer ....... %s\n\
User Agent .... %s\n\
\n\
Response ...... %s\n\
Size Min ...... %s\n\
Size Max ...... %s\n\
\n\
Statistics .... %s\n\
Records ....... %d  (%d suspect, %d common, %d combined)\n\
Requests ...... %d\n\
Methods ....... CONNECT:%d (%d%%)  COPY:%d (%d%%)  DELETE:%d (%d%%)  \
GET:%d (%d%%)  HEAD:%d (%d%%)  LOCK:%d (%d%%)  MKCOL:%d (%d%%)  \
MOVE:%d (%d%%) OPTIONS:%d (%d%%)  POST:%d (%d%%)  PROPFIND:%d (%d%%)  \
POPPATCH:%d (%d%%)  PUT:%d (%d%%)  TRACE:%d (%d%%)  UNLOCK:%d (%d%%)  \
?:%d (%d%%) \n\
Responses ..... 1nn:%d (%d%%) 2nn:%d (%d%%) 3nn:%d (%d%%) 4nn:%d (%d%%) \
5nn:%d  (%d%%) ?:%d (%d%%) \n\
%s\n",
      LogFileSpec, FileCountTotal, IgnoredString, AccessProblemString,
      LastModifiedString,
      ClientString,
      IpVersionString,
      RemoteIdentString,
      AuthUserString,
      DateTimeString, DateTimeProblemString,
      MethodString,
      PathString,
      QueryString,
      ProtocolString,
      RefererString,
      UserAgentString,
      ResponseString,
      ResponseMinSizeString,
      ResponseMaxSizeString,
      StatTimer(),
      RecordCountTotal, SuspectRecordCountTotal,
      CommonLogRecordCount, CombinedLogRecordCount,
      RequestCountTotal,
      MethodConnectCount,
      MethodConnectPercent,
      MethodCopyCount,
      MethodCopyPercent,
      MethodDeleteCount,
      MethodDeletePercent,
      MethodGetCount,
      MethodGetPercent,
      MethodHeadCount,
      MethodHeadPercent,
      MethodLockCount,
      MethodLockPercent,
      MethodMkColCount,
      MethodMkColPercent,
      MethodMoveCount,
      MethodMovePercent,
      MethodOptionsCount,
      MethodOptionsPercent,
      MethodPostCount,
      MethodPostPercent,
      MethodPropFindCount,
      MethodPropFindPercent,
      MethodPropPatchCount,
      MethodPropPatchPercent,
      MethodPutCount,
      MethodPutPercent,
      MethodTraceCount,
      MethodTracePercent,
      MethodUnLockCount,
      MethodUnLockPercent,
      MethodUnknownCount,
      MethodUnknownPercent,
      StatusCodeCount[1],
      StatusCodePercent[1],
      StatusCodeCount[2],
      StatusCodePercent[2],
      StatusCodeCount[3],
      StatusCodePercent[3],
      StatusCodeCount[4],
      StatusCodePercent[4],
      StatusCodeCount[5],
      StatusCodePercent[5],
      StatusCodeCount[0],
      StatusCodePercent[0],
      ByteString);
}      

/*****************************************************************************/
/*
Generate a CGI response containing an HTML page of statistics.
*/

void CgiStats ()

{
#ifndef PRV$M_READALL
#define PRV$M_READALL 0x0008
#endif

   static unsigned long  PrvMask [2] =
      { (unsigned long)PRV$M_SYSPRV | (unsigned long)PRV$M_READALL, 0 };

   BOOL  ShowProgressOnPage;
   int  status;
   char  *cptr,
         *ByteStringPtr;
   char  AccessProblemString [64],
         AuthUserString [256],
         ByteString [16],
         ClientString [256],
         DateTimeString [256],
         DateTimeProblemString [64],
         IgnoredString [256],
         IpVersionString [128],
         LastModifiedString [128],
         MethodString [256],
         PathString [256],
         ProtocolString [256],
         QueryString [256],
         RefererString [256],
         RemoteIdentString [256],
         ResponseMaxSizeString [128],
         ResponseMinSizeString [128],
         ResponseString [128],
         UserAgentString [256],
         VmsMessage [512];

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

   /* ensure one of the required log directory logicals is defined */
   if (!(SearchDna = SysTrnLnmSystem(DEFAULT_LOGS_LOGICAL)))
      if (!(SearchDna = SysTrnLnmSystem(DEFAULT_LOGS2_LOGICAL)))
         if (!(SearchDna = SysTrnLnmSystem(DEFAULT_LOGS3_LOGICAL)))
         {
            CgiLibResponseError (FI_LI, 0, "Logical name "
                                           DEFAULT_LOGS_LOGICAL
                                           " is not defined.");
            return;
         }
   
   sys$fao (&StartDateTimeFaoDsc, NULL, &StartDateTimeDsc, 0);
   if (StartDateTime[0] == ' ') StartDateTime[0] = '0';
   StatTimer();

   cptr = CgiLibVar ("WWW_REMOTE_USER");
   if (!cptr[0])
   {
      CgiLibResponseError (FI_LI, 0, "Authorization mandatory.");
      return;
   }

   CgiLibEnvironmentRecordOut ();
   CgiLibEnvironmentPtr = CgiLibEnvironmentName();
   CgiServerNamePtr = CgiLibVar ("WWW_SERVER_NAME");

   CgiFormLogFileSpecPtr = CgiLibVarNull ("WWW_FORM_LOGFILESPEC");
   if (!CgiFormLogFileSpecPtr)
   {
      CgiForm ();
      return;
   }

   LogModifiedCgi ();

   if (LmSinceString[0] || LmBeforeString[0])
   {
      LastModifiedString[0] = '\0';
      if (LmSinceString[0])
         sprintf (LastModifiedString, "since %s", LmSinceString);
      if (LmBeforeString[0])
      {
         for (cptr = LastModifiedString; *cptr; cptr++);
         sprintf (cptr, "%sbefore %s",
                  LastModifiedString[0] ? "<BR>" : "", LmBeforeString);
      }
   }
   else
      strcpy (LastModifiedString, "<I>&lt;none&gt;</I>");

   /* get the filter components from the form */
   ClientFilterPtr = CgiLibVar ("WWW_FORM_CLIENT");
   if (!ClientFilterPtr[0]) ClientFilterPtr = NULL;
   IpVersionFilterPtr = CgiLibVar ("WWW_FORM_IPV");
   if (*IpVersionFilterPtr == '4')
      IpVersionFilter = 4;
   else
   if (*IpVersionFilterPtr == '6')
      IpVersionFilter = 6;
   else
      IpVersionFilter = 0;
   RemoteIdentFilterPtr = CgiLibVar ("WWW_FORM_REMOTEID");
   if (!RemoteIdentFilterPtr[0]) RemoteIdentFilterPtr = NULL;
   AuthUserFilterPtr = CgiLibVar ("WWW_FORM_AUTHUSER");
   if (!AuthUserFilterPtr[0])  AuthUserFilterPtr = NULL;

   DateTimeCgi ();

   MethodFilterPtr = CgiLibVar ("WWW_FORM_METHOD");
   if (!MethodFilterPtr[0])
      MethodFilterPtr = CgiLibVar ("WWW_FORM_METHODLIST");
   if (!MethodFilterPtr[0]) MethodFilterPtr = NULL;
   PathFilterPtr = CgiLibVar ("WWW_FORM_PATH");
   if (!PathFilterPtr[0]) PathFilterPtr = NULL;
   cptr = CgiLibVar ("WWW_FORM_DECODEPATH");
   if (cptr[0]) UrlDecodePath = true; else UrlDecodePath = false;
   ProtocolFilterPtr = CgiLibVar ("WWW_FORM_PROTOCOL");
   if (!ProtocolFilterPtr[0])
      ProtocolFilterPtr = CgiLibVar ("WWW_FORM_PROTOCOLLIST");
   if (!ProtocolFilterPtr[0]) ProtocolFilterPtr = NULL;
   QueryFilterPtr = CgiLibVar ("WWW_FORM_QUERY");
   if (!QueryFilterPtr[0]) QueryFilterPtr = NULL;
   cptr = CgiLibVar ("WWW_FORM_DECODEQUERY");
   if (cptr[0]) UrlDecodeQuery = true; else UrlDecodeQuery = false;
   RefererFilterPtr = CgiLibVar ("WWW_FORM_REFERER");
   if (!RefererFilterPtr[0]) RefererFilterPtr = NULL;
   cptr = CgiLibVar ("WWW_FORM_DECODEREFERER");
   if (cptr[0]) UrlDecodeReferer = true; else UrlDecodeReferer = false;
   UserAgentFilterPtr = CgiLibVar ("WWW_FORM_USERAGENT");
   if (!UserAgentFilterPtr[0]) UserAgentFilterPtr = NULL;
   ResponseFilterPtr = CgiLibVar ("WWW_FORM_RESPONSE");
   if (!ResponseFilterPtr[0])
      ResponseFilterPtr = CgiLibVar ("WWW_FORM_RESPONSELIST");
   if (!ResponseFilterPtr[0]) ResponseFilterPtr = NULL;

   cptr = CgiLibVar ("WWW_FORM_VIEW");
   ShowLogFile = ShowProgressOnPage = false;
   if (strsame (cptr, "ALL", -1))
      ViewRecords = VIEW_ALL;
   else
   if (strsame (cptr, "ALL-LOG", -1))
   {
      ViewRecords = VIEW_ALL;
      ShowLogFile = true;
   }
   else
   if (strsame (cptr, "LOG", -1))
   {
      ViewRecords = VIEW_LOG;
      ShowLogFile = true;
   }
   else
   if (strsame (cptr, "MATCH", -1))
      ViewRecords = VIEW_MATCH;
   else
   if (strsame (cptr, "MATCH-LOG", -1))
   {
      ViewRecords = VIEW_MATCH;
      ShowLogFile = true;
   }
   else
   if (strsame (cptr, "NOMATCH", -1))
      ViewRecords = VIEW_NOMATCH;
   else
   if (strsame (cptr, "NOMATCH-LOG", -1))
   {
      ViewRecords = VIEW_NOMATCH;
      ShowLogFile = true;
   }
   else
   if (strsame (cptr, "PROGRESS", -1))
      ShowProgressOnPage = true;
   else
   if (strsame (cptr, "SUSPECT", -1))
   {
      ViewRecords = VIEW_SUSPECT;
      ShowLogFile = true;
   }
   else
   if (strsame (cptr, "UNIQUE", -1))
   {
      ViewRecords = VIEW_UNIQUE;
      ShowLogFile = true;
   }

   cptr = CgiLibVar ("WWW_FORM_ALL");
   if (cptr[0]) FilterOnAll = true;

   cptr = CgiLibVar ("WWW_FORM_REMWASD");
   if (cptr[0]) NoWasdEntries = true;

   cptr = CgiLibVar ("WWW_FORM_RESOLVE");
   if (cptr[0]) Addr2Name = true;

   cptr = CgiLibVar ("WWW_FORM_LOOKUP");
   if (isdigit(cptr[0])) LookupRetry = atoi(cptr);

   cptr = CgiLibVar ("WWW_FORM_MINSIZE");
   if (!cptr[0]) cptr = CgiLibVar ("WWW_FORM_MINSIZELIST");
   ResponseMinSize = atoi(cptr);
   if (isdigit(*cptr))
   {
      while (isdigit(*cptr)) cptr++;
      if (tolower(*cptr) == 'k') ResponseMinSize *= 1000;
      if (toupper(*cptr) == 'M') ResponseMinSize *= 1000000 ;
   }
   if (!ResponseMinSize)
      strcpy (ResponseMinSizeString, "<I>&lt;none&gt;</I>");
   else
   if (ResponseMinSize < 1000)
      sprintf (ResponseMinSizeString, "%d", ResponseMinSize); 
   else
   if (ResponseMinSize < 1000000)
      sprintf (ResponseMinSizeString, "%dk", ResponseMinSize / 1000); 
   else
      sprintf (ResponseMinSizeString, "%dM", ResponseMinSize / 1000000); 

   cptr = CgiLibVar ("WWW_FORM_MAXSIZE");
   if (!cptr[0]) cptr = CgiLibVar ("WWW_FORM_MAXSIZELIST");
   ResponseMaxSize = atoi(cptr);
   if (isdigit(*cptr))
   {
      while (isdigit(*cptr)) cptr++;
      if (tolower(*cptr) == 'k') ResponseMaxSize *= 1000;
      if (toupper(*cptr) == 'M') ResponseMaxSize *= 1000000;
   }
   if (!ResponseMaxSize)
      strcpy (ResponseMaxSizeString, "<I>&lt;none&gt;</I>");
   else
   if (ResponseMaxSize < 1000)
      sprintf (ResponseMaxSizeString, "%d", ResponseMaxSize); 
   else
   if (ResponseMaxSize < 1000000)
      sprintf (ResponseMaxSizeString, "%dk", ResponseMaxSize / 1000); 
   else
      sprintf (ResponseMaxSizeString, "%dM", ResponseMaxSize / 1000000); 

   if (!CompileFilters ())
   {
      CgiLibResponseError (FI_LI, 0,
"The regular expression&nbsp; <tt>%s</tt>&nbsp; has %s.",
         (char*)CgiLibHtmlEscape(RegCompPatternPtr, -1, NULL, 0),
         RegCompErrorString);
      return;
   }

   if (cptr = CgiLibVarNull ("WWW_FORM_GEOLOCATE"))
   {
      if (*cptr)
      {
         GeoLocateForm = true;
         if (GeoLocateForm)
            GeoLocatePtr = SysTrnLnmSystem("QDLOGSTATS_GEOLOCATE");
      }
   }

   /* WASD stream mode will stop each fflush() having carriage control added */
   CgiLibEnvironmentBinaryOut ();
   CgiLibResponseHeader (200, "text/html", "Script-Control: X-stream-mode\n");

   fprintf (stdout,
"<!DOCTYPE html>\n\
<html>\n\
<head>\n\
<meta name=\"generator\" content=\"%s\">\n\
<meta name=\"copyright\" content=\"%s\">\n\
<meta name=\"environment\" content=\"%s\">\n\
<meta name=\"dna\" content=\"%s\">\n\
<title>qdLogStats@%s</title>\n\
<style type=\"text/css\">\n\
@media print { #wrap { display:none; } }\n\
body { font-family:arial,verdana,helvetica,sans; font-size:11pt; \
background-color:white; color:black; margin:1em; }\n\
pre { font-family:monospace, monospace; margin-left:10px; }\n\
.alt1 { display:inline-block; border:none; }\n\
.attn { font-family:arial,verdana,helvetica,sans; }\n\
.fnt130 { font-size:1.3em; }\n\
.fnt080 { font-size:0.80em; }\n\
</style>\n\
<script>\n\
\
function reportWrap() {\n\
   var stylesheet = document.styleSheets[0];\n\
   var report = document.getElementById(\'report\');\n\
   var wrap = document.getElementById(\'wrap\');\n\
   var style;\n\
   if (report.style.whiteSpace == 'pre-wrap') {\n\
      report.style.whiteSpace = 'pre';\n\
      wrap.value = 'wrap';\n\
      style = 'display:inline-block;border:none;';\n\
   }\n\
   else {\n\
      report.style.whiteSpace = 'pre-wrap';\n\
      wrap.value = 'nowrap';\n\
      style = 'display:inline-block;border-left:1px solid black;\
border-right:1px solid black;margin-left:-5px;padding-left:5px;\
padding-right:5px;'\n\
   }\n\
   for (let i = 0; i < stylesheet.cssRules.length; i++) {\n\
     if (stylesheet.cssRules[i].selectorText == '.alt1') {\n\
        var alt1 = stylesheet.cssRules[i];\n\
        alt1.style = style;\n\
        break;\n\
     }\n\
   }\n\
   window.scrollTo(0,document.body.scrollHeight);\n\
}\n\
</script>\n\
%s%s%s\
</head>\n\
<body>\n\
<span class=\"fnt130\"><b><u>qdLogStats@%s</u></b></span><br>\n\
&nbsp;&nbsp;&nbsp;%s<br>\n\
&nbsp;&nbsp;&nbsp;%s\n",
      SoftwareID, CopyrightMeta,
      CgiLibEnvironmentPtr, SearchDna, CgiServerNamePtr,
      GeoLocatePtr ? "<script src=\"" : "" ,
      GeoLocatePtr ? GeoLocatePtr : "" ,
      GeoLocatePtr ? "\"></script>\n" : "" ,
      CgiServerNamePtr,
      SOFTWAREID, StartDateTime);

   if (ViewRecords)
      fputs ("<p><hr size=\"1\" width=\"85%\" align=\"left\" noshade>\
<pre id=\"report\">", stdout);
   else
   {
      /* the CGI interface always provides hidden progress indication */
      ShowProgress = PROGRESS_RECORDS;
      if (ShowProgressOnPage)
         fputs ("<pre>", stdout);
      else
         fputs ("<!-- just an indicator of progress ...\n", stdout);
   }
   fflush (stdout);

   ProgressWrap = PROGRESS_WRAP_CGI;

   /* just get the file portion of any file spec supplied */
   for (cptr = CgiFormLogFileSpecPtr; *cptr; cptr++);
   while (cptr > CgiFormLogFileSpecPtr && *cptr != ']') cptr--;
   if (*cptr == ']') cptr++;
   if (*cptr) CgiFormLogFileSpecPtr = cptr; 

   status = sys$setprv (1, &PrvMask, 0, 0);
   if (Debug) fprintf (stdout, "sys$setprv() %%X%08.08X\n", status);

   status = SearchFileSpec (CgiFormLogFileSpecPtr);

   sys$setprv (0, &PrvMask, 0, 0);

   if (ViewRecords)
      fputs ("</pre>\n\
<hr id=\"horlin\" size=\"1\" width=\"85%\" align=\"left\" noshade>\n\
<script>\
document.getElementById(\'horlin\').style.display=\'inline-block\';\
document.write(\'<input id=\"wrap\" type=\"button\" value=\"wrap\" \
onclick=\"reportWrap()\">\')\
</script>\n", stdout);
   else
   if (ShowProgressOnPage)
      fputs ("</pre>\n", stdout);
   else
      fputs (" -->\n", stdout);

   if (VMSnok (status) && status != RMS$_NMF && status != RMS$_FNF)
      sprintf (VmsMessage,
"<tr><th align=\"right\"><font color=\"#ff0000\">error</span>:&nbsp;</th>\
<td>%s<!-- %%X%08.08X --></td></tr>\n\
<tr><th height=\"8\"></th></tr>\n",
               SysGetMsg(status), status);
   else
      VmsMessage[0] = '\0';

   if (AccessProblemCount)
      sprintf (AccessProblemString, ", %d access failed", AccessProblemCount);
   else
      AccessProblemString[0] = '\0';

   if (LastModifiedIgnoredCount)
      sprintf (IgnoredString, ", %d ignored", LastModifiedIgnoredCount);
   else
      IgnoredString[0] = '\0';

   if (ByteCountTotal > 1000000000.0)
   {
      ByteCountTotal /= 1000000000.0;
      ByteStringPtr = "GBytes";
      sprintf (ByteString, "%.3f", ByteCountTotal);
   }
   else
   if (ByteCountTotal > 1000000.0)
   {
      ByteCountTotal /= 1000000.0;
      ByteStringPtr = "MBytes";
      sprintf (ByteString, "%.3f", ByteCountTotal);
   }
   else
   if (ByteCountTotal > 1000.0)
   {
      ByteCountTotal /= 1000.0;
      ByteStringPtr = "KBytes";
      sprintf (ByteString, "%.3f", ByteCountTotal);
   }
   else
   {
      ByteStringPtr = "Bytes";
      sprintf (ByteString, "%.0f", ByteCountTotal);
   }

   if (FilterOnAll)
   {
      if (!ClientFilterPtr)
         strcpy (ClientString, "<I>&lt;none&gt;</I>");
      else
         sprintf (ClientString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (ClientFilterPtr, -1, NULL, 0),
                  ClientFilterRejectCount, ClientFilterAcceptCount);
      if (!IpVersionFilter)
         strcpy (IpVersionString, "<I>&lt;none&gt;</I>");
      else
      if (IpVersionFilter == 4)
         sprintf (IpVersionString, "4  (%d nomatch, %d match)",
                  Ip4FilterRejectCount, Ip4FilterAcceptCount);
      else
      if (IpVersionFilter == 6)
         sprintf (IpVersionString, "6  (%d nomatch, %d match)",
                  Ip6FilterRejectCount, Ip6FilterAcceptCount);
      if (!AuthUserFilterPtr)
         strcpy (AuthUserString, "<I>&lt;none&gt;</I>");
      else
         sprintf (AuthUserString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (AuthUserFilterPtr, -1, NULL, 0),
                  AuthUserFilterRejectCount, AuthUserFilterAcceptCount);

      if (DtSinceFilterString[0] || DtBeforeFilterString[0])
      {
         DateTimeString[0] = '\0';
         if (DtSinceFilterString[0])
            sprintf (DateTimeString, "%ssince %s  (%d nomatch, %d match)",
                     DtBeforeFilterString[0] ? "&nbsp;&nbsp;" : "",
                     DtSinceFilterString, DtSinceFilterRejectCount,
                                          DtSinceFilterAcceptCount);
         if (DtBeforeFilterString[0])
         {
            if (DateTimeString[0]) strcat (DateTimeString, "<BR>");
            for (cptr = DateTimeString; *cptr; cptr++);
            sprintf (cptr, "before %s  (%d nomatch, %d match)",
                     DtBeforeFilterString, DtBeforeFilterRejectCount,
                                           DtBeforeFilterAcceptCount);
         }
      }
      else
         strcpy (DateTimeString, "<I>&lt;none&gt;</I>");

      if (!MethodFilterPtr)
         strcpy (MethodString, "<I>&lt;none&gt;</I>");
      else
         sprintf (MethodString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (MethodFilterPtr, -1, NULL, 0),
                  MethodFilterRejectCount, MethodFilterAcceptCount);
      if (!PathFilterPtr)
         strcpy (PathString, "<I>&lt;none&gt;</I>");
      else
         sprintf (PathString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (PathFilterPtr, -1, NULL, 0),
                  PathFilterRejectCount, PathFilterAcceptCount);
      if (!QueryFilterPtr)
         strcpy (QueryString, "<I>&lt;none&gt;</I>");
      else
         sprintf (QueryString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (QueryFilterPtr, -1, NULL, 0),
                  QueryFilterRejectCount, QueryFilterAcceptCount);
      if (!ProtocolFilterPtr)
         strcpy (ProtocolString, "<I>&lt;none&gt;</I>");
      else
         sprintf (ProtocolString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (ProtocolFilterPtr, -1, NULL, 0),
                  ProtocolFilterRejectCount, ProtocolFilterAcceptCount);
      if (!RefererFilterPtr)
         strcpy (RefererString, "<I>&lt;none&gt;</I>");
      else
         sprintf (RefererString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (RefererFilterPtr, -1, NULL, 0),
                  RefererFilterRejectCount, RefererFilterAcceptCount);
      if (!RemoteIdentFilterPtr)
         strcpy (RemoteIdentString, "<I>&lt;none&gt;</I>");
      else
         sprintf (RemoteIdentString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (RemoteIdentFilterPtr, -1, NULL, 0),
                  RemoteIdentFilterRejectCount, RemoteIdentFilterAcceptCount);
      if (!UserAgentFilterPtr)
         strcpy (UserAgentString, "<I>&lt;none&gt;</I>");
      else
         sprintf (UserAgentString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (UserAgentFilterPtr, -1, NULL, 0),
                  UserAgentFilterRejectCount, UserAgentFilterAcceptCount);
      if (!ResponseFilterPtr)
         strcpy (ResponseString, "<I>&lt;all&gt;</I>");
      else
         sprintf (ResponseString, "&quot;%s&quot;&nbsp; (%d nomatch, %d match)",
                  (char*)CgiLibHtmlEscape (ResponseFilterPtr, -1, NULL, 0),
                  StatusFilterRejectCount, StatusFilterAcceptCount);
      if (ResponseMinSize)
      {
         for (cptr = ResponseMinSizeString; *cptr; cptr++);
         sprintf (cptr, "&nbsp; (%d nomatch, %d match)",
                  ResponseMinSizeRejectCount, ResponseMinSizeAcceptCount);
      }
      if (ResponseMaxSize)
      {
         for (cptr = ResponseMaxSizeString; *cptr; cptr++);
         sprintf (cptr, "&nbsp; (%d nomatch, %d match)",
                  ResponseMaxSizeRejectCount, ResponseMaxSizeAcceptCount);
      }
   }
   else
   {
      if (!ClientFilterPtr)
         strcpy (ClientString, "<I>&lt;none&gt;</I>");
      else
         sprintf (ClientString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (ClientFilterPtr, -1, NULL, 0),
                  ClientFilterRejectCount);
      if (!IpVersionFilter)
         strcpy (IpVersionString, "<I>&lt;none&gt;</I>");
      else
      if (IpVersionFilter == 4)
         sprintf (IpVersionString, "4  (%d nomatch)",
                  Ip4FilterRejectCount);
      else
      if (IpVersionFilter == 6)
         sprintf (IpVersionString, "6  (%d nomatch)",
                  Ip6FilterRejectCount);
      if (!AuthUserFilterPtr)
         strcpy (AuthUserString, "<I>&lt;none&gt;</I>");
      else
         sprintf (AuthUserString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (AuthUserFilterPtr, -1, NULL, 0),
                  AuthUserFilterRejectCount);

      if (DtSinceFilterString[0] || DtBeforeFilterString[0])
      {
         DateTimeString[0] = '\0';
         if (DtSinceFilterString[0])
            sprintf (DateTimeString, "%ssince %s  (%d nomatch)",
                     DtBeforeFilterString[0] ? "&nbsp;&nbsp;" : "",
                     DtSinceFilterString, DtSinceFilterRejectCount);
         if (DtBeforeFilterString[0])
         {
            if (DateTimeString[0]) strcat (DateTimeString, "<BR>");
            for (cptr = DateTimeString; *cptr; cptr++);
            sprintf (cptr, "before %s  (%d nomatch)",
                     DtBeforeFilterString, DtBeforeFilterRejectCount);
         }
      }
      else
         strcpy (DateTimeString, "<I>&lt;none&gt;</I>");

      if (!MethodFilterPtr)
         strcpy (MethodString, "<I>&lt;none&gt;</I>");
      else
         sprintf (MethodString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (MethodFilterPtr, -1, NULL, 0),
                  MethodFilterRejectCount);
      if (!PathFilterPtr)
         strcpy (PathString, "<I>&lt;none&gt;</I>");
      else
         sprintf (PathString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (PathFilterPtr, -1, NULL, 0),
                  PathFilterRejectCount);
      if (!QueryFilterPtr)
         strcpy (QueryString, "<I>&lt;none&gt;</I>");
      else
         sprintf (QueryString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (QueryFilterPtr, -1, NULL, 0),
                  QueryFilterRejectCount);
      if (!ProtocolFilterPtr)
         strcpy (ProtocolString, "<I>&lt;none&gt;</I>");
      else
         sprintf (ProtocolString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (ProtocolFilterPtr, -1, NULL, 0),
                  ProtocolFilterRejectCount);
      if (!RefererFilterPtr)
         strcpy (RefererString, "<I>&lt;none&gt;</I>");
      else
         sprintf (RefererString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (RefererFilterPtr, -1, NULL, 0),
                  RefererFilterRejectCount);
      if (!RemoteIdentFilterPtr)
         strcpy (RemoteIdentString, "<I>&lt;none&gt;</I>");
      else
         sprintf (RemoteIdentString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (RemoteIdentFilterPtr, -1, NULL, 0),
                  RemoteIdentFilterRejectCount);
      if (!UserAgentFilterPtr)
         strcpy (UserAgentString, "<I>&lt;none&gt;</I>");
      else
         sprintf (UserAgentString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (UserAgentFilterPtr, -1, NULL, 0),
                  UserAgentFilterRejectCount);

      if (!ResponseFilterPtr)
         strcpy (ResponseString, "<I>&lt;none&gt;</I>");
      else
         sprintf (ResponseString, "&quot;%s&quot;&nbsp; (%d nomatch)",
                  (char*)CgiLibHtmlEscape (ResponseFilterPtr, -1, NULL, 0),
                  StatusFilterRejectCount);
      if (ResponseMinSize)
      {
         for (cptr = ResponseMinSizeString; *cptr; cptr++);
         sprintf (cptr, "&nbsp; (%d nomatch)",
                  ResponseMinSizeRejectCount);
      }
      if (ResponseMaxSize)
      {
         for (cptr = ResponseMaxSizeString; *cptr; cptr++);
         sprintf (cptr, "&nbsp; (%d nomatch)",
                  ResponseMaxSizeRejectCount);
      }
   }

   if (DateTimeProblemCount)
      sprintf (DateTimeProblemString, " (%d format problems)",
               DateTimeProblemCount);
   else
      DateTimeProblemString[0] = '\0';

   fprintf (stdout,
"<p><table cellpadding=\"0\" cellspacing=\"3\" border=\"0\">\n\
%s\
<tr><th align=\"right\">Log:&nbsp;</th><td>%s%s(%d matched%s%s)</td></tr>\n\
<tr><th align=\"right\" valign=\"top\">Modified:&nbsp;</th><td>%s</td></tr>\n\
<tr><th height=\"8\"></th></tr>\n\
<tr><th align=\"right\">Client:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">IP&nbsp;Version:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Remote&nbsp;ID:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Auth&nbsp;User:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\" valign=\"top\">Date/Time:&nbsp;</th><td>%s%s</td></tr>\n\
<tr><th align=\"right\">Method:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Path:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Query:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Protocol:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Referer:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">User&nbsp;Agent:&nbsp;</th><td>%s</td></tr>\n\
<tr><th height=\"8\"></th></tr>\n\
<tr><th align=\"right\">Response:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Size&nbsp;Min:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Max:&nbsp;</th><td>%s</td></tr>\n\
<tr><th height=\"8\"></th></tr>\n\
<tr><th align=\"right\">Statistics:&nbsp;</th><td>%s</td></tr>\n\
<tr><th align=\"right\">Records:&nbsp;</th>\
<td><nobr>%d&nbsp; (%d suspect, %d common, %d combined)</nobr></td></tr>\n\
<tr><th align=\"right\">Requests:&nbsp;</th><td>%d</td></tr>\n\
<tr><th align=\"right\" valign=\"top\">Methods:&nbsp;</th>\
<td style=\"max-width:45em;\">CONNECT:%d&nbsp;(%d%%)&nbsp; COPY:%d&nbsp;(%d%%)&nbsp; \
DELETE:%d&nbsp;(%d%%)&nbsp; GET:%d&nbsp;(%d%%)&nbsp; \
HEAD:%d&nbsp;(%d%%)&nbsp; LOCK:%d&nbsp;(%d%%)&nbsp; \
MKCOL:%d&nbsp;(%d%%)&nbsp; MOVE:%d&nbsp;(%d%%)&nbsp; \
OPTIONS:%d&nbsp;(%d%%)&nbsp; POST:%d&nbsp;(%d%%)&nbsp; \
PROPFIND:%d&nbsp;(%d%%)&nbsp; PROPPATCH:%d&nbsp;(%d%%)&nbsp; \
PUT:%d&nbsp;(%d%%)&nbsp; TRACE:%d&nbsp;(%d%%)&nbsp; \
UNLOCK:%d&nbsp;(%d%%)&nbsp; ?:%d&nbsp;(%d%%)</td></tr>\n\
<tr><th align=\"right\">Responses:&nbsp;</th>\
<td><nobr>1nn:%d&nbsp;(%d%%)&nbsp; 2nn:%d&nbsp;(%d%%)&nbsp; \
3nn:%d&nbsp;(%d%%)&nbsp; 4nn:%d&nbsp;(%d%%)&nbsp; 5nn:%d&nbsp;(%d%%)&nbsp; \
?:%d&nbsp;(%d%%)&nbsp;</nobr></td></tr>\n\
<tr><th align=\"right\">%s:&nbsp;</th><td>%s</td></tr>\n\
</table>\n\
</body>\n\
</html>\n",
      VmsMessage,
      CgiFormLogFileSpecPtr,
      CgiFormLogFileSpecPtr[0] ? "&nbsp;&nbsp;" : "", FileCountTotal,
      IgnoredString,
      AccessProblemString,
      LastModifiedString,
      ClientString,
      IpVersionString,
      RemoteIdentString,
      AuthUserString,
      DateTimeString, DateTimeProblemString,
      MethodString,
      PathString,
      QueryString,
      ProtocolString,
      RefererString,
      UserAgentString,
      ResponseString,
      ResponseMinSizeString,
      ResponseMaxSizeString,
      StatTimer(),
      RecordCountTotal, SuspectRecordCountTotal,
      CommonLogRecordCount, CombinedLogRecordCount,
      RequestCountTotal,
      MethodConnectCount,
      MethodConnectPercent,
      MethodCopyCount,
      MethodCopyPercent,
      MethodDeleteCount,
      MethodDeletePercent,
      MethodGetCount,
      MethodGetPercent,
      MethodHeadCount,
      MethodHeadPercent,
      MethodLockCount,
      MethodLockPercent,
      MethodMkColCount,
      MethodMkColPercent,
      MethodMoveCount,
      MethodMovePercent,
      MethodOptionsCount,
      MethodOptionsPercent,
      MethodPostCount,
      MethodPostPercent,
      MethodPropFindCount,
      MethodPropFindPercent,
      MethodPropPatchCount,
      MethodPropPatchPercent,
      MethodPutCount,
      MethodPutPercent,
      MethodTraceCount,
      MethodTracePercent,
      MethodUnLockCount,
      MethodUnLockPercent,
      MethodUnknownCount,
      MethodUnknownPercent,
      StatusCodeCount[1],
      StatusCodePercent[1],
      StatusCodeCount[2],
      StatusCodePercent[2],
      StatusCodeCount[3],
      StatusCodePercent[3],
      StatusCodeCount[4],
      StatusCodePercent[4],
      StatusCodeCount[5],
      StatusCodePercent[5],
      StatusCodeCount[0],
      StatusCodePercent[0],
      ByteStringPtr, ByteString);
}

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

void CgiForm ()

{
   char  *cptr;

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

   if (Debug) fprintf (stdout, "CgiForm()\n");

   GeoLocatePtr = SysTrnLnmSystem("QDLOGSTATS_GEOLOCATE");

   /* make a guess at the log file defaults */
   if (CgiLibEnvironmentIsWasd())
      cptr = DEFAULT_LOGS_WASD;
   else
   if (CgiLibEnvironmentIsOsu())
      cptr = DEFAULT_LOGS_OSU;
   else
   if (CgiLibEnvironmentIsApache())
      cptr = DEFAULT_LOGS_APACHE;
   else
      cptr = DEFAULT_LOGS_FILESPEC;

   CgiLibEnvironmentPtr = CgiLibEnvironmentName();

   CgiScriptNamePtr = CgiLibVar ("WWW_SCRIPT_NAME");

   sys$fao (&StartDateTimeFaoDsc, NULL, &StartDateTimeDsc, 0);
   if (StartDateTime[0] == ' ') StartDateTime[0] = '0';

   CgiLibResponseHeader (200, "text/html");

   fprintf (stdout,
"<!DOCTYPE html>\n\
<html>\n\
<head>\n\
<meta name=\"generator\" content=\"%s\">\n\
<meta name=\"copyright\" content=\"%s\">\n\
<meta name=\"environment\" content=\"%s\">\n\
<meta name=\"dna\" content=\"%s\">\n\
<title>qdlogstats@%s</title>\n\
<style type=\"text/css\">\n\
body { font-family:arial,verdana,helvetica,sans; font-size:11pt; }\n\
.fnt130 { font-size:1.3em; }\n\
</style>\n\
<script>\n\
function adjustSize(the,size) {\n\
   if (typeof the == 'string') the = document.getElementById(the);\n\
   if (typeof size == 'number')\n\
      the.size = size;\n\
   else\n\
   if (the.size < 30 && the.value.length >= 5)\n\
      the.size = 30;\n\
   else\n\
   if (the.size > 10 && the.value.length >= the.size * 0.7)\n\
      the.size *= 2;\n\
   else\n\
   if (the.size > 30 && the.value.length <= the.size * 0.3)\n\
      the.size /= 2;\n\
}\n\
function resetSize() {\n\
   adjustSize('client',30);\n\
   adjustSize('remoteid',30);\n\
   adjustSize('authuser',30);\n\
   adjustSize('method',10);\n\
   adjustSize('path',30);\n\
   adjustSize('query',30);\n\
   adjustSize('referer',30);\n\
   adjustSize('useragent',30);\n\
   adjustSize('response',5);\n\
   return true;\n\
}\n\
</script>\n\
</head>\n\
<body>\n\
<span class=\"fnt130\"><b><u>qdLogStats@%s</u></b></span><br>\n\
&nbsp;&nbsp;&nbsp;%s<br>\n\
&nbsp;&nbsp;&nbsp;%s\n\
<form method=\"GET\" action=\"%s\">\n\
<p><table cellpadding=\"0\" cellspacing=\"3\" border=\"0\">\n\
<tr><th align=\"right\">Log&nbsp;Specification:&nbsp;</th>\n\
<td><input type=\"text\" name=\"logfilespec\" size=\"30\" value=\"%s\" \
onfocus=\"this.select()\">\
</td></tr>\n",
      SoftwareID, CopyrightMeta, CgiLibEnvironmentPtr, SearchDna,
      CgiServerNamePtr, CgiServerNamePtr,
      SOFTWAREID, StartDateTime,
      CgiScriptNamePtr, cptr);

   LogModifiedSelector ();

   fprintf (stdout,
"<tr><td height=\"7\"></td></tr>\n\
<tr><th align=\"right\">Client:&nbsp;</th>\n\
<td><input id=\"client\" type=\"text\" name=\"client\" size=\"30\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\">\n\
&nbsp;<input type=\"checkbox\" name=\"lookup\" value=\"%d\">\
&nbsp;<span class=\"fnt080\"><i>lookup&nbsp;name</i></span>\n\
</td></tr>\n\
<tr><th align=\"right\">IP&nbsp;Version:&nbsp;</th><td>\n\
<select name=\"ipv\">\n\
<option value=\"0\" selected>all\n\
<option value=\"4\">v4 only\n\
<option value=\"6\">v6 only\n\
</select>\n\
</td></tr>\n\
<tr><th align=\"right\">Remote&nbsp;ID:&nbsp;</th>\n\
<td><input id=\"remoteid\" type=\"text\" name=\"remoteid\" size=\"30\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\"></td></tr>\n\
<tr><th align=\"right\">Auth User:&nbsp;</th>\n\
<td><input id=\"authuser\" type=\"text\" name=\"authuser\" size=\"30\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\"></td></tr>\n",
            TCPIP_LOOKUP_HOST_NAME_RETRY);

   DateTimeSelector ();

   fprintf (stdout,
"<tr><th align=\"right\">Method:&nbsp;</th><td>\n\
<select name=\"methodlist\">\n\
<option value=\"\" selected>all\n\
<option value=\"CONNECT\">CONNECT\n\
<option value=\"COPY\">COPY\n\
<option value=\"DELETE\">DELETE\n\
<option value=\"GET\">GET\n\
<option value=\"HEAD\">HEAD\n\
<option value=\"LOCK\">LOCK\n\
<option value=\"MKCOL\">MKCOL\n\
<option value=\"MOVE\">MOVE\n\
<option value=\"OPTIONS\">OPTIONS\n\
<option value=\"POST\">POST\n\
<option value=\"PROPFIND\">PROPFIND\n\
<option value=\"PROPPATCH\">PROPPATCH\n\
<option value=\"PUT\">PUT\n\
<option value=\"TRACE\">TRACE\n\
<option value=\"UNLOCK\">UNLOCK\n\
<option value=\"(WebDAV)\">WebDAV-specific\n\
<option value=\"?\">unknown\n\
</select>\n\
&nbsp;<span class=\"fnt080\"><i>or</i></span>&nbsp;\
<input id=\"method\" type=\"text\" name=\"method\" size=\"10\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\">\n\
</td></tr>\n\
<tr><th align=\"right\">Path:&nbsp;</th>\n\
<td><input id=\"path\" type=\"text\" name=\"path\" size=\"30\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\">\n\
&nbsp;<input type=\"checkbox\" name=\"decodepath\" value=\"1\">\
&nbsp;<span class=\"fnt080\"><i>decode&nbsp;first</i></span>\n\
</td></tr>\n\
<tr><th align=\"right\">Query:&nbsp;</th>\n\
<td><input id=\"query\" type=\"text\" name=\"query\" size=\"30\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\">\n\
&nbsp;<input type=\"checkbox\" name=\"decodeQuery\" value=\"1\">\
&nbsp;<span class=\"fnt080\"><i>decode&nbsp;first</i></span>\n\
</td></tr>\n\
<tr><th align=\"right\">Protocol:&nbsp;</th><td>\n\
<select name=\"protocollist\">\n\
<option value=\"\" selected>all\n\
<option value=\"HTTP/2\">HTTP/2\n\
<option value=\"HTTP/1.1\">HTTP/1.1\n\
<option value=\"HTTP/1.0\">HTTP/1.0\n\
<option value=\"^^$\">HTTP/0.9\n\
</SELECT>\n\
&nbsp;<span class=\"fnt080\"><i>or</i></span>&nbsp;\
<input type=\"text\" name=\"protocol\" size=\"10\" \
onfocus=\"this.select()\">\n\
</td></tr>\n\
<tr><th align=\"right\">Referer:&nbsp;</th>\n\
<td><input id=\"referer\" type=\"text\" name=\"referer\" size=\"30\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\">\n\
&nbsp;<input type=\"checkbox\" name=\"decodereferer\" value=\"1\">\
&nbsp;<span class=\"fnt080\"><i>decode&nbsp;first</i></span>\n\
</td></tr>\n\
<tr><th align=\"right\">User&nbsp;Agent:&nbsp;</th>\n\
<td><input id=\"useragent\" type=\"text\" name=\"useragent\" size=\"30\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\">\n\
</td></tr>\n\
<tr><td height=\"8\"></td></tr>\n\
<tr><th align=\"right\">Response:&nbsp;</th><td>\n\
<select name=\"responselist\">\n\
<option value=\"\" selected>all\n\
<option value=\"1**\">1nn - general informational\n\
<option value=\"101\">101 - switching protocols\n\
<option value=\"102\">102 - processing\n\
<option value=\"103\">103 - checkpoint\n\
<option value=\"2**\">2nn - general success\n\
<option value=\"200\">200 - success\n\
<option value=\"201\">201 - created\n\
<option value=\"202\">202 - accepted\n\
<option value=\"203\">203 - non-authoritative\n\
<option value=\"204\">204 - no content\n\
<option value=\"205\">205 - reset content\n\
<option value=\"206\">206 - partial content\n\
<option value=\"3**\">3nn - client action\n\
<option value=\"300\">300 - multiple choices\n\
<option value=\"301\">301 - moved perm\n\
<option value=\"302\">302 - moved temp\n\
<option value=\"303\">303 - see other\n\
<option value=\"304\">304 - not modified\n\
<option value=\"305\">305 - use proxy\n\
<option value=\"307\">307 - temp redirect\n\
<option value=\"4**\">4nn - client error\n\
<option value=\"400\">400 - bad request\n\
<option value=\"401\">401 - authorization\n\
<option value=\"402\">402 - payment required\n\
<option value=\"403\">403 - forbidden\n\
<option value=\"404\">404 - not found\n\
<option value=\"405\">405 - method not allowed\n\
<option value=\"406\">406 - not acceptable\n\
<option value=\"407\">407 - proxy auth\n\
<option value=\"408\">408 - request timeout\n\
<option value=\"409\">409 - conflict\n\
<option value=\"410\">410 - gone\n\
<option value=\"411\">411 - length required\n\
<option value=\"412\">412 - precondition failed\n\
<option value=\"413\">413 - entity too large\n\
<option value=\"414\">414 - URI too long\n\
<option value=\"415\">415 - unsupported media\n\
<option value=\"416\">416 - range not satifiable\n\
<option value=\"417\">417 - expectation failed\n\
<option value=\"418\">418 - I'm a teapot\n\
<option value=\"5**\">5nn - server error\n\
<option value=\"500\">500 - internal\n\
<option value=\"501\">501 - not implemented\n\
<option value=\"502\">502 - bad gateway\n\
<option value=\"503\">503 - unavailable\n\
<option value=\"504\">504 - gateway timeout\n\
<option value=\"505\">505 - HTTP version not supported\n\
<option value=\"!^(1[0-9]{2})|(2[0-9]{2})|\
(301)|(302)|(304)|(401)|(403)|(404)\">\
NOT - 1nn,2nn,301,302,304,401,403,404\n\
<option value=\"0\">error (no status)\n\
</select>\n\
&nbsp;<span class=\"fnt080\"><i>or</i></span>&nbsp;\
<input id=\"response\" type=\"text\" name=\"response\" size=\"5\" \
onfocus=\"this.select()\" onkeypress=\"adjustSize(this)\">\n\
</td></tr>\n\
<tr><th align=\"right\">Size Min:&nbsp;</th><td>\n\
<select name=\"minsizelist\">\n\
<option value=\"\" selected>none\n\
<option value=\"100\">100\n\
<option value=\"250\">250\n\
<option value=\"500\">500\n\
<option value=\"1k\">1k\n\
<option value=\"2.5k\">2.5k\n\
<option value=\"5k\">5k\n\
<option value=\"10k\">10k\n\
<option value=\"25k\">25k\n\
<option value=\"50k\">50k\n\
<option value=\"100k\">100k\n\
<option value=\"250k\">250k\n\
<option value=\"500k\">500k\n\
<option value=\"1M\">1M\n\
<option value=\"10M\">10M\n\
<option value=\"100M\">100M\n\
</select>\n\
&nbsp;<span class=\"fnt080\"><i>or</i></span>&nbsp;\
<input type=\"text\" name=\"minsize\" size=\"6\" \
onfocus=\"this.select()\">\n\
</td></tr>\n\
<tr><th align=\"right\">Max:&nbsp;</th><td>\n\
<select name=\"maxsizelist\">\n\
<option value=\"\" selected>none\n\
<option value=\"100\">100\n\
<option value=\"250\">250\n\
<option value=\"500\">500\n\
<option value=\"1k\">1k\n\
<option value=\"2.5k\">2.5k\n\
<option value=\"5k\">5k\n\
<option value=\"10k\">10k\n\
<option value=\"25k\">25k\n\
<option value=\"50k\">50k\n\
<option value=\"100k\">100k\n\
<option value=\"250k\">250k\n\
<option value=\"500k\">500k\n\
<option value=\"1M\">1M\n\
<option value=\"10M\">10M\n\
<option value=\"100M\">100M\n\
</select>\n\
&nbsp;<span class=\"fnt080\"><i>or</i></span>&nbsp;\
<input type=\"text\" name=\"maxsize\" size=\"6\" \
onfocus=\"this.select()\">\n\
</td></tr>\n\
<tr><td height=\"8\"></td></tr>\n\
<tr><th align=\"right\">View:&nbsp;</th><td>\n\
<select name=\"view\">\n\
<option value=\"none\" selected>none\n\
<option value=\"progress\">progress\n\
<option value=\"match\">matching records\n\
<option value=\"match-log\">matching + log names\n\
<option value=\"nomatch\">non-matching records\n\
<option value=\"nomatch-log\">non-matching + log names\n\
<option value=\"unique\">unique clients\n\
<option value=\"all\">all records\n\
<option value=\"suspect\">suspect records\n\
<option value=\"all-log\">all + log names\n\
<option value=\"log\">log names\n\
</select>\n");

   if (CgiLibEnvironmentIsWasd())
      fprintf (stdout,
"&nbsp;<input type=\"checkbox\" name=\"remwasd\" value=\"1\">\
<span class=\"fnt080\">&nbsp;<i>no WASD entries</i></span>\n");

   fprintf (stdout,
"&nbsp;<input type=\"checkbox\" name=\"all\" value=\"1\">\
<span class=\"fnt080\">&nbsp;<i>match all</i></span>\n\
&nbsp;<input type=\"checkbox\" name=\"resolve\" value=\"1\">\
<span class=\"fnt080\">&nbsp;<i>resolve</i></span>\n");

   if (GeoLocatePtr)
      fprintf (stdout,
"<script>\n\
document.write(\'&nbsp;<input type=\"checkbox\" name=\"geolocate\" \
value=\"1\"><span class=\"fnt080\">&nbsp;<i>geolocate</i></span>\');\n\
</script>\n\
</td></tr>\n");

   fprintf (stdout,
"<tr><th height=\"4\"></th></tr>\n\
<tr><th></th><td>\n\
<input type=\"submit\" value=\"Submit\">&nbsp;&nbsp;\
<input type=\"reset\" value=\"reset\" onclick=\"return resetSize()\">\n\
</td></tr>\n\
</table>\n\
</form>\n\
</body>\n\
</html>\n");
}

/****************************************************************************/
/*
Generate HTML form selectors for the modified since and before log file
filters.  Default it to cover the last month (for want of something better).
*/ 

void LogModifiedSelector ()

{
   static char  *MonthName [] =
      { "", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
            "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };

   int  cnt, lm;

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

   if (Debug) fprintf (stdout, "LogModifiedSelector()\n");

   if ((lm = NumTime[1] - 1) < 1) lm = 12;   

   fprintf (stdout,
"<tr><th align=\"right\">Modified&nbsp;Since:&nbsp;</th><td>\n\
<select name=\"lmsdd\">\n");
   for (cnt = 1; cnt <= 31; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%02d\n",
               cnt, cnt == NumTime[2] ? " selected" : "", cnt);
   fprintf (stdout, "</select>\n<select name=\"lmsmmm\">\n");
   for (cnt = 1; cnt <= 12; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%s\n",
               cnt, cnt == lm ? " selected" : "", MonthName[cnt]);
   fprintf (stdout, "</select>\n<select name=\"lmsyyyy\">\n");
   for (cnt = NumTime[0]-10; cnt <= NumTime[0]+1; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%04d\n",
               cnt, cnt == NumTime[0] ? " selected" : "", cnt);
   fprintf (stdout,
"</select>\n\
&nbsp;<input type=\"checkbox\" name=\"lmsfilter\" value=\"1\">\
&nbsp;<span class=\"fnt080\"><i>apply&nbsp;since</i></span>\n\
</td></tr>\n");

   fprintf (stdout,
"<tr><th align=\"right\">Before:&nbsp;</th><td>\n\
<select name=\"lmbdd\">\n");
   for (cnt = 1; cnt <= 31; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%02d\n",
               cnt, cnt == NumTime[2] ? " selected" : "", cnt);
   fprintf (stdout, "</select>\n<select name=\"lmbmmm\">\n");
   for (cnt = 1; cnt <= 12; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%s\n",
               cnt, cnt == NumTime[1] ? " selected" : "", MonthName[cnt]);
   fprintf (stdout, "</select>\n<select name=\"lmbyyyy\">\n");
   for (cnt = NumTime[0]-10; cnt <= NumTime[0]+1; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%04d\n",
               cnt, cnt == NumTime[0] ? " selected" : "", cnt);
   fprintf (stdout,
"</select>\n\
&nbsp;<input type=\"checkbox\" name=\"lmbfilter\" value=\"1\">\
&nbsp;<span class=\"fnt080\"><i>apply&nbsp;before</i></span>\n\
</td></tr>\n");
}

/****************************************************************************/
/*
Get the since and before filter form fields and convert these to binary
date/times.  If an error with the time report and exit script.
*/ 

void LogModifiedCgi ()

{
   static char  *MonthName[] =
      { "***", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
               "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };

   static $DESCRIPTOR (DateTimeFaoDsc, "!2ZL-!3AZ-!4ZL !2ZL:!2ZL:!2ZL.!2ZL");

   int  dd, mmm, yyyy, status;
   unsigned short  slen;
   unsigned long  ResultBinTime [2];
   char  *cptr;
   char  DateTime [32];
   $DESCRIPTOR (DateTimeDsc, DateTime);

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

   if (Debug) fprintf (stdout, "LogModifiedCgi()\n");

   if (CgiLibVarNull ("WWW_FORM_LMSFILTER"))
   {
      /* applying the since filter */
      cptr = CgiLibVar ("WWW_FORM_LMSDD");
      dd = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_LMSMMM");
      mmm = atoi(cptr);
      if (mmm < 1 || mmm > 12) mmm = 0;
      cptr = CgiLibVar ("WWW_FORM_LMSYYYY");
      yyyy = atoi(cptr);

      sys$fao (&DateTimeFaoDsc, &slen, &DateTimeDsc,
               dd, MonthName[mmm], yyyy, 0, 0, 0, 0);
      DateTimeDsc.dsc$w_length = slen;
      DateTime[slen] = '\0';

      status = sys$bintim (&DateTimeDsc, &LmSinceBinTime);
      if (VMSnok (status))
      {
         CgiLibResponseError (FI_LI, status,
                              "log modified since filter ... %s", DateTime);
         exit (STS$K_ERROR | STS$M_INHIB_MSG);
      }
   }

   if (CgiLibVarNull ("WWW_FORM_LMBFILTER"))
   {
      /* applying the before filter */
      cptr = CgiLibVar ("WWW_FORM_LMBDD");
      dd = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_LMBMMM");
      mmm = atoi(cptr);
      if (mmm < 1 || mmm > 12) mmm = 0;
      cptr = CgiLibVar ("WWW_FORM_LMBYYYY");
      yyyy = atoi(cptr);

      DateTimeDsc.dsc$w_length = sizeof(DateTime)-1;
      sys$fao (&DateTimeFaoDsc, &slen, &DateTimeDsc,
               dd, MonthName[mmm], yyyy, 23, 59, 59, 99);
      DateTimeDsc.dsc$w_length = slen;
      DateTime[slen] = '\0';

      status = sys$bintim (&DateTimeDsc, &LmBeforeBinTime);
      if (VMSnok (status))
      {
         CgiLibResponseError (FI_LI, status,
                              "date/time before filter ... %s", DateTime);
         exit (STS$K_ERROR | STS$M_INHIB_MSG);
      }
   }

   if (!LmSinceBinTime[0] && !LmBeforeBinTime[0]) return;

   if (LmSinceBinTime[0])
      sys$fao (&DateTime20FaoDsc, NULL, &LmSinceStringDsc,
               &LmSinceBinTime);
   else
   {
      /* create a time far enough in the past */
      status = sys$bintim (&FarEnoughBackDsc, &LmSinceBinTime);
      if (VMSnok (status)) exit (status);
   }

   if (LmBeforeBinTime[0])
      sys$fao (&DateTime20FaoDsc, NULL, &LmBeforeStringDsc,
               &LmBeforeBinTime);
   else
   {
      /* create a time far enough in the future */
      status = sys$bintim (&FarEnoughForwardDsc, &LmBeforeBinTime);
      if (VMSnok (status)) exit (status);
   }

   /* sanity check on the filter window */
   status = lib$sub_times (&LmBeforeBinTime, &LmSinceBinTime,
                           &ResultBinTime);
   if (Debug) fprintf (stdout, "lib$sub_times() %%X%08.08X\n", status);
   if (status == LIB$_NEGTIM)
   {
      CgiLibResponseError (FI_LI, 0,
                           "Impossible to select since %s and before %s",
                           LmSinceString, LmBeforeString);
      exit (STS$K_ERROR | STS$M_INHIB_MSG);
   }
}

/****************************************************************************/
/*
Generate HTML form selectors for the since and before date/time filters.
Default it to cover the time period midnight to midnight of the current day.
*/ 

void DateTimeSelector ()

{
   static char  *MonthName[] =
      { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
   int  cnt;

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

   if (Debug) fprintf (stdout, "DateTimeSelector()\n");

   fprintf (stdout,
"<tr><th align=\"right\">Date/Time&nbsp;Since:&nbsp;</th><td>\n\
<select name=\"dtsdd\">\n");
   for (cnt = 1; cnt <= 31; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%02d\n",
               cnt, cnt == NumTime[2] ? " selected" : "", cnt);
   fprintf (stdout, "</select>\n<select name=\"dtsmmm\">\n");
   for (cnt = 1; cnt <= 12; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%s\n",
               cnt, cnt == NumTime[1] ? " selected" : "", MonthName[cnt]);
   fprintf (stdout, "</select>\n<select name=\"dtsyyyy\">\n");
   for (cnt = NumTime[0]-10; cnt <= NumTime[0]+1; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%04d\n",
               cnt, cnt == NumTime[0] ? " selected" : "", cnt);
   fprintf (stdout, "</select>\n<select name=\"dtshh\">\n");
   for (cnt = 0; cnt <= 23; cnt++)
      fprintf (stdout, "<option value=\"%d\">%02d\n", cnt, cnt);
   fprintf (stdout, "</select>\n<select name=\"dtsmm\">\n");
   for (cnt = 0; cnt <= 59; cnt++)
      fprintf (stdout, "<option value=\"%d\">%02d\n", cnt, cnt);
   fprintf (stdout,
"</select>\n\
&nbsp;<input type=\"checkbox\" name=\"dtsfilter\" value=\"1\">\
&nbsp;<span class=\"fnt080\"><i>apply&nbsp;since&nbsp;filter</i></span>\n\
</td></tr>\n");

   fprintf (stdout,
"<tr><th align=\"right\">Before:&nbsp;</th><td>\n\
<select name=\"dtbdd\">\n");
   for (cnt = 1; cnt <= 31; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%02d\n",
               cnt, cnt == NumTime[2] ? " selected" : "", cnt);
   fprintf (stdout, "</select>\n<select name=\"dtbmmm\">\n");
   for (cnt = 1; cnt <= 12; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%s\n",
               cnt, cnt == NumTime[1] ? " selected" : "", MonthName[cnt]);
   fprintf (stdout, "</select>\n<select name=\"dtbyyyy\">\n");
   for (cnt = NumTime[0]-10; cnt <= NumTime[0]+1; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%04d\n",
               cnt, cnt == NumTime[0] ? " selected" : "", cnt);
   fprintf (stdout, "</select>\n<select name=\"dtbhh\">\n");
   for (cnt = 0; cnt <= 23; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%02d\n",
               cnt, cnt == 23 ? " selected" : "", cnt);
   fprintf (stdout, "</select>\n<select name=\"dtbmm\">\n");
   for (cnt = 0; cnt <= 59; cnt++)
      fprintf (stdout, "<option value=\"%d\"%s>%02d\n",
               cnt, cnt == 59 ? " selected" : "", cnt);
   fprintf (stdout,
"</select>\n\
&nbsp;<input type=\"checkbox\" name=\"dtbfilter\" value=\"1\">\
&nbsp;<span class=\"fnt080\"><i>apply&nbsp;before&nbsp;filter</i></span>\n\
</td></tr>\n");
}

/****************************************************************************/
/*
Get the since and before filter form fields and convert these to binary
date/times.  If an error with the time report and exit script.
*/ 

void DateTimeCgi ()

{
   static char  *MonthName[] =
      { "***", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
               "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };

   static $DESCRIPTOR (DateTimeFaoDsc, "!2ZL-!3AZ-!4ZL !2ZL:!2ZL:!2ZL");

   int  dd, mmm, yyyy, hh, mm, status;
   unsigned short  slen;
   unsigned long  ResultBinTime [2];
   char  *cptr;
   char  DateTime [32];
   $DESCRIPTOR (DateTimeDsc, DateTime);

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

   if (Debug) fprintf (stdout, "DateTimeCgi()\n");

   if (CgiLibVarNull ("WWW_FORM_DTSFILTER"))
   {
      /* applying the since filter */
      cptr = CgiLibVar ("WWW_FORM_DTSDD");
      dd = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_DTSMMM");
      mmm = atoi(cptr);
      if (mmm < 1 || mmm > 12) mmm = 0;
      cptr = CgiLibVar ("WWW_FORM_DTSYYYY");
      yyyy = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_DTSHH");
      hh = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_DTSMM");
      mm = atoi(cptr);

      sys$fao (&DateTimeFaoDsc, &slen, &DateTimeDsc,
               dd, MonthName[mmm], yyyy, hh, mm, 0);
      DateTimeDsc.dsc$w_length = slen;
      DateTime[slen] = '\0';

      status = sys$bintim (&DateTimeDsc, &DtSinceFilterBinTime);
      if (VMSnok (status))
      {
         CgiLibResponseError (FI_LI, status,
                              "date/time since filter ... %s", DateTime);
         exit (STS$K_ERROR | STS$M_INHIB_MSG);
      }
   }

   if (CgiLibVarNull ("WWW_FORM_DTBFILTER"))
   {
      /* applying the before filter */
      cptr = CgiLibVar ("WWW_FORM_DTBDD");
      dd = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_DTBMMM");
      mmm = atoi(cptr);
      if (mmm < 1 || mmm > 12) mmm = 0;
      cptr = CgiLibVar ("WWW_FORM_DTBYYYY");
      yyyy = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_DTBHH");
      hh = atoi(cptr);
      cptr = CgiLibVar ("WWW_FORM_DTBMM");
      mm = atoi(cptr);

      DateTimeDsc.dsc$w_length = sizeof(DateTime)-1;
      sys$fao (&DateTimeFaoDsc, &slen, &DateTimeDsc,
               dd, MonthName[mmm], yyyy, hh, mm, 0);
      DateTimeDsc.dsc$w_length = slen;
      DateTime[slen] = '\0';

      status = sys$bintim (&DateTimeDsc, &DtBeforeFilterBinTime);
      if (VMSnok (status))
      {
         CgiLibResponseError (FI_LI, status,
                              "date/time before filter ... %s", DateTime);
         exit (STS$K_ERROR | STS$M_INHIB_MSG);
      }
   }

   if (!DtSinceFilterBinTime[0] && !DtBeforeFilterBinTime[0]) return;

   if (DtSinceFilterBinTime[0])
      sys$fao (&DateTime20FaoDsc, NULL, &DtSinceFilterStringDsc,
               &DtSinceFilterBinTime);
   else
   {
      /* create a time far enough in the past */
      status = sys$bintim (&FarEnoughBackDsc, &DtSinceFilterBinTime);
      if (VMSnok (status)) exit (status);
   }

   if (DtBeforeFilterBinTime[0])
      sys$fao (&DateTime20FaoDsc, NULL, &DtBeforeFilterStringDsc,
               &DtBeforeFilterBinTime);
   else
   {
      /* create a time far enough in the future */
      status = sys$bintim (&FarEnoughForwardDsc, &DtBeforeFilterBinTime);
      if (VMSnok (status)) exit (status);
   }

   /* sanity check on the filter window */
   status = lib$sub_times (&DtBeforeFilterBinTime, &DtSinceFilterBinTime,
                           &ResultBinTime);
   if (Debug) fprintf (stdout, "lib$sub_times() %%X%08.08X\n", status);
   if (status == LIB$_NEGTIM)
   {
      CgiLibResponseError (FI_LI, 0,
                           "Impossible to filter since %s and before %s",
                           DtSinceFilterString, DtBeforeFilterString);
      exit (STS$K_ERROR | STS$M_INHIB_MSG);
   }
}

/****************************************************************************/
/*
Passed a string containing the date/time field from the log record, convert it
to a binary time and then compare to the since/before binary date/times, to
filter on the date/time.  Returns true if outside the time period specified.
*/ 

BOOL FilterBinDateTime (char *DateTimePtr)

{
   static char  DateTime [21];
   static $DESCRIPTOR (DateTimeDsc, DateTime);

   int  status;
   char  *cptr, *sptr, *zptr;
   unsigned long  DateTimeBinTime [2],
                  ResultBinTime [2];

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

   if (Debug) fprintf (stdout, "FilterBinDateTime()\n");

   /* get the first 20 characters of the date/time field */
   zptr = (sptr = DateTime) + sizeof(DateTime)-1;
   for (cptr = DateTimePtr; *cptr && sptr < zptr; *sptr++ = *cptr++);
   *sptr = '\0';
   /* make it look VMS-ish */
   if (DateTime[2] != '/') return (false);
   DateTime[2] = '-';
   if (DateTime[6] != '/') return (false);
   DateTime[6] = '-';
   if (DateTime[11] != ':') return (false);
   DateTime[11] = ' ';

   status = sys$bintim (&DateTimeDsc, &DateTimeBinTime);
   if (VMSnok (status))
   {
      if (Debug)
         fprintf (stdout, "sys$bintim() %%X%08.08X |%s|\n", status, DateTime);
      DateTimeProblemCount++;
      return (true);
   }

   /* if the since is larger (later) than the date/time then return false */
   status = lib$sub_times (&DateTimeBinTime, &DtSinceFilterBinTime,
                           &ResultBinTime);
   if (Debug) fprintf (stdout, "lib$sub_times() %%X%08.08X\n", status);
   if (status == LIB$_NEGTIM)
   {
      DtSinceFilterRejectCount++;
      return (true);
   }

   /* if the date/time is larger (later) than the before then return false */
   status = lib$sub_times (&DtBeforeFilterBinTime, &DateTimeBinTime,
                           &ResultBinTime);
   if (Debug) fprintf (stdout, "lib$sub_times() %%X%08.08X\n", status);
   if (status == LIB$_NEGTIM)
   {
      DtBeforeFilterRejectCount++;
      return (true);
   }

   DtSinceFilterAcceptCount++;
   DtBeforeFilterAcceptCount++;
   return (false);
}

/****************************************************************************/
/*
Turn the supplied string, for example "dd/aug/2002:dd:hh:mm +hhmm", into a
wilcarded date/time filter, such as "@@/aug/2002" and return a pointer to that
(sometimes modified) string.  If the string has not been changed from the
default value of "dd/mmm/yyyy:hh:mm:ss" then return NULL.
*/ 

char* DateTimeFilter (char *String)

{
   char  *cptr;

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

   if (Debug) fprintf (stdout, "DateTimeFilter() |%s|\n", String);

   if (!String) return (NULL);
   if (strsame (String, "dd/mmm/yyyy:hh:mm:ss", 20)) return (NULL);

   cptr = String;
   if (*cptr == 'd') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'd') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr != '/') return (String);
   if (*cptr) cptr++;

   if (*cptr == 'm') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'm') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'm') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr != '/') return (String);
   if (*cptr) cptr++;

   if (*cptr == 'y') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'y') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'y') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'y') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr != ':') return (String);
   if (*cptr) cptr++;

   if (*cptr == 'h') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'h') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr != ':') return (String);
   if (*cptr) cptr++;

   if (*cptr == 'm') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'm') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr != ':') return (String);
   if (*cptr) cptr++;

   if (*cptr == 's') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 's') *cptr = '*';
   if (*cptr) cptr++;
   if (!isspace(*cptr)) return (String);
   if (*cptr) cptr++;

   if (*cptr != '+' && *cptr != '-' && *(unsigned char*)cptr != 177)
      return (String);
   *cptr++ = '*';
   if (*cptr == 'h') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'h') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'm') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr == 'm') *cptr = '*';
   if (*cptr) cptr++;
   if (*cptr) return (String);

   if (cptr > String && !*cptr) cptr--;
   while (cptr > String && !isalnum(*cptr)) cptr--;
   while (*cptr && *cptr != '*') cptr++;
   if (*cptr == '*') cptr++;
   *cptr = '\0';

   return (String);
}

/****************************************************************************/
/*
Search against the command line file specification, passing each file found to
be processed.
*/ 

int SearchFileSpec (char *FileSpec)

{
   int  idx, status,
        FileNameLength,
        Length;
   char  FileName [256],
         ExpFileName [256];
   struct FAB  SearchFab;
   struct NAM  SearchNam;

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

   if (Debug)
      fprintf (stdout, "SearchFileSpec() |%s|%s|\n", SearchDna, FileSpec);

   /* initialize the file access block */
   SearchFab = cc$rms_fab;
   SearchFab.fab$l_dna = SearchDna;
   SearchFab.fab$b_dns = strlen(SearchDna);
   SearchFab.fab$l_fna = FileSpec;
   SearchFab.fab$b_fns = strlen(FileSpec);
   SearchFab.fab$l_nam = &SearchNam;

   SearchNam = cc$rms_nam;
   SearchNam.nam$l_esa = ExpFileName;
   SearchNam.nam$b_ess = sizeof(ExpFileName)-1;
   SearchNam.nam$l_rsa = FileName;
   SearchNam.nam$b_rss = sizeof(FileName)-1;

   if (VMSnok (status = sys$parse (&SearchFab, 0, 0))) return (status);

   while (VMSok (status = sys$search (&SearchFab, 0, 0)))
   {
      *SearchNam.nam$l_ver = '\0';
      if (Debug) fprintf (stdout, "FileName |%s|\n", FileName);

      ProcessLogFile (FileName);

      FileCountTotal++;
      *SearchNam.nam$l_ver = ';';
   }

   if (RequestCountTotal)
   {
      for (idx = 0; idx <= 5; idx++)
         StatusCodePercent[idx] = lround ((float)StatusCodeCount[idx] * 100.0 /
                                          (float)RequestCountTotal);
      MethodConnectPercent = lround ((float)MethodConnectCount * 100.0 /
                                     (float)RequestCountTotal);
      MethodCopyPercent = lround ((float)MethodCopyCount * 100.0 /
                                  (float)RequestCountTotal);
      MethodDeletePercent = lround ((float)MethodDeleteCount * 100.0 /
                                    (float)RequestCountTotal);
      MethodGetPercent = lround ((float)MethodGetCount * 100.0 /
                                 (float)RequestCountTotal);
      MethodHeadPercent = lround ((float)MethodHeadCount * 100.0 /
                                  (float)RequestCountTotal);
      MethodLockPercent = lround ((float)MethodLockCount * 100.0 /
                                  (float)RequestCountTotal);
      MethodMkColPercent = lround ((float)MethodMkColCount * 100.0 /
                                   (float)RequestCountTotal);
      MethodMovePercent = lround ((float)MethodMoveCount * 100.0 /
                                  (float)RequestCountTotal);
      MethodOptionsPercent = lround ((float)MethodOptionsCount * 100.0 /
                                     (float)RequestCountTotal);
      MethodPropFindPercent = lround ((float)MethodPropFindCount * 100.0 /
                                      (float)RequestCountTotal);
      MethodPropPatchPercent = lround ((float)MethodPropPatchCount * 100.0 /
                                       (float)RequestCountTotal);
      MethodPostPercent = lround ((float)MethodPostCount * 100.0 /
                                  (float)RequestCountTotal);
      MethodPutPercent = lround ((float)MethodPutCount * 100.0 /
                                 (float)RequestCountTotal);
      MethodTracePercent = lround ((float)MethodTraceCount * 100.0 /
                                   (float)RequestCountTotal);
      MethodUnLockPercent = lround ((float)MethodUnLockCount * 100.0 /
                                    (float)RequestCountTotal);
      MethodUnknownPercent = lround ((float)MethodUnknownCount * 100.0 /
                                     (float)RequestCountTotal);
   }

   return (status);
}

/****************************************************************************/
/*
Open the log file, read and process each record from it, close the file!
*/ 

int ProcessLogFile (char *FileName)

{
   BOOL  accepted,
         ShowLog;
   int  status,
        CtimeBefore,
        CtimeSince;
   char  *cptr;
   char  HtmlLine [MAX_LINE_LENGTH+(MAX_LINE_LENGTH/4)],
         Line [MAX_LINE_LENGTH],
         LineBuffer [MAX_LINE_LENGTH];
   FILE  *FilePtr;
   stat_t  statBuffer;

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

   if (Debug) fprintf (stdout, "ProcessLogFile() |%s|\n", FileName);

   if (LmSinceBinTime[0] || LmSinceBinTime[1])
      CtimeSince = decc$fix_time (&LmSinceBinTime);
   else
      CtimeSince = 0;

   if (LmBeforeBinTime[0] || LmBeforeBinTime[1])
      CtimeBefore = decc$fix_time (&LmBeforeBinTime);
   else
      CtimeBefore = 0;

   if (status = stat (FileName, &statBuffer) < 0)
   {
      if (Debug) fprintf (stdout, "stat() %d %%X%08.08X\n", status, vaxc$errno);
      AccessProblemCount++;
      status = vaxc$errno;
      return (status);
   }
   if (CtimeBefore && statBuffer.st_mtime > CtimeBefore)
   {
      LastModifiedIgnoredCount++;
      return (SS$_NORMAL);
   }
   if (CtimeSince && statBuffer.st_mtime < CtimeSince)
   {
      LastModifiedIgnoredCount++;
      return (SS$_NORMAL);
   }

   if (ShowProgress && !ViewRecords)
   {
      /* this works for both CLI and CGI (inside "<!-- -->"!) */
      if (ProgressCount == ProgressWrap)
      {
         ProgressCount = 0;
         fputc ('\n', stdout);
      }
      ProgressCount++;
      fputc ('+', stdout);
      fflush (stdout);
   }

   if (ShowLogFile)
      ShowLog = true;
   else
      ShowLog = false;

   RecordCount = 0;

   FilePtr = fopen (FileName, "r", "shr=get", "shr=put");
   if (!FilePtr)
   {
      status = vaxc$errno;
      if (Debug) fprintf (stdout, "fopen() %%X%08.08X\n", status);
      AccessProblemCount++;
      return (status);
   }

   while (fgets (Line, sizeof(Line), FilePtr))
   {
      RecordCount++;
      RecordCountTotal++;

      if (ViewRecords == VIEW_NONE)
      {
         /* again this works for both CLI and CGI (inside "<!-- -->"!) */
         if (ShowProgress && !(RecordCount % ShowProgress))
         {
            if (ProgressCount == ProgressWrap)
            {
               ProgressCount = 0;
               fputc ('\n', stdout);
            }
            ProgressCount++;
            fputc ('.', stdout);
            fflush (stdout);
         }
      }
      else
      if (ViewRecords == VIEW_ALL)
      {
         if (DoCliStats)
            OutputLogRecord (Line);
         else
         {
            CgiLibHtmlEscape (Line, -1, HtmlLine, sizeof(HtmlLine));
            OutputLogRecord (HtmlLine);
         }
      }
      else
         strcpy (LineBuffer, Line);

      if (ViewRecords == VIEW_LOG)
      {
         if (ShowLog)
         {   
            for (cptr = FileName; *cptr; cptr++);
            while (cptr > FileName && *cptr != ']' && *cptr != ':') cptr--;
            if (*cptr == ']' || *cptr == ':') cptr++;
            fprintf (stdout, "%s\n", cptr);
            ShowLog = false;
         }
      }

      if (Debug) fprintf (stdout, "|%s|\n", Line);
      accepted = ProcessLogRecord (Line);

      if ((ViewRecords == VIEW_MATCH && accepted) ||
          (ViewRecords == VIEW_NOMATCH && !accepted) ||
          (ViewRecords == VIEW_SUSPECT && accepted) ||
          (ViewRecords == VIEW_UNIQUE && accepted))
      {
         if (ShowLog)
         {   
            for (cptr = FileName; *cptr; cptr++);
            while (cptr > FileName && *cptr != ']' && *cptr != ':') cptr--;
            if (*cptr == ']' || *cptr == ':') cptr++;
            fprintf (stdout, "%s\n", cptr);
            ShowLog = false;
         }
         if (DoCliStats)
            OutputLogRecord (LineBuffer);
         else
         {
            CgiLibHtmlEscape (LineBuffer, -1, HtmlLine, sizeof(HtmlLine));
            OutputLogRecord (HtmlLine);
            fflush (stdout);
         }
      }
   }

   fclose (FilePtr);

   return (SS$_NORMAL);
}

/*****************************************************************************/
/*
Output a single record from the log.  If client host name lookup is enabled
then check whether the client field is a dotted-decimal host address.  If it is
then lookup the host name and output that instead of the address.
*/

void OutputLogRecord (char *rptr)

{
   static int  LineCount;

   char  *cptr, *sptr, *zptr;
   char  client [256];

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

   if (Debug) fprintf (stdout, "OutputLogRecord()\n");

   if (!DoCliStats && (LineCount & 1))
      fputs ("<span class=\"alt1\">", stdout);

   zptr = (sptr = client) + sizeof(client)-1;
   while (*rptr && *rptr != ' ' && sptr < zptr) *sptr++ = *rptr++;
   *sptr = '\0';
   while (*rptr && *rptr != ' ') rptr++;
   if (!DoCliStats && (LineCount & 1))
   {
      for (sptr = rptr; *sptr && *sptr != '\n'; sptr++);
      *sptr = '\0';
   }

   fputs (client, stdout);

   if (Addr2Name)
   {
      if (TcpIpIsAddress (client))
         sptr = TcpIpLookup (NULL, client, NULL, NULL);
      else
         sptr = TcpIpLookup (client, NULL, NULL, NULL);
      if (DoCliStats)
         fprintf (stdout, " (%s)", sptr);
      else
         fprintf (stdout, " <span class=\"attn\">(%s)</span>", sptr);
   }

   if (GeoLocatePtr)
   {
      if (!TcpIpIsAddress (sptr = client))
         sptr = TcpIpLookup (client, NULL, NULL, NULL);
      if (TcpIpIsAddress (sptr))
      {
         GeoLocateId++;
         fprintf (stdout,
" <span class=\"attn\" id=\"geo%d\"></span>\
<script>geoLocate(\'geo%d\',\'%s\')</script>",
                  GeoLocateId, GeoLocateId, sptr);
      }
      else
         fprintf (stdout, " <span class=\"attn\">(%s)</span>", sptr);
   }

   /* output the rest of the log record */
   fputs (rptr, stdout);

   if (!DoCliStats && (LineCount++ & 1))
      fputs ("</span>\n", stdout);
}

/*****************************************************************************/
/*
Process a single record (line) from the log file.
Common: 'client rfc891 authuser date/time request status bytes'
Combined: 'client rfc891 authuser date/time request status bytes referer agent'
*/

BOOL ProcessLogRecord (char *Line)

{
   BOOL  RejectRecord;
   int  ByteCount;
   uchar  Ip4Addr [4],
          Ip6Addr [16];
   char  *cptr, *sptr,
         *AuthUserPtr,
         *ClientPtr,
         *BytesPtr,
         *DateTimePtr,
         *QueryStringPtr,
         *ProtocolPtr,
         *RefererPtr,
         *RemoteIdentPtr,
         *RequestPtr,
         *StatusPtr,
         *UserAgentPtr;
   char  ch;
   char  EmptyString [1],
         Scratch [MAX_LINE_LENGTH];

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

   if (Debug) fprintf (stdout, "ProcessLogRecord()\n");

   EmptyString[0] = '\0';

   cptr = Line;

   /* client */
   ClientPtr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';

   /* remote ident (RFC891) */
   while (*cptr && isspace(*cptr)) cptr++;
   RemoteIdentPtr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';

   /* authorized user */
   while (*cptr && isspace(*cptr)) cptr++;
   AuthUserPtr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';

   /* date/time */
   while (*cptr && *cptr != '[') cptr++;
   if (*cptr) cptr++;
   DateTimePtr = cptr;
   while (*cptr && *cptr != ']') cptr++;
   if (*cptr) *cptr++ = '\0';

   /* request ("method path?query protocol") */
   while (*cptr && *cptr != '\"') cptr++;
   if (*cptr) cptr++;
   RequestPtr = cptr;
   while (*cptr && *cptr != '\"') cptr++;
   if (*cptr) *cptr++ = '\0';

   /* HTTP response status */
   while (*cptr && isspace(*cptr)) cptr++;
   StatusPtr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';

   /* bytes transmitted */
   while (*cptr && isspace(*cptr)) cptr++;
   BytesPtr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';

   /* referer (only for COMBINED) */
   RefererPtr = NULL;
   while (*cptr && isspace(*cptr)) cptr++;
   if (*cptr == '\"')
   {
      cptr++;
      RefererPtr = cptr;
      while (*cptr && *cptr != '\"') cptr++;
   }
   else
   if (*cptr)
   {
      RefererPtr = cptr;
      while (*cptr && !isspace(*cptr)) cptr++;
   }
   if (*cptr) *cptr++ = '\0';

   /* user agent (only for COMBINED) */
   UserAgentPtr = NULL;
   while (*cptr && isspace(*cptr)) cptr++;
   if (*cptr == '\"')
   {
      cptr++;
      UserAgentPtr = cptr;
      while (*cptr && *cptr != '\"') cptr++;
   }
   else
   if (*cptr)
   {
      UserAgentPtr = cptr;
      while (*cptr && !isspace(*cptr)) cptr++;
   }
   if (*cptr) *cptr++ = '\0';

   if (!ClientPtr[0] ||
       !DateTimePtr[0] ||
       !RequestPtr[0] ||
       !StatusPtr[0] ||
       !BytesPtr)
   {
      SuspectRecordCountTotal++;
      if (ViewRecords != VIEW_SUSPECT) return (false);
   }
   else
   if (ViewRecords == VIEW_SUSPECT)
      return (false);

   if (!RefererPtr && !UserAgentPtr)
      CommonLogRecordCount++;
   else
      CombinedLogRecordCount++;

   /* reset the pattern counter */
   FilterThisOut (NULL, NULL);

   RejectRecord = false;

   if (ClientFilterPtr)
   {
      if (LookupRetry)
      {
         cptr = TcpIpLookup (ClientPtr, NULL, NULL, NULL);
         if (cptr) ClientPtr = cptr;
      }
      if (FilterThisOut (ClientPtr, ClientFilterPtr))
      {
         ClientFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         ClientFilterAcceptCount++;
   }
   if (IpVersionFilter)
   {
      /* check if it looks like an IPv4 address */
      for (cptr = ClientPtr; isdigit(*cptr) || *cptr == '.'; cptr++);
      if (!*cptr)
      {
         /* looks like IPv4 */
         if (IpVersionFilter == 4)
            Ip4FilterAcceptCount++;
         else
         {
            Ip4FilterRejectCount++;
            if (!FilterOnAll) return (false);
            RejectRecord = true;
         }
      }
      else
      {
         /* check if it looks like an IPv6 address */
         cptr = ClientPtr;
         if (*(unsigned long*)cptr == '::FF' && !memcmp (cptr, "::FFFF:", 7))
            cptr = "";
         else
         if (*(unsigned long*)cptr == '::ff' && !memcmp (cptr, "::ffff:", 7))
            cptr = "";
         else
            while (isxdigit(*cptr) || *cptr == ':' || *cptr == '-') cptr++;

         if (!*cptr)
         {
            /* looks like IPv6 */
            if (IpVersionFilter == 6)
               Ip6FilterAcceptCount++;
            else
            {
               Ip6FilterRejectCount++;
               if (!FilterOnAll) return (false);
               RejectRecord = true;
            }
         }
         else
         {
            /* assume it's a host name */
            cptr = TcpIpLookup (ClientPtr, NULL, Ip4Addr, Ip6Addr);
            if (IpVersionFilter == 4)
            {
               if (cptr)
               {
                  if (MATCH4 (Ip4Addr, Ip4AddrZero))
                     Ip4FilterAcceptCount++;
                  else
                  {
                     Ip4FilterRejectCount++;
                     if (!FilterOnAll) return (false);
                     RejectRecord = true;
                  }
               }
               else
               {
                  Ip4FilterRejectCount++;
                  if (!FilterOnAll) return (false);
                  RejectRecord = true;
               }
            }
            else
            if (IpVersionFilter == 6)
            {
               if (cptr)
               {
                  if (MATCH0 (Ip6Addr, Ip6AddrZero, 16))
                  {
                     Ip6FilterRejectCount++;
                     if (!FilterOnAll) return (false);
                     RejectRecord = true;
                  }
                  else
                     Ip6FilterAcceptCount++;
               }
               else
               {
                  Ip6FilterRejectCount++;
                  if (!FilterOnAll) return (false);
                  RejectRecord = true;
               }
            }
         }
      }
   }
   if (RemoteIdentFilterPtr)
   {
      if (FilterThisOut (RemoteIdentPtr, RemoteIdentFilterPtr))
      {
         RemoteIdentFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         RemoteIdentFilterAcceptCount++;
   }
   if (AuthUserFilterPtr)
   {
      if (FilterThisOut (AuthUserPtr, AuthUserFilterPtr))
      {
         AuthUserFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         AuthUserFilterAcceptCount++;
   }

   if (DtBeforeFilterBinTime[0] || DtSinceFilterBinTime[0])
   {
      if (FilterBinDateTime (DateTimePtr))
      {
         DateTimeFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         DateTimeFilterAcceptCount++;
   }
   else
   if (DateTimeFilterPtr)
   {
      /* binary time takes precedence over this pattern matching */
      if (FilterThisOut (DateTimePtr, DateTimeFilterPtr))
      {
         DateTimeFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         DateTimeFilterAcceptCount++;
   }

   if (MethodFilterPtr)
   {
      for (cptr = RequestPtr; *cptr && *cptr != ' '; cptr++);
      /* terminate path at query string (should be necessary) */
      if (!*cptr) cptr = NULL;
      if (cptr) *cptr = '\0';
      if (*MethodFilterPtr == '?')
      {
         if (MATCH4 (RequestPtr, "GET") ||
             MATCH5 (RequestPtr, "HEAD") ||
             MATCH5 (RequestPtr, "POST") ||
             /* now the less frequently occuring methods */
             MATCH8 (RequestPtr, "CONNECT") ||
             MATCH5 (RequestPtr, "COPY") ||
             MATCH7 (RequestPtr, "DELETE") ||
             MATCH5 (RequestPtr, "LOCK") ||
             MATCH6 (RequestPtr, "MKCOL") ||
             MATCH5 (RequestPtr, "MOVE") ||
             MATCH8 (RequestPtr, "OPTIONS") ||
             MATCH8 (RequestPtr, "PROPFIND") ||
             MATCH8 (RequestPtr, "PROPATCH") ||
             MATCH4 (RequestPtr, "PUT") ||
             MATCH6 (RequestPtr, "TRACE") ||
             MATCH7 (RequestPtr, "UNLOCK"))
         {
            MethodFilterRejectCount++;
            RejectRecord = true;
         }
         else
            MethodFilterAcceptCount++;
      }
      else
      if (*MethodFilterPtr == '(')
      {
         /* WebDAV-specific methods */
         if (MATCH5 (RequestPtr, "COPY") ||
             MATCH7 (RequestPtr, "DELETE") ||
             MATCH5 (RequestPtr, "LOCK") ||
             MATCH6 (RequestPtr, "MKCOL") ||
             MATCH5 (RequestPtr, "MOVE") ||
             MATCH8 (RequestPtr, "PROPFIND") ||
             MATCH8 (RequestPtr, "PROPATCH") ||
             MATCH7 (RequestPtr, "UNLOCK"))
            MethodFilterAcceptCount++;
         else
         {
            MethodFilterRejectCount++;
            RejectRecord = true;
         }
      }
      else
      {
         if (FilterThisOut (RequestPtr, MethodFilterPtr))
         {
            MethodFilterRejectCount++;
            if (!FilterOnAll) return (false);
            RejectRecord = true;
         }
         else
            MethodFilterAcceptCount++;
      }
      if (cptr) *cptr = ' ';
   }
   QueryStringPtr = ProtocolPtr = NULL;
   if (NoWasdEntries)
   {
      /* include the server method (POST) */
      cptr = RequestPtr;
      while (*cptr && *cptr != ' ') cptr++;
      while (*cptr && *cptr == ' ') cptr++;
      /* find the start of any query string */
      for (sptr = cptr; *sptr && *sptr != '?' && *sptr != ' '; sptr++);
      /* terminate path at query string */
      ch = *sptr;
      *sptr = '\0';
      /*
         If it matches something like:
         "POST /KLAATU::WASD:80-BEGIN-00000000"
         "POST /KLAATU::WASD:80-TIMESTAMP-00000001"
         "POST /KLAATU::WASD:80-END-00000002"
      */
      if (!FilterThisOut (RequestPtr, "POST /*::WASD:*-*-*") ||
          !FilterThisOut (RequestPtr, "POST /*::WASD%:*-*-*") ||
          !FilterThisOut (RequestPtr, "POST /*::HTTP%:*-*-*"))
         RejectRecord = true;
      *sptr = ch;
   }
   if (PathFilterPtr)
   {
      /* skip over the method */
      for (cptr = RequestPtr; *cptr && *cptr != ' '; cptr++);
      while (*cptr && *cptr == ' ') cptr++;
      /* find the start of any query string */
      for (sptr = cptr; *sptr && *sptr != '?' && *sptr != ' '; sptr++);
      /* terminate path at query string */
      if (*sptr == '?')
         QueryStringPtr = sptr + 1;
      else
      {
         QueryStringPtr = EmptyString;
         if (*sptr == ' ') ProtocolPtr = sptr + 1;
      }
      ch = *sptr;
      *sptr = '\0';
      if (UrlDecodePath && *cptr)
      {
         strcpy (Scratch, cptr);
         cptr = Scratch;
         CgiLibUrlDecode (cptr);
      }
      if (FilterThisOut (cptr, PathFilterPtr))
      {
         PathFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         PathFilterAcceptCount++;
      *sptr = ch;
   }
   if (QueryFilterPtr)
   {
      if (QueryStringPtr)
         cptr = QueryStringPtr;
      else
      {
         /* find the start of any query string */
         for (cptr = RequestPtr; *cptr && *cptr != '?'; cptr++);
         if (*cptr) cptr++;
         QueryStringPtr = cptr;
      }
      for (sptr = cptr; *sptr && *sptr != ' '; sptr++);
      ch = *sptr;
      *sptr = '\0';
      if (UrlDecodeQuery && *cptr)
      {
         strcpy (Scratch, cptr);
         cptr = Scratch;
         CgiLibUrlDecode (cptr);
      }
      if (FilterThisOut (cptr, QueryFilterPtr))
      {
         QueryFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         QueryFilterAcceptCount++;
      *sptr = ch;
      if (*sptr == ' ')
         ProtocolPtr = sptr + 1;
      else
         ProtocolPtr = EmptyString;
   }
   if (ProtocolFilterPtr)
   {
      if (ProtocolPtr)
         cptr = ProtocolPtr;
      else
      {
         if (QueryStringPtr)
            cptr = QueryStringPtr;
         else
         {
            /* find the start of any query string */
            for (cptr = RequestPtr; *cptr && *cptr != ' '; cptr++);
            while (*cptr && *cptr == ' ') cptr++;
            while (*cptr && *cptr != ' ' && *cptr != '?') cptr++;
            if (*cptr == '?') cptr++;
         }
         /* find the end of the query string and the start of the protocol */
         while (*cptr && *cptr != ' ') cptr++;
      }
      if (*cptr == ' ') cptr++;
      if (FilterThisOut (cptr, ProtocolFilterPtr))
      {
         ProtocolFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         ProtocolFilterAcceptCount++;
   }
   if (RefererFilterPtr)
   {
      /* if the record did not have a COMBINED referer field then reject */
      if ((cptr = RefererPtr) && UrlDecodeReferer)
      {
         strcpy (Scratch, cptr);
         cptr = Scratch;
         CgiLibUrlDecode (cptr);
      }
      if (!cptr || FilterThisOut (cptr, RefererFilterPtr))
      {
         RefererFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         RefererFilterAcceptCount++;
   }
   if (ResponseFilterPtr)
   {
      if (!cptr || FilterThisOut (StatusPtr, ResponseFilterPtr))
      {
         StatusFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         StatusFilterAcceptCount++;
   }
   if (UserAgentFilterPtr)
   {
      /* if the record did not have a COMBINED user agent field then reject */
      if (!UserAgentPtr || FilterThisOut (UserAgentPtr, UserAgentFilterPtr))
      {
         UserAgentFilterRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         UserAgentFilterAcceptCount++;
   }

   ByteCount = atoi(BytesPtr);
   if (ResponseMinSize)
   {
      if (ByteCount < ResponseMinSize || !isdigit(*BytesPtr))
      {
         ResponseMinSizeRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         ResponseMinSizeAcceptCount++;
   }
   if (ResponseMaxSize)
   {
      if (ByteCount > ResponseMaxSize || !isdigit(*BytesPtr))
      {
         ResponseMaxSizeRejectCount++;
         if (!FilterOnAll) return (false);
         RejectRecord = true;
      }
      else
         ResponseMaxSizeAcceptCount++;
   }

   if (ViewRecords == VIEW_UNIQUE)
      RejectRecord = !UniqueClient (ClientPtr);

   if (RejectRecord) return (false);

   RequestCountTotal++;
   ByteCountTotal += (float)ByteCount;
   switch (StatusPtr[0])
   {
      case '1' : StatusCodeCount[1]++; break;
      case '2' : StatusCodeCount[2]++; break;
      case '3' : StatusCodeCount[3]++; break;
      case '4' : StatusCodeCount[4]++; break;
      case '5' : StatusCodeCount[5]++; break;
      default  : StatusCodeCount[0]++;
   }

   for (cptr = RequestPtr; *cptr && *cptr != ' '; cptr++);
   /* terminate path at query string (should be necessary) */
   if (!*cptr) cptr = NULL;
   if (cptr) *cptr = '\0';

   if (MATCH4 (RequestPtr, "GET"))
      MethodGetCount++;
   else
   if (MATCH5 (RequestPtr, "HEAD"))
      MethodHeadCount++;
   else
   if (MATCH5 (RequestPtr, "POST"))
      MethodPostCount++;
   else
   /* now the less frequently occuring methods */
   if (MATCH8 (RequestPtr, "CONNECT"))
      MethodConnectCount++;
   else
   if (MATCH5 (RequestPtr, "COPY"))
      MethodCopyCount++;
   else
   if (MATCH7 (RequestPtr, "DELETE"))
      MethodDeleteCount++;
   else
   if (MATCH5 (RequestPtr, "LOCK"))
      MethodLockCount++;
   else
   if (MATCH6 (RequestPtr, "MKCOL"))
      MethodMkColCount++;
   else
   if (MATCH5 (RequestPtr, "MOVE"))
      MethodMoveCount++;
   else
   if (MATCH8 (RequestPtr, "OPTIONS"))
      MethodOptionsCount++;
   else
   if (MATCH8 (RequestPtr, "PROPFIND"))
      MethodPropFindCount++;
   else
   if (MATCH8 (RequestPtr, "PROPPATCH"))
      MethodPropPatchCount++;
   else
   if (MATCH4 (RequestPtr, "PUT"))
      MethodPutCount++;
   else
   if (MATCH6 (RequestPtr, "TRACE"))
      MethodTraceCount++;
   else
   if (MATCH7 (RequestPtr, "UNLOCK"))
      MethodUnLockCount++;
   else
      MethodUnknownCount++;

   if (cptr) *cptr = ' ';

   return (true);
}


/*****************************************************************************/
/*
Pre-compile regular expressions.  Report the first error by return false. 
Return true if all required compile ok.
*/

BOOL CompileFilters ()

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

   if (Debug) fprintf (stdout, "CompileFilters()\n");

   FilterThisOut (NULL, NULL);
   if (ClientFilterPtr) FilterThisOut (NULL, ClientFilterPtr);
   if (RemoteIdentFilterPtr) FilterThisOut (NULL, RemoteIdentFilterPtr);
   if (AuthUserFilterPtr) FilterThisOut (NULL, AuthUserFilterPtr);
   if (!DtBeforeFilterBinTime[0] && !DtSinceFilterBinTime[0])
      if (DateTimeFilterPtr)
         FilterThisOut (NULL, DateTimeFilterPtr);
   if (MethodFilterPtr)
      if (*MethodFilterPtr != '?')
         FilterThisOut (NULL, MethodFilterPtr);
   if (PathFilterPtr) FilterThisOut (NULL, PathFilterPtr);
   if (QueryFilterPtr) FilterThisOut (NULL, QueryFilterPtr);
   if (ProtocolFilterPtr) FilterThisOut (NULL, ProtocolFilterPtr);
   if (RefererFilterPtr) FilterThisOut (NULL, RefererFilterPtr);
   if (ResponseFilterPtr) FilterThisOut (NULL, ResponseFilterPtr);
   if (UserAgentFilterPtr) FilterThisOut (NULL, UserAgentFilterPtr);
   if (RegCompPatternPtr) return (false);
   return (true);
}

/*****************************************************************************/
/*
Return false if the pattern matches the string, true if it doesn't.  Keep an
array of pre-compiled regular expressions.
*/

BOOL FilterThisOut
(
char *StringPtr,
char *PatternPtr
)
{
   static int  PatternCount;
   static regex_t  CompiledPattern[REGEX_PATTERN_MAX];

   BOOL  NegateResult;
   int  retval;
   char  *pptr, *sptr, *tptr, *zptr;
   char  Scratch [256];
   regex_t  *pregptr;

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

   if (Debug)
      fprintf (stdout, "FilterThisOut() |%s|%s|\n",
               StringPtr ? StringPtr : "", PatternPtr ? PatternPtr : "");

   if (!StringPtr && !PatternPtr)
   {
      /* reset the pattern count */
      PatternCount = 0;
      return (true);
   }

   if (PatternCount >= REGEX_PATTERN_MAX) exit (SS$_BUGCHECK);
   pregptr = &CompiledPattern[PatternCount++];

   if (*PatternPtr == '!')
   {
      PatternPtr++;
      /* if we're going to say *not* this, there must be *something* there */
      if (StringPtr && !*StringPtr) return (true);
      NegateResult = true;
   }
   else
      NegateResult = false;

   if (!pregptr->buffer)
   {
      /* check for simple wildcard match */
      if (*PatternPtr != REGEX_CHAR)
      {
         /* simple wildcard match, create regex equivalent */
         zptr = (sptr = Scratch) + sizeof(Scratch)-2;
         /* anchor the start */
         *sptr++ = '^';
         for (pptr = PatternPtr; *pptr && sptr < zptr; pptr++)
         {
            switch (*pptr)
            {
               case '*' :
                  /* match any zero or more characters */
                  *sptr++ = '.';
                  if (sptr < zptr) *sptr++ = *pptr;
                  break;
               case '%' :
                  /* match any single character */
                  *sptr++ = '.';
                  break;
               case '?' :
                  /* match zero or any single character */
                  *sptr++ = '.';
                  if (sptr < zptr) *sptr++ = *pptr;
                  break;
               case '\\' :
               case '^' :
               case '$' :
               case '.' :
               case '+' :
               case '|' :
               case '{' :
               case '[' :
               case '(' :
                  /* meta-character, quote the character */
                  *sptr++ = '\\';
                  if (sptr < zptr) *sptr++ = *pptr;
                  break;
               default :
                  *sptr++ = *pptr;
            }
         }
         /* anchor the end */
         *sptr++ = '$';
         *sptr = '\0';
         PatternPtr = Scratch;
         if (Debug) fprintf (stdout, "|%s|\n", PatternPtr);
      }
      else
         PatternPtr++;

      /* compile the pattern */
      retval = regcomp (pregptr, PatternPtr, REGEX_C_FLAGS);
      if (retval)
      {
         /* compilation error */
         if (!RegCompPatternPtr)
         {
            /* note the first regex compilation error details */
            RegCompPatternPtr = PatternPtr;
            regerror (retval, pregptr,
                      RegCompErrorString, sizeof(RegCompErrorString));
            if (Debug)
               fprintf (stdout, "|%s|%s|\n",
                        RegCompPatternPtr, RegCompErrorString);
            RegCompErrorString[0] = tolower(RegCompErrorString[0]);
         }
         return (true);
      }
      if (!StringPtr) return (true);
   }

   /*
      Start with a light-weight character match.
      Even if regex is eventually required this will eliminate many
      strings on simple character comparison before more heavy-weight
      pattern matching needs to be called into play.
   */
   sptr = StringPtr;
   pptr = PatternPtr;
   if (*pptr == '^')
   {
      /* must be a regex pattern */
      pptr++;
      /* step over any start-of-line anchor seeing we're there already */
      if (*pptr == '^')
      {
         pptr++;
         /* if regex for empty string, then it's a match */
         if (*(USHORTPTR)pptr == '$\0' && !*sptr)
            return (NegateResult ? true : false);
      }
   }
   while (*pptr && *sptr)
   {
      if (*(USHORTPTR)pptr == '*\0') break;
      switch (*pptr)
      {
         /* "significant" characters when pattern matching */
         case '*' :
         case '^' :
         case '$' :
         case '.' :
         case '+' :
         case '?' :
         case '|' :
         case '{' :
         case '[' :
         case '(' :
         case '\\' :
            /* meta-character, quit now and perform a regex match */
            retval = regexec (pregptr, StringPtr, 0, NULL, REGEX_E_FLAGS);
            if (retval) return (NegateResult ? false : true);
            return (NegateResult ? true : false);
      }
      if (tolower(*pptr) != tolower(*sptr) && *pptr != '%') break;
      pptr++;
      sptr++;
   }

   /* if matched exactly then don't filter it out */
   if (!*pptr && !*sptr) return (NegateResult ? true : false);

   /* if the pattern ended in a trailing wildcard it matches, don't filter */
   if (*(USHORTPTR)pptr == '*\0') return (NegateResult ? true : false);

   /* doesn't match! */
   return (NegateResult ? false : true);
}

/*****************************************************************************/
/*
Return true if the supplied client string has not been encountered before.
Maintain a simple linked list of each client as it is encountered.
*/

typedef struct ClientRecordStruct
{
   struct ClientRecordStruct *NextPtr;
   char  ClientString[];
} ClientRecord;

BOOL UniqueClient (char *ClientPtr)

{
   static struct ClientRecordStruct  *ClientList;

   struct ClientRecordStruct  *crptr;

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

   if (Debug) fprintf (stdout, "UniqueClient() |%s|\n", ClientPtr);

   for (crptr = ClientList; crptr != NULL; crptr = crptr->NextPtr)
   {
      if (!MATCH8 (ClientPtr, crptr->ClientString)) continue;
      if (!strcmp (ClientPtr, crptr->ClientString)) return (false);
   }

   crptr = calloc (1, sizeof(struct ClientRecordStruct) +
                      strlen(ClientPtr) + 1);
   if (!crptr) exit (vaxc$errno);
   strcpy (crptr->ClientString, ClientPtr);
   crptr->NextPtr = ClientList;
   ClientList = crptr;   

   return (true);
}

/*****************************************************************************/
/*
If |Name| is non-NULL lookup the IP address using the host name.
If |Address| is non-NULL lookup the host name using the address.
If the Ip4AddtrPtr and/or Ip6AddrPtr are non-NULL populate them.
Return either a pointer to the resolved host name or IP address string or an
error message between square brackets.
*/

char* TcpIpLookup
(
char *Name,
char *Address,
uchar *Ip4Addr,
uchar *Ip6Addr
)
{
#define CACHE_MAX 16

   static  aCacheIdx, nCacheIdx;
   static char  abuf [CACHE_MAX][256],
                ares [CACHE_MAX][256],
                nbuf [CACHE_MAX][256],
                nres [CACHE_MAX][256];

   int  idx, retry, retval;
   void  *addptr;
   struct sockaddr_in  addr4;
   struct sockaddr_in6  addr6;
   struct addrinfo  hints;
   struct addrinfo  *aiptr;

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

   if (Debug) fprintf (stdout, "TcpIpLookup() |%s|%s| %d %d\n",
                       Name, Address, Ip4Addr, Ip6Addr);

   if (Ip4Addr) memset (Ip4Addr, 0, 4);
   if (Ip6Addr) memset (Ip6Addr, 0, 16);

   if (Name)
   {
      for (idx = 0; idx < CACHE_MAX; idx++)
         if (!strcmp (nbuf[idx], Name))
            return (nres[idx]);
      idx = nCacheIdx++ % CACHE_MAX;
      strcpy (nbuf[idx], Name);

      aiptr = NULL;
      memset (&hints, 0, sizeof(hints));
      hints.ai_flags |= AI_CANONNAME;
      retval = 0;
      for (retry = TCPIP_LOOKUP_HOST_NAME_RETRY; retry; retry--)
      {
         retval = getaddrinfo (Name, NULL, &hints, &aiptr);
         if (retval != EINTR && retval != EAI_AGAIN) break;
         sleep (1);
      }
      if (retval)
      {
         if (retval == EAI_NONAME)
            sprintf (nres[idx], "[unknown]");
         else
         if (retval == EAI_FAIL || retval == EAI_AGAIN)
            sprintf (nres[idx], "[failed]");
         else
            sprintf (nres[idx], "[%s]", gai_strerror(retval));
         return (nres[idx]);
      }
      else
      {
         if (aiptr->ai_family == AF_INET)
         {
            /* IPv4 */
            addptr = &((struct sockaddr_in *)aiptr->ai_addr)->sin_addr;
            if (Ip4Addr) memcpy (Ip4Addr, addptr, 4);
         }
         else
         {
            /* must be IPv6 */
            addptr = &((struct sockaddr_in6 *)aiptr->ai_addr)->sin6_addr;
            if (Ip6Addr) memcpy (Ip6Addr, addptr, 16);
         }

         if (!inet_ntop (aiptr->ai_family, addptr, nres[idx], sizeof(nres[0])))
            sprintf (nres[idx], "[%s]", strerror(errno));
      }

      /* free the addrinfo */
      freeaddrinfo(aiptr);

      return (nres[idx]);
   }

   if (Address)
   {
      for (idx = 0; idx < CACHE_MAX; idx++)
         if (!strcmp (abuf[idx], Address))
            return (ares[idx]);
      idx = aCacheIdx++ % CACHE_MAX;
      strcpy (abuf[idx], Address);

      retval = 0;
      memset (&addr4, 0, sizeof(addr4));
      if (inet_pton (AF_INET, Address, &addr4.sin_addr) > 0)
      {
         /* MultiNet does not support BSD 4.4 AF_INET addresses */
#ifdef NO_SOCKADDR_LEN_4
         /* this kludge seems to work for both! */
         *(USHORTPTR)&addr4 = AF_INET;
#else
         addr4.sin_len = sizeof(struct sockaddr_in);
         addr4.sin_family = AF_INET;
#endif
         if (Ip4Addr)
            memcpy (Ip4Addr, &addr4.sin_addr, sizeof(addr4.sin_addr));
         for (retry = TCPIP_LOOKUP_HOST_NAME_RETRY; retry; retry--)
         {
            retval = getnameinfo ((struct sockaddr*)&addr4, sizeof(addr4),
                                  ares[idx], sizeof(ares[0]),
                                  NULL, 0, NI_NAMEREQD);
            if (retval != EINTR && retval != EAI_AGAIN) break;
            sleep (1);
         }
         if (retval)
         {
            if (retval == EAI_NONAME)
               sprintf (ares[idx], "[unknown]");
            else
            if (retval == EAI_FAIL || retval == EAI_AGAIN)
               sprintf (ares[idx], "[failed]");
            else
               sprintf (ares[idx], "[%s]", gai_strerror(retval));
         }
         return (ares[idx]);
      }
      else
      {
         memset (&addr6, 0, sizeof(addr6));
         if (inet_pton (AF_INET6, Address, &addr6.sin6_addr) > 0)
         {
            addr6.sin6_len = sizeof(struct sockaddr_in6);
            addr6.sin6_family = AF_INET6;
            if (Ip6Addr)
               memcpy (Ip6Addr, &addr6.sin6_addr, sizeof(addr6.sin6_addr));
            for (retry = TCPIP_LOOKUP_HOST_NAME_RETRY; retry; retry--)
            {
               retval = getnameinfo ((struct sockaddr*)&addr6, addr6.sin6_len,
                                     ares[idx], sizeof(ares[0]),
                                     NULL, 0, NI_NAMEREQD);
               if (retval != EINTR && retval != EAI_AGAIN) break;
               sleep (1);
            }
            if (retval)
            {
               if (retval == EAI_NONAME)
                  sprintf (ares[idx], "[unknown]");
               else
               if (retval == EAI_FAIL || retval == EAI_AGAIN)
                  sprintf (ares[idx], "[failed]");
               else
                  sprintf (ares[idx], "[%s]", gai_strerror(retval));
            }
         }
         else
            sprintf (ares[aCacheIdx], "[%s]", strerror(errno));
         return (ares[idx]);
      }
   }

   return ("[bugcheck]");
}

/*****************************************************************************/
/*
Return true if it looks like an IPv4 or IPv6 address.
*/

BOOL TcpIpIsAddress (char *string)

{
   char  *cptr;

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

   if (Debug) fprintf (stdout, "TcpIpIsAddress() |%s|\n", string);

   if (!string) return (false);

   for (cptr = string; *cptr && isspace(*cptr); cptr++);
   if (!*cptr) return (false);

   cptr = string;
   if (*(unsigned long*)cptr == '::FF' && !memcmp (cptr, "::FFFF:", 7))
      cptr += 7;
   else
   if (*(unsigned long*)cptr == '::ff' && !memcmp (cptr, "::ffff:", 7))
      cptr += 7;

   while (*cptr && (isdigit(*cptr) || *cptr == '.')) cptr++;
   if (!*cptr) return (true);

   for (cptr = string;
        *cptr && (isxdigit(*cptr) || *cptr == ':' || *cptr == '-');
        cptr++);
   if (!*cptr) return (true);

   return (false);
}

/*****************************************************************************/
/*
Initialise (first call) and then output (second call) some statistics.
*/

char* StatTimer ()

{
   static $DESCRIPTOR (StatFaoDsc,
"time:!%T cpu:!UL.!UL dio:!UL bio:!UL faults:!UL rec/sec:!AZ\0");

   static unsigned long  LibStatTimerReal = 1,
                         LibStatTimerCpu = 2,
                         LibStatTimerBio = 3,
                         LibStatTimerDio = 4,
                         LibStatTimerFaults = 5;

   static char  StatString [128];
   static $DESCRIPTOR (StatStringDsc, StatString);

   int  status;
   unsigned long  CpuBinTime,
                  CountBio,
                  CountDio,
                  CountFaults;
   unsigned long  RealBinTime [2];
   float  fSeconds;
   char  *cptr, *sptr;
   char  RealTime[32],
         RecordsPerSecond [32];

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

   if (Debug) fprintf (stdout, "StatTimer()\n");

   if (!StatString[0])
   {
      lib$init_timer (0);
      StatString[0] = '*';
      return (NULL);
   }

   lib$stat_timer (&LibStatTimerReal, &RealBinTime, 0);
   lib$stat_timer (&LibStatTimerCpu, &CpuBinTime, 0);
   lib$stat_timer (&LibStatTimerBio, &CountBio, 0);
   lib$stat_timer (&LibStatTimerDio, &CountDio, 0);
   lib$stat_timer (&LibStatTimerFaults, &CountFaults, 0);

   fSeconds = (float)RealBinTime[0];
   fSeconds += (float)((signed int)RealBinTime[1]) * 4294967296.0;
   fSeconds *= -0.0000001;
   if ((float)RecordCountTotal / fSeconds > 100.0)
      sprintf (RecordsPerSecond, "%d",
               (int)((float)RecordCountTotal / fSeconds));
   else
      sprintf (RecordsPerSecond, "%g", (float)RecordCountTotal / fSeconds);

   sys$fao (&StatFaoDsc, 0, &StatStringDsc,
            &RealBinTime, CpuBinTime/100, CpuBinTime%100,
            CountDio, CountBio, CountFaults,
            RecordsPerSecond);

   /* compress the real time string */
   for (sptr = cptr = StatString; cptr < StatString+5; *sptr++ = *cptr++);
   while ((*cptr == '0' || *cptr == ':') && cptr < StatString+12) cptr++;
   while (*cptr) *sptr++ = *cptr++;
   *sptr = '\0';

   return (StatString);
}

/*****************************************************************************/
/*
Get "command-line" parameters, whether from the command-line or from a
configuration symbol or logical containing the equivalent.

(This code is *derived* from a similar functionality in [SRC.HTTPD]TCPIP.C)
*/

GetParameters ()

{
   static char  CommandLine [256];
   static unsigned long  Flags = 0;

   int  status,
        SkipParameters;
   unsigned short  Length;
   char  ch;
   char  *aptr, *cptr, *clptr, *sptr;
   $DESCRIPTOR (CommandLineDsc, CommandLine);
   $DESCRIPTOR (DateTimeDsc, "");

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

   if (Debug) fprintf (stdout, "GetParameters()\n");

   if (!(clptr = getenv ("QDLOGSTATS$PARAM")))
   {
      /* get the entire command line following the verb */
      if (VMSnok (status =
          lib$get_foreign (&CommandLineDsc, 0, &Length, &Flags)))
         exit (status);
      (clptr = CommandLine)[Length] = '\0';
   }

   /* if [C]SWS (VMS Apache) */
   if (CgiLibEnvironmentIsApache())
   {
      /* CSWS 1.2/3 look for something non-space outside of quotes */
      for (cptr = clptr; *cptr; cptr++)
      {
         if (isspace(*cptr)) continue;
         if (*cptr != '\"') break;
         cptr++;
         while (*cptr && *cptr != '\"') cptr++;
         if (*cptr) cptr++;
      }
      /* CSWS 1.2/3 if nothing outside of quotes then ignore command line */
      if (!*cptr) return;
      /* SWS 2.0 doesn't begin with /APACHE from DCL procedure wrapper */
      if (!strsame (cptr, "/APACHE", 7)) return;
   }

   /* if OSU environment then skip P1, P2, P3 */
   if (CgiLibEnvironmentIsOsu())
      SkipParameters = 3;
   else
      SkipParameters = 0;

   aptr = NULL;
   ch = *clptr;
   for (;;)
   {
      if (aptr && *aptr == '/') *aptr = '\0';
      if (!ch) break;

      *clptr = ch;
      if (Debug) fprintf (stdout, "clptr |%s|\n", clptr);
      while (*clptr && isspace(*clptr)) *clptr++ = '\0';
      aptr = clptr;
      if (*clptr == '/') clptr++;
      while (*clptr && !isspace (*clptr) && *clptr != '/')
      {
         if (*clptr != '\"')
         {
            clptr++;
            continue;
         }
         cptr = clptr;
         clptr++;
         while (*clptr)
         {
            if (*clptr == '\"')
               if (*(clptr+1) == '\"')
                  clptr++;
               else
                  break;
            *cptr++ = *clptr++;
         }
         *cptr = '\0';
         if (*clptr) clptr++;
      }
      ch = *clptr;
      if (*clptr) *clptr = '\0';
      if (Debug) fprintf (stdout, "aptr |%s|\n", aptr);
      if (!*aptr) continue;

      if (SkipParameters)
      {
         SkipParameters--;
         continue;
      }

      if (strsame (aptr, "/RESOLVE", 6))
      {
         Addr2Name = true;
         continue;
      }
      if (strsame (aptr, "/APACHE", 4))
      {
         /* just skip this marker for command-line parameters under SWS 2.0 */
         continue;
      }
      if (strsame (aptr, "/ALL", -1))
      {
         FilterOnAll = true;
         continue;
      }
      if (strsame (aptr, "/AUTHUSER=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         AuthUserFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/BEFORE=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         DateTimeDsc.dsc$a_pointer = cptr;
         DateTimeDsc.dsc$w_length = strlen(cptr);
         if (DateTimeDsc.dsc$w_length >= 11 && !isalnum(cptr[11]))
            cptr[11] = ' ';
         status = lib$convert_date_string (&DateTimeDsc, &LmBeforeBinTime,
                                           0, 0, 0, 0);
         if (VMSnok (status)) exit (status);
         continue;
      }
      if (strsame (aptr, "/CLIENT=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         ClientFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/DBUG", -1))
      {
         Debug = true;
         continue;
      }
      if (strsame (aptr, "/DATETIME=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         DateTimeFilterPtr = DateTimeFilter (cptr);
         continue;
      }
      if (strsame (aptr, "/DECODE=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         if (!*cptr)
         {
            UrlDecodePath = UrlDecodeQuery = UrlDecodeReferer = true;
            continue;
         }
         if (*cptr == '(') cptr++;
         while (*cptr && *cptr != ')')
         {
            while (*cptr == ',') cptr++;
            if (*cptr) cptr++;
            if (toupper(*cptr) == 'P')
               UrlDecodePath = true;
            else
            if (toupper(*cptr) == 'Q')
               UrlDecodeQuery = true;
            else
            if (toupper(*cptr) == 'R')
               UrlDecodeReferer = true;
            else
            {
               for (sptr = cptr; *sptr && *sptr != ',' && *sptr != ')'; sptr++);
               *sptr = '\0';
               fprintf (stdout, "%%%s-E-INVKEYW, invalid keyword\n \\%s\\\n",
                        Utility, cptr);
               exit (STS$K_ERROR | STS$M_INHIB_MSG);
            }
            while (*cptr && *cptr != ',' && *cptr != ')') cptr++;
         }
         continue;
      }
      if (strsame (aptr, "/DTBEFORE=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         DateTimeDsc.dsc$a_pointer = cptr;
         DateTimeDsc.dsc$w_length = strlen(cptr);
         if (DateTimeDsc.dsc$w_length >= 11 && !isalnum(cptr[11]))
            cptr[11] = ' ';
         status = lib$convert_date_string (&DateTimeDsc, &DtBeforeFilterBinTime,
                                           0, 0, 0, 0);
         if (VMSnok (status)) exit (status);
         continue;
      }
      if (strsame (aptr, "/DTSINCE=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         DateTimeDsc.dsc$a_pointer = cptr;
         DateTimeDsc.dsc$w_length = strlen(cptr);
         if (DateTimeDsc.dsc$w_length >= 11 && !isalnum(cptr[11]))
            cptr[11] = ' ';
         status = lib$convert_date_string (&DateTimeDsc, &DtSinceFilterBinTime,
                                           0, 0, 0, 0);
         if (VMSnok (status)) exit (status);
         continue;
      }
      if (strsame (aptr, "/IP=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         if (isdigit(*cptr))
            IpVersionFilter = atoi(cptr);
         else
         {
            fprintf (stdout, "%%%s-E-IVKEYW, unrecognized keyword\n \\%s\\\n",
                     Utility, cptr);
            exit (STS$K_ERROR | STS$M_INHIB_MSG);
         }
         continue;
      }
      if (strsame (aptr, "/LOG", -1))
      {
         ShowLogFile = true;
         continue;
      }
      if (strsame (aptr, "/LOOKUP=", 5))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         if (isdigit(*cptr))
            LookupRetry = atoi(cptr);
         else
            LookupRetry = 0;
         continue;
      }
      if (strsame (aptr, "/METHOD=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         MethodFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/NOWASD", -1))
      {
         NoWasdEntries = true;
         continue;
      }
      if (strsame (aptr, "/OUTPUT=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         OutputPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/PATH=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         PathFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/PROGRESS=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         ShowProgress = atoi(cptr);
         if (ShowProgress <= 0) ShowProgress = PROGRESS_RECORDS;
         continue;
      }
      if (strsame (aptr, "/QUERY=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         QueryFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/REFERER=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         RefererFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/REMOTEID=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         RemoteIdentFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/RESPONSE", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         ResponseFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/SINCE=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         DateTimeDsc.dsc$a_pointer = cptr;
         DateTimeDsc.dsc$w_length = strlen(cptr);
         if (DateTimeDsc.dsc$w_length >= 11 && !isalnum(cptr[11]))
            cptr[11] = ' ';
         status = lib$convert_date_string (&DateTimeDsc, &LmSinceBinTime,
                                           0, 0, 0, 0);
         if (VMSnok (status)) exit (status);
         continue;
      }
      if (strsame (aptr, "/SIZE=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         while (*cptr == '=') cptr++;
         while (*cptr == '(') cptr++;
         while (*cptr)
         {
            if (strsame (cptr, "MIN=", 4))
            {
               cptr += 4;
               ResponseMinSize = atoi(cptr);
               while (isdigit(*cptr)) cptr++;
               if (tolower(*cptr) == 'k') ResponseMinSize *= 1000;
               if (toupper(*cptr) == 'M') ResponseMinSize *= 1000000;
            }
            else
            if (strsame (cptr, "MAX=", 4))
            {
               cptr += 4;
               ResponseMaxSize = atoi(cptr);
               while (isdigit(*cptr)) cptr++;
               if (tolower(*cptr) == 'k') ResponseMaxSize *= 1000;
               if (toupper(*cptr) == 'M') ResponseMaxSize *= 1000000;
            }
            else
            {
               fprintf (stdout, "%%%s-E-IVKEYW, unrecognized keyword\n \\%s\\\n",
                        Utility, cptr);
               exit (STS$K_ERROR | STS$M_INHIB_MSG);
            }
            while (*cptr && *cptr != ',' && *cptr != ')') cptr++;
            while (*cptr == ',' || *cptr == ')') cptr++;
         }
         continue;
      }
      if (strsame (aptr, "/SOFTWAREID", 4) ||
          strsame (aptr, "/VERSION", 4))
      {
         fprintf (stdout, "%%%s-I-SOFTWAREID, %s\n%s\n",
                  Utility, SoftwareID, CopyrightInfo);
         exit (SS$_NORMAL);
      }
      if (strsame (aptr, "/USERAGENT=", 4))
      {
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (*cptr) cptr++;
         UserAgentFilterPtr = cptr;
         continue;
      }
      if (strsame (aptr, "/VIEW=", 4))
      {
         ViewRecords = VIEW_MATCH;
         for (cptr = aptr; *cptr && *cptr != '='; cptr++);
         if (!*cptr) continue;
         cptr++;
         if (strsame (cptr, "ALL", 3))
            ViewRecords = VIEW_ALL;
         else
         if (strsame (cptr, "LOG", 3))
            ViewRecords = VIEW_LOG;
         else
         if (strsame (cptr, "MATCH", 3))
            ViewRecords = VIEW_MATCH;
         else
         if (strsame (cptr, "NOMATCH", 3))
            ViewRecords = VIEW_NOMATCH;
         else
         if (strsame (cptr, "SUSPECT", 7))
            ViewRecords = VIEW_SUSPECT;
         else
         if (strsame (cptr, "UNIQUE", 6))
            ViewRecords = VIEW_UNIQUE;
         else
         {
            fprintf (stdout, "%%%s-E-IVKEYW, unrecognized keyword\n \\%s\\\n",
                     Utility, cptr);
            exit (STS$K_ERROR | STS$M_INHIB_MSG);
         }
         continue;
      }

      if (*aptr == '/')
      {
         fprintf (stdout, "%%%s-E-IVQUAL, unrecognized qualifier\n \\%s\\\n",
                  Utility, aptr+1);
         exit (STS$K_ERROR | STS$M_INHIB_MSG);
      }

      if (!LogFileSpec[0])
      {
         sptr = LogFileSpec;
         for (cptr = aptr; *cptr; *sptr++ = toupper(*cptr++));
         *sptr = '\0';
         continue;
      }

      fprintf (stdout, "%%%s-E-MAXPARM, too many parameters\n \\%s\\\n",
               Utility, aptr);
      exit (STS$K_ERROR | STS$M_INHIB_MSG);
   }
}

/*****************************************************************************/
/*
Get the value of a system-level (only) logical name.  Returns a pointer to
dynamic storage containing the null-terminated string, or NULL if a problem.
A *little* like 'getenv()' but only from the system logical table - serves much
the same purpose anyway.
*/

char* SysTrnLnmSystem (char *LogicalName)

{
   static unsigned short  Length;
   static char  LogicalValue [256];
   static $DESCRIPTOR (LogicalNameDsc, "");
   static $DESCRIPTOR (LnmSystemDsc, "LNM$SYSTEM");
   static struct {
      short int  buf_len;
      short int  item;
      void  *buf_addr;
      unsigned short  *ret_len;
   } LnmItems [] =
   {
      { sizeof(LogicalValue)-1, LNM$_STRING, LogicalValue, &Length },
      { 0,0,0,0 }
   };

   int  status;
   char  *sptr;

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

   if (Debug) fprintf (stdout, "SysTrnLnmSystem() |%s|\n", LogicalName);

   LogicalNameDsc.dsc$w_length = strlen(LogicalName);
   LogicalNameDsc.dsc$a_pointer = LogicalName;

   status = sys$trnlnm (0, &LnmSystemDsc, &LogicalNameDsc, 0, &LnmItems);
   if (Debug) fprintf (stdout, "sys$trnlnm() %%X%08.08X\n", status);
   if (VMSnok (status)) return (NULL);

   LogicalValue[Length] = '\0';
   if (Debug) fprintf (stdout, "|%s|\n", LogicalValue);
   if (!(sptr = calloc (1, Length+1))) exit (vaxc$errno);
   memcpy (sptr, LogicalValue, Length+1);
   return (sptr);
}

/*****************************************************************************/
/*
Return a pointer to the message string corresponding to the supplied VMS status
value.
*/

char* SysGetMsg (int VmsStatus)

{
   static char  Message [256];

   int  status;
   short int  Length;
   $DESCRIPTOR (MessageDsc, Message);

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

   Message[0] = '\0';
   if (VmsStatus)
   {
      /* text component only */
      sys$getmsg (VmsStatus, &Length, &MessageDsc, 1, 0);
      Message[Length] = '\0';
   }
   if (Message[0])
      return (Message);
   else
      return ("(internal error)");
}
 
/*****************************************************************************/
/*
Because it can be installed with privileges (for CLI usage) ...
*/ 

void NeedsPrivilegedAccount ()

{
   static unsigned long  PrivAcctMask [2] = { PRV$M_SETPRV | PRV$M_SYSPRV, 0 };

   static long  Pid = -1;
   static unsigned long  JpiAuthPriv [2];

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

   int  status;

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

   if (Debug) fprintf (stdout, "NeedsPrivilegedAccount()\n");

   status = sys$getjpiw (0, &Pid, 0, &JpiItems, 0, 0, 0);
   if (VMSnok (status)) exit (status);

   if (!(JpiAuthPriv[0] & PrivAcctMask[0])) exit (SS$_NOSYSPRV);
}

/****************************************************************************/
/*
Does a case-insensitive, character-by-character string compare and returns 
true if two strings are the same, or false if not.  If a maximum number of 
characters are specified only those will be compared, if the entire strings 
should be compared then specify the number of characters as 0.
*/ 

BOOL strsame
(
char *sptr1,
char *sptr2,
int  count
)
{
   /*********/
   /* begin */
   /*********/

   while (*sptr1 && *sptr2)
   {
      if (toupper (*sptr1++) != toupper (*sptr2++)) return (false);
      if (count)
         if (!--count) return (true);
   }
   if (*sptr1 || *sptr2)
      return (false);
   else
      return (true);
}

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

int ShowHelp ()

{
   fputs (
"Usage for Quick and Dirty LOG STATisticS\n\
\n\
$ QDLOGSTATS <log-file-spec> [<filters>] [<other qualifiers>]\n\
\n\
Utility to extract very elementary statistics from Web server common/combined\n\
format log files.  A number of filters allow subsets of the log contents to be\n\
selected using simple wildcard expressions.  Strings are NOT case-sensitive.\n\
Optionally, log file records can be viewed as processed, or a simple progress\n\
indicator can be displayed (\"+\" for each file, \".\" per 1000 records thereof).\n\
\n\
/ALL /AUTHUSER=filter /BEFORE=time /CLIENT=filter /DATETIME=filter\n\
/DECODE[=keyword] /DTBEFORE=time /DTSINCE=time /IP=[4|6] /LOG\n\
/LOOKUP[=integer] /METHOD=filter /NOWASD /OUTPUT=file /PATH=filter\n\
/PROGRESS[=integer] /PROTOCOL=filter /QUERY=filter /REFERER=filter\n\
/RESOLVE /RESPONSE=filter /SINCE=time /SIZE=[MIN=,MAX=] /SOFTWAREID\n\
SERAGENT=filter /VERSION /VIEW[=MATCH(D)|ALL|NOMATCH|LOG|SUSPECT]\n\
\n\
$ QDLOGSTATS == \"$dir:QDLOGSTATS\"\n\
$ QDLOGSTATS WASD_LOGS:*.LOG /VIEW /PATH=\"/wasd/*.zip\"\n\
$ QDLOGSTATS WASD_LOGS:*NOV*ACCESS* /PATH=\"/CGI-BIN/*\" /QUERY=\"-{-}\"\n\
$ QDLOGSTATS WASD_LOGS:*ACCESS*.LOG /METHOD=POST /DTSINCE=YESTERDAY\n\
$ QDLOGSTATS WASD_LOGS:*.LOG /SINCE=01-FEB-2002 /USERAGENT=*MOZILLA*X11*\n\
\n", stdout);

   return (SS$_NORMAL);
}

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