1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
|
/*
Copyright (c) 2008-2009 Z RESEARCH, Inc. <http://www.zresearch.com>
This file is part of GlusterFS.
GlusterFS 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 3 of the License,
or (at your option) any later version.
GlusterFS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef CORE_PRIVATE
#define CORE_PRIVATE
#endif
#ifndef NO_CONTENT_TYPE
#define NO_CONTENT_TYPE "none"
#endif
#define BYTERANGE_FMT "%" APR_OFF_T_FMT "-%" APR_OFF_T_FMT "/%" APR_OFF_T_FMT
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <httpd.h>
#include <http_config.h>
#include <http_core.h>
#include <http_request.h>
#include <http_protocol.h>
#include <http_log.h>
#include <http_main.h>
#include <util_script.h>
#include <util_filter.h>
#include <libglusterfsclient.h>
#include <sys/uio.h>
#include <pthread.h>
#include <apr.h>
#include <apr_strings.h>
#include <apr_buckets.h>
#include <apr_fnmatch.h>
#include <apr_lib.h>
#define GLUSTERFS_INVALID_LOGLEVEL "mod_glfs: Unrecognized log-level \"%s\", possible values are \"DEBUG|WARNING|ERROR|CRITICAL|NONE\"\n"
#define GLUSTERFS_HANDLER "glusterfs-handler"
#define GLUSTERFS_CHUNK_SIZE 131072
static char c_by_encoding, c_by_type, c_by_path;
#define BY_ENCODING &c_by_encoding
#define BY_TYPE &c_by_type
#define BY_PATH &c_by_path
module AP_MODULE_DECLARE_DATA glusterfs_module;
extern module core_module;
#define NO_OPTIONS (1 << 0) /* Indexing options */
#define ICONS_ARE_LINKS (1 << 1)
#define SCAN_HTML_TITLES (1 << 2)
#define SUPPRESS_ICON (1 << 3)
#define SUPPRESS_LAST_MOD (1 << 4)
#define SUPPRESS_SIZE (1 << 5)
#define SUPPRESS_DESC (1 << 6)
#define SUPPRESS_PREAMBLE (1 << 7)
#define SUPPRESS_COLSORT (1 << 8)
#define SUPPRESS_RULES (1 << 9)
#define FOLDERS_FIRST (1 << 10)
#define VERSION_SORT (1 << 11)
#define TRACK_MODIFIED (1 << 12)
#define FANCY_INDEXING (1 << 13)
#define TABLE_INDEXING (1 << 14)
#define IGNORE_CLIENT (1 << 15)
#define IGNORE_CASE (1 << 16)
#define EMIT_XHTML (1 << 17)
#define SHOW_FORBIDDEN (1 << 18)
#define K_NOADJUST 0
#define K_ADJUST 1
#define K_UNSET 2
/*
* Define keys for sorting.
*/
#define K_NAME 'N' /* Sort by file name (default) */
#define K_LAST_MOD 'M' /* Last modification date */
#define K_SIZE 'S' /* Size (absolute, not as displayed) */
#define K_DESC 'D' /* Description */
#define K_VALID "NMSD" /* String containing _all_ valid K_ opts */
#define D_ASCENDING 'A'
#define D_DESCENDING 'D'
#define D_VALID "AD" /* String containing _all_ valid D_ opts */
/*
* These are the dimensions of the default icons supplied with Apache.
*/
#define DEFAULT_ICON_WIDTH 20
#define DEFAULT_ICON_HEIGHT 22
/*
* Other default dimensions.
*/
#define DEFAULT_NAME_WIDTH 23
#define DEFAULT_DESC_WIDTH 23
struct mod_glfs_ai_item {
char *type;
char *apply_to;
char *apply_path;
char *data;
};
typedef struct mod_glfs_ai_desc_t {
char *pattern;
char *description;
int full_path;
int wildcards;
} mod_glfs_ai_desc_t;
typedef enum {
SLASH_OFF = 0,
SLASH_ON,
SLASH_UNSET
} mod_glfs_dir_slash_cfg;
/* static ap_filter_rec_t *mod_glfs_output_filter_handle; */
/*TODO: verify error returns to server core */
typedef struct glusterfs_dir_config {
char *logfile;
char *loglevel;
char *specfile;
char *mount_dir;
char *buf;
size_t xattr_file_size;
uint32_t cache_timeout;
libglusterfs_handle_t handle;
/* mod_dir options */
apr_array_header_t *index_names;
mod_glfs_dir_slash_cfg do_slash;
/* autoindex options */
char *default_icon;
char *style_sheet;
apr_int32_t opts;
apr_int32_t incremented_opts;
apr_int32_t decremented_opts;
int name_width;
int name_adjust;
int desc_width;
int desc_adjust;
int icon_width;
int icon_height;
char default_keyid;
char default_direction;
apr_array_header_t *icon_list;
apr_array_header_t *alt_list;
apr_array_header_t *desc_list;
apr_array_header_t *ign_list;
apr_array_header_t *hdr_list;
apr_array_header_t *rdme_list;
char *ctype;
char *charset;
} glusterfs_dir_config_t;
typedef struct glusterfs_async_local {
int op_ret;
int op_errno;
char async_read_complete;
off_t length;
off_t read_bytes;
glusterfs_read_buf_t *buf;
request_rec *request;
pthread_mutex_t lock;
pthread_cond_t cond;
}glusterfs_async_local_t;
#define GLUSTERFS_CMD_PERMS ACCESS_CONF
static glusterfs_dir_config_t *
mod_glfs_dconfig (request_rec *r)
{
glusterfs_dir_config_t *dir_config = NULL;
if (r->per_dir_config != NULL) {
dir_config = ap_get_module_config (r->per_dir_config, &glusterfs_module);
}
return dir_config;
}
static const char *
cmd_add_xattr_file_size (cmd_parms *cmd, void *dummy, const char *arg)
{
glusterfs_dir_config_t *dir_config = dummy;
dir_config->xattr_file_size = atoi (arg);
return NULL;
}
static const char *
cmd_set_cache_timeout (cmd_parms *cmd, void *dummy, const char *arg)
{
glusterfs_dir_config_t *dir_config = dummy;
dir_config->cache_timeout = atoi (arg);
return NULL;
}
static const char *
cmd_set_loglevel (cmd_parms *cmd, void *dummy, const char *arg)
{
glusterfs_dir_config_t *dir_config = dummy;
char *error = NULL;
if (strncasecmp (arg, "DEBUG", strlen ("DEBUG"))
&& strncasecmp (arg, "WARNING", strlen ("WARNING"))
&& strncasecmp (arg, "CRITICAL", strlen ("CRITICAL"))
&& strncasecmp (arg, "NONE", strlen ("NONE"))
&& strncasecmp (arg, "ERROR", strlen ("ERROR")))
error = GLUSTERFS_INVALID_LOGLEVEL;
else
dir_config->loglevel = apr_pstrdup (cmd->pool, arg);
return error;
}
static const char *
cmd_add_logfile (cmd_parms *cmd, void *dummy, const char *arg)
{
glusterfs_dir_config_t *dir_config = dummy;
dir_config->logfile = apr_pstrdup (cmd->pool, arg);
return NULL;
}
static const char *
cmd_add_volume_specfile (cmd_parms *cmd, void *dummy, const char *arg)
{
glusterfs_dir_config_t *dir_config = dummy;
dir_config->specfile = apr_pstrdup (cmd->pool, arg);
return NULL;
}
#define WILDCARDS_REQUIRED 0
static const char *
cmd_add_desc (cmd_parms *cmd, void *d, const char *desc,
const char *to)
{
glusterfs_dir_config_t *dcfg = (glusterfs_dir_config_t *) d;
mod_glfs_ai_desc_t *desc_entry;
char *prefix = "";
desc_entry = (mod_glfs_ai_desc_t *) apr_array_push(dcfg->desc_list);
desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
desc_entry->wildcards = (WILDCARDS_REQUIRED
|| desc_entry->full_path
|| apr_fnmatch_test(to));
if (desc_entry->wildcards) {
prefix = desc_entry->full_path ? "*/" : "*";
desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
prefix, to, "*", NULL);
}
else {
desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
}
desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
return NULL;
}
static void push_item(apr_array_header_t *arr, char *type, const char *to,
const char *path, const char *data)
{
struct mod_glfs_ai_item *p = (struct mod_glfs_ai_item *) apr_array_push(arr);
if (!to) {
to = "";
}
if (!path) {
path = "";
}
p->type = type;
p->data = data ? apr_pstrdup(arr->pool, data) : NULL;
p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
}
else if (to) {
p->apply_to = apr_pstrdup(arr->pool, to);
}
else {
p->apply_to = NULL;
}
}
static const char *
cmd_add_ignore (cmd_parms *cmd, void *d, const char *ext)
{
push_item(((glusterfs_dir_config_t *) d)->ign_list, 0, ext, cmd->path, NULL);
return NULL;
}
static const char *
cmd_add_header (cmd_parms *cmd, void *d, const char *name)
{
push_item(((glusterfs_dir_config_t *) d)->hdr_list, 0, NULL, cmd->path,
name);
return NULL;
}
static const char *
cmd_add_readme (cmd_parms *cmd, void *d, const char *name)
{
push_item(((glusterfs_dir_config_t *) d)->rdme_list, 0, NULL, cmd->path,
name);
return NULL;
}
static const char *
cmd_add_opts (cmd_parms *cmd, void *d, int argc, char *const argv[])
{
int i;
char *w;
apr_int32_t opts;
apr_int32_t opts_add;
apr_int32_t opts_remove;
char action;
glusterfs_dir_config_t *d_cfg = (glusterfs_dir_config_t *) d;
opts = d_cfg->opts;
opts_add = d_cfg->incremented_opts;
opts_remove = d_cfg->decremented_opts;
for (i = 0; i < argc; i++) {
int option = 0;
w = argv[i];
if ((*w == '+') || (*w == '-')) {
action = *(w++);
}
else {
action = '\0';
}
if (!strcasecmp(w, "FancyIndexing")) {
option = FANCY_INDEXING;
}
else if (!strcasecmp(w, "FoldersFirst")) {
option = FOLDERS_FIRST;
}
else if (!strcasecmp(w, "HTMLTable")) {
option = TABLE_INDEXING;
}
else if (!strcasecmp(w, "IconsAreLinks")) {
option = ICONS_ARE_LINKS;
}
else if (!strcasecmp(w, "IgnoreCase")) {
option = IGNORE_CASE;
}
else if (!strcasecmp(w, "IgnoreClient")) {
option = IGNORE_CLIENT;
}
else if (!strcasecmp(w, "ScanHTMLTitles")) {
option = SCAN_HTML_TITLES;
}
else if (!strcasecmp(w, "SuppressColumnSorting")) {
option = SUPPRESS_COLSORT;
}
else if (!strcasecmp(w, "SuppressDescription")) {
option = SUPPRESS_DESC;
}
else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
option = SUPPRESS_PREAMBLE;
}
else if (!strcasecmp(w, "SuppressIcon")) {
option = SUPPRESS_ICON;
}
else if (!strcasecmp(w, "SuppressLastModified")) {
option = SUPPRESS_LAST_MOD;
}
else if (!strcasecmp(w, "SuppressSize")) {
option = SUPPRESS_SIZE;
}
else if (!strcasecmp(w, "SuppressRules")) {
option = SUPPRESS_RULES;
}
else if (!strcasecmp(w, "TrackModified")) {
option = TRACK_MODIFIED;
}
else if (!strcasecmp(w, "VersionSort")) {
option = VERSION_SORT;
}
else if (!strcasecmp(w, "XHTML")) {
option = EMIT_XHTML;
}
else if (!strcasecmp(w, "ShowForbidden")) {
option = SHOW_FORBIDDEN;
}
else if (!strcasecmp(w, "None")) {
if (action != '\0') {
return "Cannot combine '+' or '-' with 'None' keyword";
}
opts = NO_OPTIONS;
opts_add = 0;
opts_remove = 0;
}
else if (!strcasecmp(w, "IconWidth")) {
if (action != '-') {
d_cfg->icon_width = DEFAULT_ICON_WIDTH;
}
else {
d_cfg->icon_width = 0;
}
}
else if (!strncasecmp(w, "IconWidth=", 10)) {
if (action == '-') {
return "Cannot combine '-' with IconWidth=n";
}
d_cfg->icon_width = atoi(&w[10]);
}
else if (!strcasecmp(w, "IconHeight")) {
if (action != '-') {
d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
}
else {
d_cfg->icon_height = 0;
}
}
else if (!strncasecmp(w, "IconHeight=", 11)) {
if (action == '-') {
return "Cannot combine '-' with IconHeight=n";
}
d_cfg->icon_height = atoi(&w[11]);
}
else if (!strcasecmp(w, "NameWidth")) {
if (action != '-') {
return "NameWidth with no value may only appear as "
"'-NameWidth'";
}
d_cfg->name_width = DEFAULT_NAME_WIDTH;
d_cfg->name_adjust = K_NOADJUST;
}
else if (!strncasecmp(w, "NameWidth=", 10)) {
if (action == '-') {
return "Cannot combine '-' with NameWidth=n";
}
if (w[10] == '*') {
d_cfg->name_adjust = K_ADJUST;
}
else {
int width = atoi(&w[10]);
if (width && (width < 5)) {
return "NameWidth value must be greater than 5";
}
d_cfg->name_width = width;
d_cfg->name_adjust = K_NOADJUST;
}
}
else if (!strcasecmp(w, "DescriptionWidth")) {
if (action != '-') {
return "DescriptionWidth with no value may only appear as "
"'-DescriptionWidth'";
}
d_cfg->desc_width = DEFAULT_DESC_WIDTH;
d_cfg->desc_adjust = K_NOADJUST;
}
else if (!strncasecmp(w, "DescriptionWidth=", 17)) {
if (action == '-') {
return "Cannot combine '-' with DescriptionWidth=n";
}
if (w[17] == '*') {
d_cfg->desc_adjust = K_ADJUST;
}
else {
int width = atoi(&w[17]);
if (width && (width < 12)) {
return "DescriptionWidth value must be greater than 12";
}
d_cfg->desc_width = width;
d_cfg->desc_adjust = K_NOADJUST;
}
}
else if (!strncasecmp(w, "Type=", 5)) {
d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]);
}
else if (!strncasecmp(w, "Charset=", 8)) {
d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]);
}
else {
return "Invalid directory indexing option";
}
if (action == '\0') {
opts |= option;
opts_add = 0;
opts_remove = 0;
}
else if (action == '+') {
opts_add |= option;
opts_remove &= ~option;
}
else {
opts_remove |= option;
opts_add &= ~option;
}
}
if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
return "Cannot combine other IndexOptions keywords with 'None'";
}
d_cfg->incremented_opts = opts_add;
d_cfg->decremented_opts = opts_remove;
d_cfg->opts = opts;
return NULL;
}
static const char *
cmd_set_default_order(cmd_parms *cmd, void *m,
const char *direction, const char *key)
{
glusterfs_dir_config_t *d_cfg = (glusterfs_dir_config_t *) m;
if (!strcasecmp(direction, "Ascending")) {
d_cfg->default_direction = D_ASCENDING;
}
else if (!strcasecmp(direction, "Descending")) {
d_cfg->default_direction = D_DESCENDING;
}
else {
return "First keyword must be 'Ascending' or 'Descending'";
}
if (!strcasecmp(key, "Name")) {
d_cfg->default_keyid = K_NAME;
}
else if (!strcasecmp(key, "Date")) {
d_cfg->default_keyid = K_LAST_MOD;
}
else if (!strcasecmp(key, "Size")) {
d_cfg->default_keyid = K_SIZE;
}
else if (!strcasecmp(key, "Description")) {
d_cfg->default_keyid = K_DESC;
}
else {
return "Second keyword must be 'Name', 'Date', 'Size', or "
"'Description'";
}
return NULL;
}
static char c_by_encoding, c_by_type, c_by_path;
#define BY_ENCODING &c_by_encoding
#define BY_TYPE &c_by_type
#define BY_PATH &c_by_path
/*
* This routine puts the standard HTML header at the top of the index page.
* We include the DOCTYPE because we may be using features therefrom (i.e.,
* HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
*/
static void emit_preamble(request_rec *r, int xhtml, const char *title)
{
glusterfs_dir_config_t *d;
d = (glusterfs_dir_config_t *) ap_get_module_config(r->per_dir_config,
&glusterfs_module);
if (xhtml) {
ap_rvputs(r, DOCTYPE_XHTML_1_0T,
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
" <head>\n <title>Index of ", title,
"</title>\n", NULL);
} else {
ap_rvputs(r, DOCTYPE_HTML_3_2,
"<html>\n <head>\n"
" <title>Index of ", title,
"</title>\n", NULL);
}
if (d->style_sheet != NULL) {
ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
"\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
}
ap_rvputs(r, " </head>\n <body>\n", NULL);
}
static const char *cmd_add_alt(cmd_parms *cmd, void *d, const char *alt,
const char *to)
{
if (cmd->info == BY_PATH) {
if (!strcmp(to, "**DIRECTORY**")) {
to = "^^DIRECTORY^^";
}
}
if (cmd->info == BY_ENCODING) {
char *tmp = apr_pstrdup(cmd->pool, to);
ap_str_tolower(tmp);
to = tmp;
}
push_item(((glusterfs_dir_config_t *) d)->alt_list, cmd->info, to,
cmd->path, alt);
return NULL;
}
static const char *cmd_add_icon(cmd_parms *cmd, void *d, const char *icon,
const char *to)
{
char *iconbak = apr_pstrdup(cmd->pool, icon);
if (icon[0] == '(') {
char *alt;
char *cl = strchr(iconbak, ')');
if (cl == NULL) {
return "missing closing paren";
}
alt = ap_getword_nc(cmd->pool, &iconbak, ',');
*cl = '\0'; /* Lose closing paren */
cmd_add_alt(cmd, d, &alt[1], to);
}
if (cmd->info == BY_PATH) {
if (!strcmp(to, "**DIRECTORY**")) {
to = "^^DIRECTORY^^";
}
}
if (cmd->info == BY_ENCODING) {
char *tmp = apr_pstrdup(cmd->pool, to);
ap_str_tolower(tmp);
to = tmp;
}
push_item(((glusterfs_dir_config_t *) d)->icon_list, cmd->info, to,
cmd->path, iconbak);
return NULL;
}
static void *
mod_glfs_create_dir_config(apr_pool_t *p, char *dirspec)
{
glusterfs_dir_config_t *dir_config = NULL;
dir_config = (glusterfs_dir_config_t *) apr_pcalloc(p, sizeof(*dir_config));
dir_config->mount_dir = dirspec;
dir_config->logfile = dir_config->specfile = (char *)0;
dir_config->loglevel = "warning";
dir_config->handle = (libglusterfs_handle_t) 0;
dir_config->cache_timeout = 0;
dir_config->buf = NULL;
/* mod_dir options init */
dir_config->index_names = NULL;
dir_config->do_slash = SLASH_UNSET;
/* autoindex options init */
dir_config->icon_width = 0;
dir_config->icon_height = 0;
dir_config->name_width = DEFAULT_NAME_WIDTH;
dir_config->name_adjust = K_UNSET;
dir_config->desc_width = DEFAULT_DESC_WIDTH;
dir_config->desc_adjust = K_UNSET;
dir_config->icon_list = apr_array_make(p, 4, sizeof(struct mod_glfs_ai_item));
dir_config->alt_list = apr_array_make(p, 4, sizeof(struct mod_glfs_ai_item));
dir_config->desc_list = apr_array_make(p, 4, sizeof(mod_glfs_ai_desc_t));
dir_config->ign_list = apr_array_make(p, 4, sizeof(struct mod_glfs_ai_item));
dir_config->hdr_list = apr_array_make(p, 4, sizeof(struct mod_glfs_ai_item));
dir_config->rdme_list = apr_array_make(p, 4, sizeof(struct mod_glfs_ai_item));
dir_config->opts = 0;
dir_config->incremented_opts = 0;
dir_config->decremented_opts = 0;
dir_config->default_keyid = '\0';
dir_config->default_direction = '\0';
return (void *) dir_config;
}
static void *
mod_glfs_merge_dir_config(apr_pool_t *p, void *parent_conf,
void *newloc_conf)
{
glusterfs_dir_config_t *new = (glusterfs_dir_config_t *)
apr_pcalloc(p, sizeof(glusterfs_dir_config_t));
glusterfs_dir_config_t *add = newloc_conf;
glusterfs_dir_config_t *base = parent_conf;
if (add->logfile)
new->logfile = apr_pstrdup (p, add->logfile);
if (add->loglevel)
new->loglevel = apr_pstrdup (p, add->loglevel);
if (add->specfile)
new->specfile = apr_pstrdup (p, add->specfile);
if (add->mount_dir)
new->mount_dir = apr_pstrdup (p, add->mount_dir);
new->xattr_file_size = add->xattr_file_size;
new->cache_timeout = add->cache_timeout;
new->handle = add->handle;
new->buf = add->buf;
/* mod_dir */
new->index_names = add->index_names ? add->index_names : base->index_names;
new->do_slash =
(add->do_slash == SLASH_UNSET) ? base->do_slash : add->do_slash;
/* auto index */
new->default_icon = add->default_icon ? add->default_icon
: base->default_icon;
new->style_sheet = add->style_sheet ? add->style_sheet
: base->style_sheet;
new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
new->ctype = add->ctype ? add->ctype : base->ctype;
new->charset = add->charset ? add->charset : base->charset;
new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
new->ign_list = apr_array_append(p, add->ign_list, base->ign_list);
new->hdr_list = apr_array_append(p, add->hdr_list, base->hdr_list);
new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
new->rdme_list = apr_array_append(p, add->rdme_list, base->rdme_list);
if (add->opts & NO_OPTIONS) {
/*
* If the current directory says 'no options' then we also
* clear any incremental mods from being inheritable further down.
*/
new->opts = NO_OPTIONS;
new->incremented_opts = 0;
new->decremented_opts = 0;
}
else {
/*
* If there were any nonincremental options selected for
* this directory, they dominate and we don't inherit *anything.*
* Contrariwise, we *do* inherit if the only settings here are
* incremental ones.
*/
if (add->opts == 0) {
new->incremented_opts = (base->incremented_opts
| add->incremented_opts)
& ~add->decremented_opts;
new->decremented_opts = (base->decremented_opts
| add->decremented_opts);
/*
* We may have incremental settings, so make sure we don't
* inadvertently inherit an IndexOptions None from above.
*/
new->opts = (base->opts & ~NO_OPTIONS);
}
else {
/*
* There are local nonincremental settings, which clear
* all inheritance from above. They *are* the new base settings.
*/
new->opts = add->opts;;
}
/*
* We're guaranteed that there'll be no overlap between
* the add-options and the remove-options.
*/
new->opts |= new->incremented_opts;
new->opts &= ~new->decremented_opts;
}
/*
* Inherit the NameWidth settings if there aren't any specific to
* the new location; otherwise we'll end up using the defaults set in the
* config-rec creation routine.
*/
if (add->name_adjust == K_UNSET) {
new->name_width = base->name_width;
new->name_adjust = base->name_adjust;
}
else {
new->name_width = add->name_width;
new->name_adjust = add->name_adjust;
}
/*
* Likewise for DescriptionWidth.
*/
if (add->desc_adjust == K_UNSET) {
new->desc_width = base->desc_width;
new->desc_adjust = base->desc_adjust;
}
else {
new->desc_width = add->desc_width;
new->desc_adjust = add->desc_adjust;
}
new->default_keyid = add->default_keyid ? add->default_keyid
: base->default_keyid;
new->default_direction = add->default_direction ? add->default_direction
: base->default_direction;
return (void *) new;
}
static void
mod_glfs_child_init(apr_pool_t *p, server_rec *s)
{
int i;
core_server_config *sconf = NULL;
ap_conf_vector_t **sec_ent = NULL;
glusterfs_dir_config_t *dir_config = NULL;
glusterfs_init_ctx_t ctx;
int num_sec = 0;
sconf = (core_server_config *) ap_get_module_config (s->module_config, &core_module);
sec_ent = (ap_conf_vector_t **) sconf->sec_url->elts;
num_sec = sconf->sec_url->nelts;
for (i = 0; i < num_sec; i++) {
dir_config = ap_get_module_config (sec_ent[i], &glusterfs_module);
if (dir_config) {
memset (&ctx, 0, sizeof (ctx));
ctx.logfile = dir_config->logfile;
ctx.loglevel = dir_config->loglevel;
ctx.lookup_timeout = ctx.stat_timeout = dir_config->cache_timeout;
ctx.specfile = dir_config->specfile;
dir_config->handle = glusterfs_init (&ctx);
if (!dir_config->handle) {
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
"mod_glfs_child_init: glusterfs_init failed, check glusterfs logfile %s for more details",
dir_config->logfile);
}
}
dir_config = NULL;
}
}
static void
mod_glfs_child_exit(server_rec *s, apr_pool_t *p)
{
int i;
core_server_config *sconf = ap_get_module_config(s->module_config,
&core_module);
ap_conf_vector_t **sec_ent = (ap_conf_vector_t **) sconf->sec_url->elts;
glusterfs_dir_config_t *dir_config = NULL;
glusterfs_init_ctx_t ctx;
int num_sec = sconf->sec_url->nelts;
for (i = 0; i < num_sec; i++) {
dir_config = ap_get_module_config (sec_ent[i], &glusterfs_module);
if (dir_config && dir_config->handle) {
glusterfs_fini (dir_config->handle);
dir_config->handle = 0;
}
dir_config = NULL;
}
}
static apr_filetype_e filetype_from_mode(mode_t mode)
{
apr_filetype_e type = APR_NOFILE;
if (S_ISREG(mode))
type = APR_REG;
else if (S_ISDIR(mode))
type = APR_DIR;
else if (S_ISCHR(mode))
type = APR_CHR;
else if (S_ISBLK(mode))
type = APR_BLK;
else if (S_ISFIFO(mode))
type = APR_PIPE;
else if (S_ISLNK(mode))
type = APR_LNK;
else if (S_ISSOCK(mode))
type = APR_SOCK;
else
type = APR_UNKFILE;
return type;
}
static void fill_out_finfo(apr_finfo_t *finfo, struct stat *info,
apr_int32_t wanted)
{
finfo->valid = APR_FINFO_MIN | APR_FINFO_IDENT | APR_FINFO_NLINK
| APR_FINFO_OWNER | APR_FINFO_PROT;
finfo->protection = apr_unix_mode2perms(info->st_mode);
finfo->filetype = filetype_from_mode(info->st_mode);
finfo->user = info->st_uid;
finfo->group = info->st_gid;
finfo->size = info->st_size;
finfo->device = info->st_dev;
finfo->nlink = info->st_nlink;
/* Check for overflow if storing a 64-bit st_ino in a 32-bit
* apr_ino_t for LFS builds: */
if (sizeof(apr_ino_t) >= sizeof(info->st_ino)
|| (apr_ino_t)info->st_ino == info->st_ino) {
finfo->inode = info->st_ino;
} else {
finfo->valid &= ~APR_FINFO_INODE;
}
apr_time_ansi_put(&finfo->atime, info->st_atime);
#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
finfo->atime += info->st_atim.tv_nsec / APR_TIME_C(1000);
#elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC)
finfo->atime += info->st_atimensec / APR_TIME_C(1000);
#elif defined(HAVE_STRUCT_STAT_ST_ATIME_N)
finfo->ctime += info->st_atime_n / APR_TIME_C(1000);
#endif
apr_time_ansi_put(&finfo->mtime, info->st_mtime);
#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
finfo->mtime += info->st_mtim.tv_nsec / APR_TIME_C(1000);
#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
finfo->mtime += info->st_mtimensec / APR_TIME_C(1000);
#elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
finfo->ctime += info->st_mtime_n / APR_TIME_C(1000);
#endif
apr_time_ansi_put(&finfo->ctime, info->st_ctime);
#ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC
finfo->ctime += info->st_ctim.tv_nsec / APR_TIME_C(1000);
#elif defined(HAVE_STRUCT_STAT_ST_CTIMENSEC)
finfo->ctime += info->st_ctimensec / APR_TIME_C(1000);
#elif defined(HAVE_STRUCT_STAT_ST_CTIME_N)
finfo->ctime += info->st_ctime_n / APR_TIME_C(1000);
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
#ifdef DEV_BSIZE
finfo->csize = (apr_off_t)info->st_blocks * (apr_off_t)DEV_BSIZE;
#else
finfo->csize = (apr_off_t)info->st_blocks * (apr_off_t)512;
#endif
finfo->valid |= APR_FINFO_CSIZE;
#endif
}
static int
mod_glfs_map_to_storage(request_rec *r)
{
glusterfs_dir_config_t *dir_config = NULL, *tmp = NULL;
int access_status;
int ret;
char *path = NULL;
struct stat st = {0, };
core_server_config *sconf = NULL;
ap_conf_vector_t **sec_ent = NULL;
int num_sec = 0, i = 0;
sconf = (core_server_config *) ap_get_module_config (r->server->module_config, &core_module);
sec_ent = (ap_conf_vector_t **) sconf->sec_url->elts;
num_sec = sconf->sec_url->nelts;
for (i = 0; i < num_sec; i++) {
tmp = ap_get_module_config (sec_ent[i], &glusterfs_module);
if (tmp && !strncmp (tmp->mount_dir, r->uri, strlen (tmp->mount_dir))) {
if (!dir_config ||
strlen (tmp->mount_dir) > strlen (dir_config->mount_dir)) {
dir_config = tmp;
}
}
}
if (dir_config && dir_config->mount_dir && !(strncmp (apr_pstrcat (r->pool, dir_config->mount_dir, "/", NULL), r->uri, strlen (dir_config->mount_dir) + 1) && !r->handler))
r->handler = GLUSTERFS_HANDLER; //apr_pstrdup (r->pool, GLUSTERFS_HANDLER);
if (!r->handler || (r->handler && strcmp (r->handler, GLUSTERFS_HANDLER)))
return DECLINED;
if (dir_config->mount_dir)
path = r->uri + strlen (dir_config->mount_dir);
memset (&r->finfo, 0, sizeof (r->finfo));
dir_config->buf = calloc (1, dir_config->xattr_file_size);
if (!dir_config->buf) {
return HTTP_INTERNAL_SERVER_ERROR;
}
if (!dir_config->handle) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r,
"mod_glfs_map_to_storage: glusterfs handle is NULL, check glusterfs logfile %s",
dir_config->logfile);
return HTTP_INTERNAL_SERVER_ERROR;
}
ret = glusterfs_lookup (dir_config->handle, path, dir_config->buf,
dir_config->xattr_file_size, &st);
if (ret == -1 || st.st_size > dir_config->xattr_file_size || S_ISDIR (st.st_mode)) {
free (dir_config->buf);
dir_config->buf = NULL;
if (ret == -1) {
int error = HTTP_NOT_FOUND;
char *emsg = NULL;
if (r->path_info == NULL) {
emsg = apr_pstrcat(r->pool, strerror (errno), r->filename, NULL);
}
else {
emsg = apr_pstrcat(r->pool, strerror (errno), r->filename, r->path_info, NULL);
}
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, "%s", emsg);
if (errno != ENOENT) {
error = HTTP_INTERNAL_SERVER_ERROR;
}
return error;
}
}
r->finfo.pool = r->pool;
r->finfo.fname = r->filename;
fill_out_finfo (&r->finfo, &st,
APR_FINFO_MIN | APR_FINFO_IDENT | APR_FINFO_NLINK | APR_FINFO_OWNER | APR_FINFO_PROT);
/* r->filename = apr_pstrcat (r->pool, r->filename, r->path_info, NULL); */
/* allow core module to run directory_walk() and location_walk() */
return DECLINED;
}
static int
mod_glfs_readv_async_cbk (glusterfs_read_buf_t *buf,
void *cbk_data)
{
glusterfs_async_local_t *local = cbk_data;
pthread_mutex_lock (&local->lock);
{
local->async_read_complete = 1;
local->buf = buf;
pthread_cond_signal (&local->cond);
}
pthread_mutex_unlock (&local->lock);
return 0;
}
/* use read_async just to avoid memcpy of read buffer in libglusterfsclient */
static int
mod_glfs_read_async (request_rec *r, apr_bucket_brigade *bb, long fd, apr_off_t offset, apr_off_t length)
{
glusterfs_async_local_t local;
off_t end;
int nbytes;
int complete;
conn_rec *c = r->connection;
apr_bucket *e = NULL;
apr_status_t status;
if (length == 0) {
return 0;
}
pthread_cond_init (&local.cond, NULL);
pthread_mutex_init (&local.lock, NULL);
memset (&local, 0, sizeof (local));
local.request = r;
if (length > 0)
end = offset + length;
do {
glusterfs_read_buf_t *buf;
if (length > 0) {
nbytes = end - offset;
if (nbytes > GLUSTERFS_CHUNK_SIZE)
nbytes = GLUSTERFS_CHUNK_SIZE;
} else
nbytes = GLUSTERFS_CHUNK_SIZE;
glusterfs_read_async(fd,
nbytes,
offset,
mod_glfs_readv_async_cbk,
(void *)&local);
pthread_mutex_lock (&local.lock);
{
while (!local.async_read_complete) {
pthread_cond_wait (&local.cond, &local.lock);
}
local.op_ret = local.buf->op_ret;
local.op_errno = local.buf->op_errno;
local.async_read_complete = 0;
buf = local.buf;
if (length < 0)
complete = (local.buf->op_ret <= 0);
else {
local.read_bytes += local.buf->op_ret;
complete = ((local.read_bytes == length) || (local.buf->op_ret < 0));
}
}
pthread_mutex_unlock (&local.lock);
if (!bb) {
bb = apr_brigade_create (r->pool, c->bucket_alloc);
}
apr_brigade_writev (bb, NULL, NULL, buf->vector, buf->count);
/* make sure all the data is written out, since we call glusterfs_free on buf once
ap_pass_brigade returns */
e = apr_bucket_flush_create (c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL (bb, e);
status = ap_pass_brigade (r->output_filters, bb);
if (status != APR_SUCCESS) {
/* no way to know what type of error occurred */
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r,
"mod_glfs_handler: ap_pass_brigade returned %i",
status);
complete = 1;
local.op_ret = -1;
}
glusterfs_free (buf);
/* bb has already been cleaned up by core_output_filter, just being paranoid */
apr_brigade_cleanup (bb);
offset += nbytes;
} while (!complete);
return (local.op_ret < 0 ? HTTP_INTERNAL_SERVER_ERROR : OK);
}
/* TODO: to read blocks of size "length" from offset "offset" */
/*
static int
mod_glfs_read_sync (request_rec *r, int fd, off_t offset, off_t length)
{
int error = OK;
off_t read_bytes;
char buf [GLUSTERFS_CHUNK_SIZE];
while ((read_bytes = glusterfs_read (fd, buf, GLUSTERFS_CHUNK_SIZE)) && read_bytes != -1) {
ap_rwrite (buf, read_bytes, r);
}
if (read_bytes) {
error = SERVER_ERROR;
}
return error;
}
*/
static int
parse_byterange(char *range, apr_off_t clength,
apr_off_t *start, apr_off_t *end)
{
char *dash = strchr(range, '-');
char *errp;
apr_off_t number;
if (!dash) {
return 0;
}
if ((dash == range)) {
/* In the form "-5" */
if (apr_strtoff(&number, dash+1, &errp, 10) || *errp) {
return 0;
}
*start = clength - number;
*end = clength - 1;
}
else {
*dash++ = '\0';
if (apr_strtoff(&number, range, &errp, 10) || *errp) {
return 0;
}
*start = number;
if (*dash) {
if (apr_strtoff(&number, dash, &errp, 10) || *errp) {
return 0;
}
*end = number;
}
else { /* "5-" */
*end = clength - 1;
}
}
if (*start < 0) {
*start = 0;
}
if (*end >= clength) {
*end = clength - 1;
}
if (*start > *end) {
return -1;
}
return (*start > 0 || *end < clength);
}
static int use_range_x(request_rec *r)
{
const char *ua;
return (apr_table_get(r->headers_in, "Request-Range")
|| ((ua = apr_table_get(r->headers_in, "User-Agent"))
&& ap_strstr_c(ua, "MSIE 3")));
}
static int ap_set_byterange(request_rec *r)
{
const char *range;
const char *if_range;
const char *match;
const char *ct;
int num_ranges;
if (r->assbackwards) {
return 0;
}
/* Check for Range request-header (HTTP/1.1) or Request-Range for
* backwards-compatibility with second-draft Luotonen/Franks
* byte-ranges (e.g. Netscape Navigator 2-3).
*
* We support this form, with Request-Range, and (farther down) we
* send multipart/x-byteranges instead of multipart/byteranges for
* Request-Range based requests to work around a bug in Netscape
* Navigator 2-3 and MSIE 3.
*/
if (!(range = apr_table_get(r->headers_in, "Range"))) {
range = apr_table_get(r->headers_in, "Request-Range");
}
if (!range || strncasecmp(range, "bytes=", 6) || r->status != HTTP_OK) {
return 0;
}
/* is content already a single range? */
if (apr_table_get(r->headers_out, "Content-Range")) {
return 0;
}
/* is content already a multiple range? */
if ((ct = apr_table_get(r->headers_out, "Content-Type"))
&& (!strncasecmp(ct, "multipart/byteranges", 20)
|| !strncasecmp(ct, "multipart/x-byteranges", 22))) {
return 0;
}
/* Check the If-Range header for Etag or Date.
* Note that this check will return false (as required) if either
* of the two etags are weak.
*/
if ((if_range = apr_table_get(r->headers_in, "If-Range"))) {
if (if_range[0] == '"') {
if (!(match = apr_table_get(r->headers_out, "Etag"))
|| (strcmp(if_range, match) != 0)) {
return 0;
}
}
else if (!(match = apr_table_get(r->headers_out, "Last-Modified"))
|| (strcmp(if_range, match) != 0)) {
return 0;
}
}
if (!ap_strchr_c(range, ',')) {
/* a single range */
num_ranges = 1;
}
else {
/* a multiple range */
num_ranges = 2;
}
r->status = HTTP_PARTIAL_CONTENT;
r->range = range + 6;
return num_ranges;
}
static void
mod_glfs_handle_byte_ranges (request_rec *r, long fd, int num_ranges)
{
conn_rec *c = r->connection;
char *boundary = NULL, *bound_head = NULL;
const char *orig_ct = NULL;
apr_bucket_brigade *bsend = NULL;
apr_bucket *e = NULL;
apr_off_t range_start;
apr_off_t range_end;
char *current = NULL;
apr_status_t rv;
char found = 0;
orig_ct = ap_make_content_type (r, r->content_type);
if (num_ranges > 1) {
boundary = apr_psprintf(r->pool, "%" APR_UINT64_T_HEX_FMT "%lx",
(apr_uint64_t)r->request_time, (long) getpid());
ap_set_content_type(r, apr_pstrcat(r->pool, "multipart",
use_range_x(r) ? "/x-" : "/",
"byteranges; boundary=",
boundary, NULL));
if (strcasecmp(orig_ct, NO_CONTENT_TYPE)) {
bound_head = apr_pstrcat(r->pool,
CRLF "--", boundary,
CRLF "Content-type: ",
orig_ct,
CRLF "Content-range: bytes ",
NULL);
}
else {
/* if we have no type for the content, do our best */
bound_head = apr_pstrcat(r->pool,
CRLF "--", boundary,
CRLF "Content-range: bytes ",
NULL);
}
// ap_xlate_proto_to_ascii(bound_head, strlen(bound_head));
}
while ((current = ap_getword(r->pool, &r->range, ','))
&& (rv = parse_byterange(current, r->finfo.size, &range_start,
&range_end))) {
apr_bucket *e2;
apr_bucket *ec;
bsend = NULL;
if (rv == -1) {
continue;
}
found = 1;
/* For single range requests, we must produce Content-Range header.
* Otherwise, we need to produce the multipart boundaries.
*/
if (num_ranges == 1) {
apr_table_setn(r->headers_out, "Content-Range",
apr_psprintf(r->pool, "bytes " BYTERANGE_FMT,
range_start, range_end, r->finfo.size));
}
else {
char *ts;
/* this brigade holds what we will be sending */
bsend = apr_brigade_create(r->pool, c->bucket_alloc);
e = apr_bucket_pool_create(bound_head, strlen(bound_head),
r->pool, c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bsend, e);
ts = apr_psprintf(r->pool, BYTERANGE_FMT CRLF CRLF,
range_start, range_end, r->finfo.size);
// ap_xlate_proto_to_ascii(ts, strlen(ts));
e = apr_bucket_pool_create(ts, strlen(ts), r->pool,
c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bsend, e);
}
mod_glfs_read_async (r, bsend, fd, range_start, (range_end + 1 - range_start));
}
bsend = apr_brigade_create (r->pool, c->bucket_alloc);
if (found == 0) {
r->status = HTTP_OK;
/* bsend is assumed to be empty if we get here. */
e = ap_bucket_error_create(HTTP_RANGE_NOT_SATISFIABLE, NULL,
r->pool, c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bsend, e);
e = apr_bucket_eos_create(c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bsend, e);
ap_pass_brigade (r->output_filters, bsend);
return;
}
if (num_ranges > 1) {
char *end;
/* add the final boundary */
end = apr_pstrcat(r->pool, CRLF "--", boundary, "--" CRLF, NULL);
// ap_xlate_proto_to_ascii(end, strlen(end));
e = apr_bucket_pool_create(end, strlen(end), r->pool, c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bsend, e);
}
ap_pass_brigade (r->output_filters, bsend);
}
/****************************************************************
*
* Looking things up in config entries...
*/
/* Structure used to hold entries when we're actually building an index */
struct ent {
char *name;
char *icon;
char *alt;
char *desc;
apr_off_t size;
apr_time_t lm;
struct ent *next;
int ascending, ignore_case, version_sort;
char key;
int isdir;
};
static char *find_item(request_rec *r, apr_array_header_t *list, int path_only)
{
const char *content_type = ap_field_noparam(r->pool, r->content_type);
const char *content_encoding = r->content_encoding;
char *path = r->filename;
struct mod_glfs_ai_item *items = (struct mod_glfs_ai_item *) list->elts;
int i;
for (i = 0; i < list->nelts; ++i) {
struct mod_glfs_ai_item *p = &items[i];
/* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
if (!*(p->apply_to)) {
return p->data;
}
else if (p->type == BY_PATH || path[0] == '^') {
if (!ap_strcmp_match(path, p->apply_to)) {
return p->data;
}
}
else if (!path_only) {
if (!content_encoding) {
if (p->type == BY_TYPE) {
if (content_type
&& !ap_strcasecmp_match(content_type,
p->apply_to)) {
return p->data;
}
}
}
else {
if (p->type == BY_ENCODING) {
if (!ap_strcasecmp_match(content_encoding,
p->apply_to)) {
return p->data;
}
}
}
}
}
}
return NULL;
}
#define find_icon(d,p,t) find_item(p,d->icon_list,t)
#define find_alt(d,p,t) find_item(p,d->alt_list,t)
#define find_header(d,p) find_item(p,d->hdr_list,0)
#define find_readme(d,p) find_item(p,d->rdme_list,0)
static char *find_default_item(char *bogus_name, apr_array_header_t *list)
{
request_rec r;
/* Bleah. I tried to clean up find_item, and it lead to this bit
* of ugliness. Note that the fields initialized are precisely
* those that find_item looks at...
*/
r.filename = bogus_name;
r.content_type = r.content_encoding = NULL;
return find_item(&r, list, 1);
}
#define find_default_icon(d,n) find_default_item(n, d->icon_list)
#define find_default_alt(d,n) find_default_item(n, d->alt_list)
/*
* Look through the list of pattern/description pairs and return the first one
* if any) that matches the filename in the request. If multiple patterns
* match, only the first one is used; since the order in the array is the
* same as the order in which directives were processed, earlier matching
* directives will dominate.
*/
#ifdef CASE_BLIND_FILESYSTEM
#define MATCH_FLAGS APR_FNM_CASE_BLIND
#else
#define MATCH_FLAGS 0
#endif
static char *find_desc(glusterfs_dir_config_t *dcfg, const char *filename_full)
{
int i;
mod_glfs_ai_desc_t *list = (mod_glfs_ai_desc_t *) dcfg->desc_list->elts;
const char *filename_only;
const char *filename;
/*
* If the filename includes a path, extract just the name itself
* for the simple matches.
*/
if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
filename_only = filename_full;
}
else {
filename_only++;
}
for (i = 0; i < dcfg->desc_list->nelts; ++i) {
mod_glfs_ai_desc_t *tuple = &list[i];
int found;
/*
* Only use the full-path filename if the pattern contains '/'s.
*/
filename = (tuple->full_path) ? filename_full : filename_only;
/*
* Make the comparison using the cheapest method; only do
* wildcard checking if we must.
*/
if (tuple->wildcards) {
found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
}
else {
found = (ap_strstr_c(filename, tuple->pattern) != NULL);
}
if (found) {
return tuple->description;
}
}
return NULL;
}
static int ignore_entry(glusterfs_dir_config_t *d, char *path)
{
apr_array_header_t *list = d->ign_list;
struct mod_glfs_ai_item *items = (struct mod_glfs_ai_item *) list->elts;
char *tt;
int i;
if ((tt = strrchr(path, '/')) == NULL) {
tt = path;
}
else {
tt++;
}
for (i = 0; i < list->nelts; ++i) {
struct mod_glfs_ai_item *p = &items[i];
char *ap;
if ((ap = strrchr(p->apply_to, '/')) == NULL) {
ap = p->apply_to;
}
else {
ap++;
}
#ifndef CASE_BLIND_FILESYSTEM
if (!ap_strcmp_match(path, p->apply_path)
&& !ap_strcmp_match(tt, ap)) {
return 1;
}
#else /* !CASE_BLIND_FILESYSTEM */
/*
* On some platforms, the match must be case-blind. This is really
* a factor of the filesystem involved, but we can't detect that
* reliably - so we have to granularise at the OS level.
*/
if (!ap_strcasecmp_match(path, p->apply_path)
&& !ap_strcasecmp_match(tt, ap)) {
return 1;
}
#endif /* !CASE_BLIND_FILESYSTEM */
}
return 0;
}
/*****************************************************************
*
* Actually generating output
*/
/*
* Elements of the emitted document:
* Preamble
* Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
* succeeds for the (content_type == text/html) header file.
* Header file
* Emitted if found (and able).
* H1 tag line
* Emitted if a header file is NOT emitted.
* Directory stuff
* Always emitted.
* HR
* Emitted if FANCY_INDEXING is set.
* Readme file
* Emitted if found (and able).
* ServerSig
* Emitted if ServerSignature is not Off AND a readme file
* is NOT emitted.
* Postamble
* Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
* succeeds for the (content_type == text/html) readme file.
*/
/*
* emit a plain text file
*/
static void do_emit_plain(request_rec *r, apr_file_t *f)
{
char buf[AP_IOBUFSIZE + 1];
int ch;
apr_size_t i, c, n;
apr_status_t rv;
ap_rputs("<pre>\n", r);
while (!apr_file_eof(f)) {
do {
n = sizeof(char) * AP_IOBUFSIZE;
rv = apr_file_read(f, buf, &n);
} while (APR_STATUS_IS_EINTR(rv));
if (n == 0 || rv != APR_SUCCESS) {
/* ###: better error here? */
break;
}
buf[n] = '\0';
c = 0;
while (c < n) {
for (i = c; i < n; i++) {
if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
break;
}
}
ch = buf[i];
buf[i] = '\0';
ap_rputs(&buf[c], r);
if (ch == '<') {
ap_rputs("<", r);
}
else if (ch == '>') {
ap_rputs(">", r);
}
else if (ch == '&') {
ap_rputs("&", r);
}
c = i + 1;
}
}
ap_rputs("</pre>\n", r);
}
/*
* Handle the preamble through the H1 tag line, inclusive. Locate
* the file with a subrequests. Process text/html documents by actually
* running the subrequest; text/xxx documents get copied verbatim,
* and any other content type is ignored. This means that a non-text
* document (such as HEADER.gif) might get multiviewed as the result
* instead of a text document, meaning nothing will be displayed, but
* oh well.
*/
static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
int emit_xhtml, char *title)
{
apr_table_t *hdrs = r->headers_in;
apr_file_t *f = NULL;
request_rec *rr = NULL;
int emit_amble = 1;
int emit_H1 = 1;
const char *r_accept;
const char *r_accept_enc;
/*
* If there's a header file, send a subrequest to look for it. If it's
* found and html do the subrequest, otherwise handle it
*/
r_accept = apr_table_get(hdrs, "Accept");
r_accept_enc = apr_table_get(hdrs, "Accept-Encoding");
apr_table_setn(hdrs, "Accept", "text/html, text/plain");
apr_table_unset(hdrs, "Accept-Encoding");
if ((header_fname != NULL) && r->args) {
header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
}
if ((header_fname != NULL)
&& (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters))
&& (rr->status == HTTP_OK)
&& (rr->filename != NULL)
&& (rr->finfo.filetype == APR_REG)) {
/*
* Check for the two specific cases we allow: text/html and
* text/anything-else. The former is allowed to be processed for
* SSIs.
*/
if (rr->content_type != NULL) {
if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
"text/html")) {
ap_filter_t *f;
/* Hope everything will work... */
emit_amble = 0;
emit_H1 = 0;
if (! suppress_amble) {
emit_preamble(r, emit_xhtml, title);
}
/* This is a hack, but I can't find any better way to do this.
* The problem is that we have already created the sub-request,
* but we just inserted the OLD_WRITE filter, and the
* sub-request needs to pass its data through the OLD_WRITE
* filter, or things go horribly wrong (missing data, data in
* the wrong order, etc). To fix it, if you create a
* sub-request and then insert the OLD_WRITE filter before you
* run the request, you need to make sure that the sub-request
* data goes through the OLD_WRITE filter. Just steal this
* code. The long-term solution is to remove the ap_r*
* functions.
*/
for (f=rr->output_filters;
f->frec != ap_subreq_core_filter_handle; f = f->next);
f->next = r->output_filters;
/*
* If there's a problem running the subrequest, display the
* preamble if we didn't do it before -- the header file
* didn't get displayed.
*/
if (ap_run_sub_req(rr) != OK) {
/* It didn't work */
emit_amble = suppress_amble;
emit_H1 = 1;
}
}
else if (!strncasecmp("text/", rr->content_type, 5)) {
/*
* If we can open the file, prefix it with the preamble
* regardless; since we'll be sending a <pre> block around
* the file's contents, any HTML header it had won't end up
* where it belongs.
*/
if (apr_file_open(&f, rr->filename, APR_READ,
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
emit_preamble(r, emit_xhtml, title);
emit_amble = 0;
do_emit_plain(r, f);
apr_file_close(f);
emit_H1 = 0;
}
}
}
}
if (r_accept) {
apr_table_setn(hdrs, "Accept", r_accept);
}
else {
apr_table_unset(hdrs, "Accept");
}
if (r_accept_enc) {
apr_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
}
if (emit_amble) {
emit_preamble(r, emit_xhtml, title);
}
if (emit_H1) {
ap_rvputs(r, "<h1>Index of ", title, "</h1>\n", NULL);
}
if (rr != NULL) {
ap_destroy_sub_req(rr);
}
}
/*
* Handle the Readme file through the postamble, inclusive. Locate
* the file with a subrequests. Process text/html documents by actually
* running the subrequest; text/xxx documents get copied verbatim,
* and any other content type is ignored. This means that a non-text
* document (such as FOOTER.gif) might get multiviewed as the result
* instead of a text document, meaning nothing will be displayed, but
* oh well.
*/
static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
{
apr_file_t *f = NULL;
request_rec *rr = NULL;
int suppress_post = 0;
int suppress_sig = 0;
/*
* If there's a readme file, send a subrequest to look for it. If it's
* found and a text file, handle it -- otherwise fall through and
* pretend there's nothing there.
*/
if ((readme_fname != NULL)
&& (rr = ap_sub_req_lookup_uri(readme_fname, r, r->output_filters))
&& (rr->status == HTTP_OK)
&& (rr->filename != NULL)
&& rr->finfo.filetype == APR_REG) {
/*
* Check for the two specific cases we allow: text/html and
* text/anything-else. The former is allowed to be processed for
* SSIs.
*/
if (rr->content_type != NULL) {
if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
"text/html")) {
ap_filter_t *f;
for (f=rr->output_filters;
f->frec != ap_subreq_core_filter_handle; f = f->next);
f->next = r->output_filters;
if (ap_run_sub_req(rr) == OK) {
/* worked... */
suppress_sig = 1;
suppress_post = suppress_amble;
}
}
else if (!strncasecmp("text/", rr->content_type, 5)) {
/*
* If we can open the file, suppress the signature.
*/
if (apr_file_open(&f, rr->filename, APR_READ,
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
do_emit_plain(r, f);
apr_file_close(f);
suppress_sig = 1;
}
}
}
}
if (!suppress_sig) {
ap_rputs(ap_psignature("", r), r);
}
if (!suppress_post) {
ap_rputs("</body></html>\n", r);
}
if (rr != NULL) {
ap_destroy_sub_req(rr);
}
}
static char *find_title(request_rec *r)
{
char titlebuf[MAX_STRING_LEN], *find = "<title>";
apr_file_t *thefile = NULL;
int x, y, p;
apr_size_t n;
if (r->status != HTTP_OK) {
return NULL;
}
if ((r->content_type != NULL)
&& (!strcasecmp(ap_field_noparam(r->pool, r->content_type),
"text/html")
|| !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
&& !r->content_encoding) {
if (apr_file_open(&thefile, r->filename, APR_READ,
APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
return NULL;
}
n = sizeof(char) * (MAX_STRING_LEN - 1);
apr_file_read(thefile, titlebuf, &n);
if (n <= 0) {
apr_file_close(thefile);
return NULL;
}
titlebuf[n] = '\0';
for (x = 0, p = 0; titlebuf[x]; x++) {
if (apr_tolower(titlebuf[x]) == find[p]) {
if (!find[++p]) {
if ((p = ap_ind(&titlebuf[++x], '<')) != -1) {
titlebuf[x + p] = '\0';
}
/* Scan for line breaks for Tanmoy's secretary */
for (y = x; titlebuf[y]; y++) {
if ((titlebuf[y] == CR) || (titlebuf[y] == LF)) {
if (y == x) {
x++;
}
else {
titlebuf[y] = ' ';
}
}
}
apr_file_close(thefile);
return apr_pstrdup(r->pool, &titlebuf[x]);
}
}
else {
p = 0;
}
}
apr_file_close(thefile);
}
return NULL;
}
static struct ent *make_parent_entry(apr_int32_t autoindex_opts,
glusterfs_dir_config_t *d,
request_rec *r, char keyid,
char direction)
{
struct ent *p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
char *testpath;
/*
* p->name is now the true parent URI.
* testpath is a crafted lie, so that the syntax '/some/..'
* (or simply '..')be used to describe 'up' from '/some/'
* when processeing IndexIgnore, and Icon|Alt|Desc configs.
*/
/* The output has always been to the parent. Don't make ourself
* our own parent (worthless cyclical reference).
*/
if (!(p->name = ap_make_full_path(r->pool, r->uri, "../"))) {
return (NULL);
}
ap_getparents(p->name);
if (!*p->name) {
return (NULL);
}
/* IndexIgnore has always compared "/thispath/.." */
testpath = ap_make_full_path(r->pool, r->filename, "..");
if (ignore_entry(d, testpath)) {
return (NULL);
}
p->size = -1;
p->lm = -1;
p->key = apr_toupper(keyid);
p->ascending = (apr_toupper(direction) == D_ASCENDING);
p->version_sort = autoindex_opts & VERSION_SORT;
if (autoindex_opts & FANCY_INDEXING) {
if (!(p->icon = find_default_icon(d, testpath))) {
p->icon = find_default_icon(d, "^^DIRECTORY^^");
}
if (!(p->alt = find_default_alt(d, testpath))) {
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
p->alt = "DIR";
}
}
p->desc = find_desc(d, testpath);
}
return p;
}
static struct ent *make_autoindex_entry(const apr_finfo_t *dirent,
int autoindex_opts,
glusterfs_dir_config_t *d,
request_rec *r, char keyid,
char direction,
const char *pattern)
{
request_rec *rr;
struct ent *p;
int show_forbidden = 0;
/* Dot is ignored, Parent is handled by make_parent_entry() */
if ((dirent->name[0] == '.') && (!dirent->name[1]
|| ((dirent->name[1] == '.') && !dirent->name[2])))
return (NULL);
/*
* On some platforms, the match must be case-blind. This is really
* a factor of the filesystem involved, but we can't detect that
* reliably - so we have to granularise at the OS level.
*/
if (pattern && (apr_fnmatch(pattern, dirent->name,
APR_FNM_NOESCAPE | APR_FNM_PERIOD
#ifdef CASE_BLIND_FILESYSTEM
| APR_FNM_CASE_BLIND
#endif
)
!= APR_SUCCESS)) {
return (NULL);
}
if (ignore_entry(d, ap_make_full_path(r->pool,
r->filename, dirent->name))) {
return (NULL);
}
if (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, NULL))) {
return (NULL);
}
if((autoindex_opts & SHOW_FORBIDDEN)
&& (rr->status == HTTP_UNAUTHORIZED || rr->status == HTTP_FORBIDDEN)) {
show_forbidden = 1;
}
if ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG)
|| !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status)
|| ap_is_HTTP_REDIRECT(rr->status)
|| show_forbidden == 1)) {
ap_destroy_sub_req(rr);
return (NULL);
}
p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
if (dirent->filetype == APR_DIR) {
p->name = apr_pstrcat(r->pool, dirent->name, "/", NULL);
}
else {
p->name = apr_pstrdup(r->pool, dirent->name);
}
p->size = -1;
p->icon = NULL;
p->alt = NULL;
p->desc = NULL;
p->lm = -1;
p->isdir = 0;
p->key = apr_toupper(keyid);
p->ascending = (apr_toupper(direction) == D_ASCENDING);
p->version_sort = !!(autoindex_opts & VERSION_SORT);
p->ignore_case = !!(autoindex_opts & IGNORE_CASE);
if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {
p->lm = rr->finfo.mtime;
if (dirent->filetype == APR_DIR) {
if (autoindex_opts & FOLDERS_FIRST) {
p->isdir = 1;
}
rr->filename = ap_make_dirstr_parent (rr->pool, rr->filename);
/* omit the trailing slash (1.3 compat) */
rr->filename[strlen(rr->filename) - 1] = '\0';
if (!(p->icon = find_icon(d, rr, 1))) {
p->icon = find_default_icon(d, "^^DIRECTORY^^");
}
if (!(p->alt = find_alt(d, rr, 1))) {
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
p->alt = "DIR";
}
}
}
else {
p->icon = find_icon(d, rr, 0);
p->alt = find_alt(d, rr, 0);
p->size = rr->finfo.size;
}
p->desc = find_desc(d, rr->filename);
if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
p->desc = apr_pstrdup(r->pool, find_title(rr));
}
}
ap_destroy_sub_req(rr);
/*
* We don't need to take any special action for the file size key.
* If we did, it would go here.
*/
if (keyid == K_LAST_MOD) {
if (p->lm < 0) {
p->lm = 0;
}
}
return (p);
}
static char *terminate_description(glusterfs_dir_config_t *d, char *desc,
apr_int32_t autoindex_opts, int desc_width)
{
int maxsize = desc_width;
register int x;
/*
* If there's no DescriptionWidth in effect, default to the old
* behaviour of adjusting the description size depending upon
* what else is being displayed. Otherwise, stick with the
* setting.
*/
if (d->desc_adjust == K_UNSET) {
if (autoindex_opts & SUPPRESS_ICON) {
maxsize += 6;
}
if (autoindex_opts & SUPPRESS_LAST_MOD) {
maxsize += 19;
}
if (autoindex_opts & SUPPRESS_SIZE) {
maxsize += 7;
}
}
for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) {
if (desc[x] == '<') {
while (desc[x] != '>') {
if (!desc[x]) {
maxsize = 0;
break;
}
++x;
}
}
else if (desc[x] == '&') {
/* entities like ä count as one character */
--maxsize;
for ( ; desc[x] != ';'; ++x) {
if (desc[x] == '\0') {
maxsize = 0;
break;
}
}
}
else {
--maxsize;
}
}
if (!maxsize && desc[x] != '\0') {
desc[x - 1] = '>'; /* Grump. */
desc[x] = '\0'; /* Double Grump! */
}
return desc;
}
/*
* Emit the anchor for the specified field. If a field is the key for the
* current request, the link changes its meaning to reverse the order when
* selected again. Non-active fields always start in ascending order.
*/
static void emit_link(request_rec *r, const char *anchor, char column,
char curkey, char curdirection,
const char *colargs, int nosort)
{
if (!nosort) {
char qvalue[9];
qvalue[0] = '?';
qvalue[1] = 'C';
qvalue[2] = '=';
qvalue[3] = column;
qvalue[4] = ';';
qvalue[5] = 'O';
qvalue[6] = '=';
/* reverse? */
qvalue[7] = ((curkey == column) && (curdirection == D_ASCENDING))
? D_DESCENDING : D_ASCENDING;
qvalue[8] = '\0';
ap_rvputs(r, "<a href=\"", qvalue, colargs ? colargs : "",
"\">", anchor, "</a>", NULL);
}
else {
ap_rputs(anchor, r);
}
}
static void output_directories(struct ent **ar, int n,
glusterfs_dir_config_t *d, request_rec *r,
apr_int32_t autoindex_opts, char keyid,
char direction, const char *colargs)
{
int x;
apr_size_t rv;
char *name = r->uri;
char *tp;
int static_columns = !!(autoindex_opts & SUPPRESS_COLSORT);
apr_pool_t *scratch;
int name_width;
int desc_width;
char *name_scratch;
char *pad_scratch;
char *breakrow = "";
apr_pool_create(&scratch, r->pool);
if (name[0] == '\0') {
name = "/";
}
name_width = d->name_width;
desc_width = d->desc_width;
if ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING))
== FANCY_INDEXING) {
if (d->name_adjust == K_ADJUST) {
for (x = 0; x < n; x++) {
int t = strlen(ar[x]->name);
if (t > name_width) {
name_width = t;
}
}
}
if (d->desc_adjust == K_ADJUST) {
for (x = 0; x < n; x++) {
if (ar[x]->desc != NULL) {
int t = strlen(ar[x]->desc);
if (t > desc_width) {
desc_width = t;
}
}
}
}
}
name_scratch = apr_palloc(r->pool, name_width + 1);
pad_scratch = apr_palloc(r->pool, name_width + 1);
memset(pad_scratch, ' ', name_width);
pad_scratch[name_width] = '\0';
if (autoindex_opts & TABLE_INDEXING) {
int cols = 1;
ap_rputs("<table><tr>", r);
if (!(autoindex_opts & SUPPRESS_ICON)) {
ap_rputs("<th>", r);
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
"\" alt=\"[ICO]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("></th>", r);
}
else {
ap_rputs(" </th>", r);
}
++cols;
}
ap_rputs("<th>", r);
emit_link(r, "Name", K_NAME, keyid, direction,
colargs, static_columns);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
ap_rputs("</th><th>", r);
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
ap_rputs("</th><th>", r);
emit_link(r, "Size", K_SIZE, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
ap_rputs("</th><th>", r);
emit_link(r, "Description", K_DESC, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_RULES)) {
breakrow = apr_psprintf(r->pool,
"<tr><th colspan=\"%d\">"
"<hr%s></th></tr>\n", cols,
(autoindex_opts & EMIT_XHTML) ? " /" : "");
}
ap_rvputs(r, "</th></tr>", breakrow, NULL);
}
else if (autoindex_opts & FANCY_INDEXING) {
ap_rputs("<pre>", r);
if (!(autoindex_opts & SUPPRESS_ICON)) {
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
"\" alt=\"Icon \"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("> ", r);
}
else {
ap_rputs(" ", r);
}
}
emit_link(r, "Name", K_NAME, keyid, direction,
colargs, static_columns);
ap_rputs(pad_scratch + 4, r);
/*
* Emit the guaranteed-at-least-one-space-between-columns byte.
*/
ap_rputs(" ", r);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
colargs, static_columns);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
emit_link(r, "Size", K_SIZE, keyid, direction,
colargs, static_columns);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
emit_link(r, "Description", K_DESC, keyid, direction,
colargs, static_columns);
}
if (!(autoindex_opts & SUPPRESS_RULES)) {
ap_rputs("<hr", r);
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputc('\n', r);
}
}
else {
ap_rputs("<ul>", r);
}
for (x = 0; x < n; x++) {
char *anchor, *t, *t2;
int nwidth;
apr_pool_clear(scratch);
t = ar[x]->name;
anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
if (!x && t[0] == '/') {
t2 = "Parent Directory";
}
else {
t2 = t;
}
if (autoindex_opts & TABLE_INDEXING) {
ap_rputs("<tr>", r);
if (!(autoindex_opts & SUPPRESS_ICON)) {
ap_rputs("<td valign=\"top\">", r);
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
}
if ((ar[x]->icon) || d->default_icon) {
ap_rvputs(r, "<img src=\"",
ap_escape_html(scratch,
ar[x]->icon ? ar[x]->icon
: d->default_icon),
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
"]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputs(" ", r);
}
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rputs("</a></td>", r);
}
else {
ap_rputs("</td>", r);
}
}
if (d->name_adjust == K_ADJUST) {
ap_rvputs(r, "<td><a href=\"", anchor, "\">",
ap_escape_html(scratch, t2), "</a>", NULL);
}
else {
nwidth = strlen(t2);
if (nwidth > name_width) {
memcpy(name_scratch, t2, name_width - 3);
name_scratch[name_width - 3] = '.';
name_scratch[name_width - 2] = '.';
name_scratch[name_width - 1] = '>';
name_scratch[name_width] = 0;
t2 = name_scratch;
nwidth = name_width;
}
ap_rvputs(r, "<td><a href=\"", anchor, "\">",
ap_escape_html(scratch, t2),
"</a>", pad_scratch + nwidth, NULL);
}
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
if (ar[x]->lm != -1) {
char time_str[MAX_STRING_LEN];
apr_time_exp_t ts;
apr_time_exp_lt(&ts, ar[x]->lm);
apr_strftime(time_str, &rv, MAX_STRING_LEN,
"</td><td align=\"right\">%d-%b-%Y %H:%M ",
&ts);
ap_rputs(time_str, r);
}
else {
ap_rputs("</td><td> ", r);
}
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
char buf[5];
ap_rvputs(r, "</td><td align=\"right\">",
apr_strfsize(ar[x]->size, buf), NULL);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
if (ar[x]->desc) {
if (d->desc_adjust == K_ADJUST) {
ap_rvputs(r, "</td><td>", ar[x]->desc, NULL);
}
else {
ap_rvputs(r, "</td><td>",
terminate_description(d, ar[x]->desc,
autoindex_opts,
desc_width), NULL);
}
}
}
else {
ap_rputs("</td><td> ", r);
}
ap_rputs("</td></tr>\n", r);
}
else if (autoindex_opts & FANCY_INDEXING) {
if (!(autoindex_opts & SUPPRESS_ICON)) {
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
}
if ((ar[x]->icon) || d->default_icon) {
ap_rvputs(r, "<img src=\"",
ap_escape_html(scratch,
ar[x]->icon ? ar[x]->icon
: d->default_icon),
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
"]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputs(" ", r);
}
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rputs("</a> ", r);
}
else {
ap_rputc(' ', r);
}
}
nwidth = strlen(t2);
if (nwidth > name_width) {
memcpy(name_scratch, t2, name_width - 3);
name_scratch[name_width - 3] = '.';
name_scratch[name_width - 2] = '.';
name_scratch[name_width - 1] = '>';
name_scratch[name_width] = 0;
t2 = name_scratch;
nwidth = name_width;
}
ap_rvputs(r, "<a href=\"", anchor, "\">",
ap_escape_html(scratch, t2),
"</a>", pad_scratch + nwidth, NULL);
/*
* The blank before the storm.. er, before the next field.
*/
ap_rputs(" ", r);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
if (ar[x]->lm != -1) {
char time_str[MAX_STRING_LEN];
apr_time_exp_t ts;
apr_time_exp_lt(&ts, ar[x]->lm);
apr_strftime(time_str, &rv, MAX_STRING_LEN,
"%d-%b-%Y %H:%M ", &ts);
ap_rputs(time_str, r);
}
else {
/*Length="22-Feb-1998 23:42 " (see 4 lines above) */
ap_rputs(" ", r);
}
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
char buf[5];
ap_rputs(apr_strfsize(ar[x]->size, buf), r);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
if (ar[x]->desc) {
ap_rputs(terminate_description(d, ar[x]->desc,
autoindex_opts,
desc_width), r);
}
}
ap_rputc('\n', r);
}
else {
ap_rvputs(r, "<li><a href=\"", anchor, "\"> ",
ap_escape_html(scratch, t2),
"</a></li>\n", NULL);
}
}
if (autoindex_opts & TABLE_INDEXING) {
ap_rvputs(r, breakrow, "</table>\n", NULL);
}
else if (autoindex_opts & FANCY_INDEXING) {
if (!(autoindex_opts & SUPPRESS_RULES)) {
ap_rputs("<hr", r);
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("></pre>\n", r);
}
else {
ap_rputs("</pre>\n", r);
}
}
else {
ap_rputs("</ul>\n", r);
}
}
/*
* Compare two file entries according to the sort criteria. The return
* is essentially a signum function value.
*/
static int dsortf(struct ent **e1, struct ent **e2)
{
struct ent *c1;
struct ent *c2;
int result = 0;
/*
* First, see if either of the entries is for the parent directory.
* If so, that *always* sorts lower than anything else.
*/
if ((*e1)->name[0] == '/') {
return -1;
}
if ((*e2)->name[0] == '/') {
return 1;
}
/*
* Now see if one's a directory and one isn't, if we're set
* isdir for FOLDERS_FIRST.
*/
if ((*e1)->isdir != (*e2)->isdir) {
return (*e1)->isdir ? -1 : 1;
}
/*
* All of our comparisons will be of the c1 entry against the c2 one,
* so assign them appropriately to take care of the ordering.
*/
if ((*e1)->ascending) {
c1 = *e1;
c2 = *e2;
}
else {
c1 = *e2;
c2 = *e1;
}
switch (c1->key) {
case K_LAST_MOD:
if (c1->lm > c2->lm) {
return 1;
}
else if (c1->lm < c2->lm) {
return -1;
}
break;
case K_SIZE:
if (c1->size > c2->size) {
return 1;
}
else if (c1->size < c2->size) {
return -1;
}
break;
case K_DESC:
if (c1->version_sort) {
result = apr_strnatcmp(c1->desc ? c1->desc : "",
c2->desc ? c2->desc : "");
}
else {
result = strcmp(c1->desc ? c1->desc : "",
c2->desc ? c2->desc : "");
}
if (result) {
return result;
}
break;
}
/* names may identical when treated case-insensitively,
* so always fall back on strcmp() flavors to put entries
* in deterministic order. This means that 'ABC' and 'abc'
* will always appear in the same order, rather than
* variably between 'ABC abc' and 'abc ABC' order.
*/
if (c1->version_sort) {
if (c1->ignore_case) {
result = apr_strnatcasecmp (c1->name, c2->name);
}
if (!result) {
result = apr_strnatcmp(c1->name, c2->name);
}
}
/* The names may be identical in respects other other than
* filename case when strnatcmp is used above, so fall back
* to strcmp on conflicts so that fn1.01.zzz and fn1.1.zzz
* are also sorted in a deterministic order.
*/
if (!result && c1->ignore_case) {
result = strcasecmp (c1->name, c2->name);
}
if (!result) {
result = strcmp (c1->name, c2->name);
}
return result;
}
static int
mod_glfs_index_directory (request_rec *r,
glusterfs_dir_config_t *autoindex_conf)
{
char *title_name = ap_escape_html(r->pool, r->uri);
char *title_endp;
char *name = r->filename;
char *pstring = NULL;
apr_finfo_t dirent;
long fd = -1;
apr_status_t status;
int num_ent = 0, x;
struct ent *head, *p;
struct ent **ar = NULL;
const char *qstring;
apr_int32_t autoindex_opts = autoindex_conf->opts;
char keyid;
char direction;
char *colargs;
char *fullpath;
apr_size_t dirpathlen;
char *ctype = "text/html";
char *charset;
glusterfs_dir_config_t *dir_config = NULL;
int ret = -1;
struct dirent entry = {0, };
struct stat st = {0, };
char *path = NULL;
char *fname = NULL;
dir_config = mod_glfs_dconfig (r);
if (!dir_config || !dir_config->handle) {
return HTTP_INTERNAL_SERVER_ERROR;
}
path = r->uri + strlen (dir_config->mount_dir);
if (!dir_config->handle) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
"mod_glfs_index_directory: glusterfs handler is NULL, check glusterfs logfile %s for more details",
dir_config->logfile);
return HTTP_INTERNAL_SERVER_ERROR;
}
fd = glusterfs_open (dir_config->handle, path, O_RDONLY, 0);
if (fd == 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"file permissions deny server access: %s", r->filename);
return HTTP_FORBIDDEN;
}
if (autoindex_conf->ctype) {
ctype = autoindex_conf->ctype;
}
if (autoindex_conf->charset) {
charset = autoindex_conf->charset;
}
else {
#if APR_HAS_UNICODE_FS
charset = "UTF-8";
#else
charset = "ISO-8859-1";
#endif
}
if (*charset) {
ap_set_content_type(r, apr_pstrcat(r->pool, ctype, ";charset=",
charset, NULL));
}
else {
ap_set_content_type(r, ctype);
}
if (autoindex_opts & TRACK_MODIFIED) {
ap_update_mtime(r, r->finfo.mtime);
ap_set_last_modified(r);
ap_set_etag(r);
}
if (r->header_only) {
glusterfs_close (fd);
return 0;
}
/*
* If there is no specific ordering defined for this directory,
* default to ascending by filename.
*/
keyid = autoindex_conf->default_keyid
? autoindex_conf->default_keyid : K_NAME;
direction = autoindex_conf->default_direction
? autoindex_conf->default_direction : D_ASCENDING;
/*
* Figure out what sort of indexing (if any) we're supposed to use.
*
* If no QUERY_STRING was specified or client query strings have been
* explicitly disabled.
* If we are ignoring the client, suppress column sorting as well.
*/
if (autoindex_opts & IGNORE_CLIENT) {
qstring = NULL;
autoindex_opts |= SUPPRESS_COLSORT;
colargs = "";
}
else {
char fval[5], vval[5], *ppre = "", *epattern = "";
fval[0] = '\0'; vval[0] = '\0';
qstring = r->args;
while (qstring && *qstring) {
/* C= First Sort key Column (N, M, S, D) */
if ( qstring[0] == 'C' && qstring[1] == '='
&& qstring[2] && strchr(K_VALID, qstring[2])
&& ( qstring[3] == '&' || qstring[3] == ';'
|| !qstring[3])) {
keyid = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
/* O= Sort order (A, D) */
else if ( qstring[0] == 'O' && qstring[1] == '='
&& ( (qstring[2] == D_ASCENDING)
|| (qstring[2] == D_DESCENDING))
&& ( qstring[3] == '&' || qstring[3] == ';'
|| !qstring[3])) {
direction = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
/* F= Output Format (0 plain, 1 fancy (pre), 2 table) */
else if ( qstring[0] == 'F' && qstring[1] == '='
&& qstring[2] && strchr("012", qstring[2])
&& ( qstring[3] == '&' || qstring[3] == ';'
|| !qstring[3])) {
if (qstring[2] == '0') {
autoindex_opts &= ~(FANCY_INDEXING | TABLE_INDEXING);
}
else if (qstring[2] == '1') {
autoindex_opts = (autoindex_opts | FANCY_INDEXING)
& ~TABLE_INDEXING;
}
else if (qstring[2] == '2') {
autoindex_opts |= FANCY_INDEXING | TABLE_INDEXING;
}
strcpy(fval, ";F= ");
fval[3] = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
/* V= Version sort (0, 1) */
else if ( qstring[0] == 'V' && qstring[1] == '='
&& (qstring[2] == '0' || qstring[2] == '1')
&& ( qstring[3] == '&' || qstring[3] == ';'
|| !qstring[3])) {
if (qstring[2] == '0') {
autoindex_opts &= ~VERSION_SORT;
}
else if (qstring[2] == '1') {
autoindex_opts |= VERSION_SORT;
}
strcpy(vval, ";V= ");
vval[3] = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
/* P= wildcard pattern (*.foo) */
else if (qstring[0] == 'P' && qstring[1] == '=') {
const char *eos = qstring += 2; /* for efficiency */
while (*eos && *eos != '&' && *eos != ';') {
++eos;
}
if (eos == qstring) {
pstring = NULL;
}
else {
pstring = apr_pstrndup(r->pool, qstring, eos - qstring);
if (ap_unescape_url(pstring) != OK) {
/* ignore the pattern, if it's bad. */
pstring = NULL;
}
else {
ppre = ";P=";
/* be correct */
epattern = ap_escape_uri(r->pool, pstring);
}
}
if (*eos && *++eos) {
qstring = eos;
}
else {
qstring = NULL;
}
}
/* Syntax error? Ignore the remainder! */
else {
qstring = NULL;
}
}
colargs = apr_pstrcat(r->pool, fval, vval, ppre, epattern, NULL);
}
/* Spew HTML preamble */
title_endp = title_name + strlen(title_name) - 1;
while (title_endp > title_name && *title_endp == '/') {
*title_endp-- = '\0';
}
emit_head(r, find_header(autoindex_conf, r),
autoindex_opts & SUPPRESS_PREAMBLE,
autoindex_opts & EMIT_XHTML, title_name);
/*
* Since we don't know how many dir. entries there are, put them into a
* linked list and then arrayificate them so qsort can use them.
*/
head = NULL;
p = make_parent_entry(autoindex_opts, autoindex_conf, r, keyid, direction);
if (p != NULL) {
p->next = head;
head = p;
num_ent++;
}
fullpath = apr_palloc(r->pool, APR_PATH_MAX);
dirpathlen = strlen(name);
memcpy(fullpath, name, dirpathlen);
do {
ret = glusterfs_readdir (fd, &entry, sizeof (entry));
if (ret <= 0) {
break;
}
fname = apr_pstrcat (r->pool, path, entry.d_name);
ret = glusterfs_stat (dir_config->handle, fname, &st);
if (ret != 0) {
break;
}
dirent.fname = fname;
dirent.name = apr_pstrdup (r->pool, entry.d_name);
fill_out_finfo (&dirent, &st,
APR_FINFO_MIN | APR_FINFO_IDENT | APR_FINFO_NLINK | APR_FINFO_OWNER |
APR_FINFO_PROT);
p = make_autoindex_entry(&dirent, autoindex_opts, autoindex_conf, r,
keyid, direction, pstring);
if (p != NULL) {
p->next = head;
head = p;
num_ent++;
}
} while (1);
if (num_ent > 0) {
ar = (struct ent **) apr_palloc(r->pool,
num_ent * sizeof(struct ent *));
p = head;
x = 0;
while (p) {
ar[x++] = p;
p = p->next;
}
qsort((void *) ar, num_ent, sizeof(struct ent *),
(int (*)(const void *, const void *)) dsortf);
}
output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts,
keyid, direction, colargs);
glusterfs_close (fd);
emit_tail(r, find_readme(autoindex_conf, r),
autoindex_opts & SUPPRESS_PREAMBLE);
return 0;
}
static int
handle_autoindex(request_rec *r)
{
glusterfs_dir_config_t *dir_config = NULL;
int allow_opts;
allow_opts = ap_allow_options(r);
r->allowed |= (AP_METHOD_BIT << M_GET);
if (r->method_number != M_GET) {
return DECLINED;
}
dir_config = mod_glfs_dconfig (r);
/* OK, nothing easy. Trot out the heavy artillery... */
if (allow_opts & OPT_INDEXES) {
int errstatus;
if ((errstatus = ap_discard_request_body(r)) != OK) {
return errstatus;
}
/* KLUDGE --- make the sub_req lookups happen in the right directory.
* Fixing this in the sub_req_lookup functions themselves is difficult,
* and would probably break virtual includes...
*/
if (r->filename[strlen(r->filename) - 1] != '/') {
r->filename = apr_pstrcat(r->pool, r->filename, "/", NULL);
}
return mod_glfs_index_directory(r, dir_config);
} else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"Directory index forbidden by "
"Options directive: %s", r->filename);
return HTTP_FORBIDDEN;
}
}
static int
mod_glfs_handler (request_rec *r)
{
conn_rec *c = r->connection;
apr_bucket_brigade *bb;
apr_bucket *e;
core_dir_config *d;
int errstatus;
long fd = -1;
apr_status_t status;
glusterfs_dir_config_t *dir_config = NULL;
char *path = NULL;
int num_ranges = 0;
apr_size_t size = 0;
apr_off_t range_start = 0, range_end = 0;
char *current = NULL;
apr_status_t rv = 0;
/* XXX if/when somebody writes a content-md5 filter we either need to
* remove this support or coordinate when to use the filter vs.
* when to use this code
* The current choice of when to compute the md5 here matches the 1.3
* support fairly closely (unlike 1.3, we don't handle computing md5
* when the charset is translated).
*/
int bld_content_md5;
if (!r->handler || (r->handler && strcmp (r->handler, GLUSTERFS_HANDLER)))
return DECLINED;
if (r->uri[0] == '\0') {
return DECLINED;
}
if (r->finfo.filetype == APR_DIR) {
return handle_autoindex (r);
}
dir_config = mod_glfs_dconfig (r);
ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, -1);
/* We understood the (non-GET) method, but it might not be legal for
this particular resource. Check to see if the 'deliver_script'
flag is set. If so, then we go ahead and deliver the file since
it isn't really content (only GET normally returns content).
Note: based on logic further above, the only possible non-GET
method at this point is POST. In the future, we should enable
script delivery for all methods. */
if (r->method_number != M_GET) {
core_request_config *req_cfg;
req_cfg = ap_get_module_config(r->request_config, &core_module);
if (!req_cfg->deliver_script) {
/* The flag hasn't been set for this request. Punt. */
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"This resource does not accept the %s method.",
r->method);
return HTTP_METHOD_NOT_ALLOWED;
}
}
if (!dir_config->handle) {
ap_log_rerror (APLOG_MARK, APLOG_ERR, 0, r,
"glusterfs initialization failed\n");
return HTTP_FORBIDDEN;
}
d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
&core_module);
bld_content_md5 = (d->content_md5 & 1)
&& r->output_filters->frec->ftype != AP_FTYPE_RESOURCE;
if ((errstatus = ap_discard_request_body(r)) != OK) {
return errstatus;
}
if (r->finfo.filetype == 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"File does not exist: %s", r->filename);
return HTTP_NOT_FOUND;
}
if ((r->used_path_info != AP_REQ_ACCEPT_PATH_INFO) &&
r->path_info && *r->path_info)
{
/* default to reject */
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"File does not exist: %s",
apr_pstrcat(r->pool, r->filename, r->path_info, NULL));
return HTTP_NOT_FOUND;
}
ap_update_mtime (r, r->finfo.mtime);
ap_set_last_modified (r);
ap_set_etag (r);
apr_table_setn (r->headers_out, "Accept-Ranges", "bytes");
num_ranges = ap_set_byterange(r);
if (num_ranges == 0) {
size = r->finfo.size;
} else {
char *tmp = apr_pstrdup (r->pool, r->range);
while ((current = ap_getword(r->pool, (const char **)&tmp, ','))
&& (rv = parse_byterange(current, r->finfo.size, &range_start,
&range_end))) {
size += (range_end - range_start);
}
}
ap_set_content_length (r, size);
if ((errstatus = ap_meets_conditions(r)) != OK) {
r->status = errstatus;
}
/* file is small enough to have already got the content in glusterfs_lookup */
if (r->finfo.size <= dir_config->xattr_file_size && dir_config->buf) {
if (bld_content_md5) {
apr_table_setn (r->headers_out, "Content-MD5",
(const char *)ap_md5_binary(r->pool, dir_config->buf, r->finfo.size));
}
ap_log_rerror (APLOG_MARK, APLOG_NOTICE, 0, r,
"fetching data from glusterfs through xattr interface\n");
bb = apr_brigade_create(r->pool, c->bucket_alloc);
e = apr_bucket_heap_create (dir_config->buf, r->finfo.size, free, c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL (bb, e);
e = apr_bucket_eos_create(c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb, e);
dir_config->buf = NULL;
/* let the byterange_filter handle multipart requests */
status = ap_pass_brigade(r->output_filters, bb);
if (status == APR_SUCCESS
|| r->status != HTTP_OK
|| c->aborted) {
return OK;
}
else {
/* no way to know what type of error occurred */
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r,
"mod_glfs_handler: ap_pass_brigade returned %i",
status);
return HTTP_INTERNAL_SERVER_ERROR;
}
}
if (!dir_config->handle) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
"mod_glfs_handler: glusterfs handler is NULL, check glusterfs logfile %s for more details",
dir_config->logfile);
return HTTP_INTERNAL_SERVER_ERROR;
}
/* do standard open/read/close to fetch content */
path = r->uri + strlen (dir_config->mount_dir);
fd = glusterfs_open (dir_config->handle, path , O_RDONLY, 0);
if (fd == 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"file permissions deny server access: %s", r->filename);
return HTTP_FORBIDDEN;
}
/* byterange_filter cannot handle range requests, since we are not sending the
whole data in a single brigade */
if (num_ranges == 0) {
mod_glfs_read_async (r, NULL, fd, 0, -1);
} else {
mod_glfs_handle_byte_ranges (r, fd, num_ranges);
}
glusterfs_close (fd);
}
#if 0
static apr_status_t
mod_glfs_output_filter (ap_filter_t *f,
apr_bucket_brigade *b)
{
size_t size = 0;
apr_bucket_t *e = NULL;
size = atol (apr_table_get (r->notes, MOD_GLFS_SIZE));
for (e = APR_BRIGADE_FIRST(b);
e != APR_BRIGADE_SENTINEL(b);
e = APR_BUCKET_NEXT(e))
{
/* FIXME: can there be more than one heap buckets? */
if (e->type == &apr_bucket_type_heap) {
break;
}
}
if (e != APR_BRIGADE_SENTINEL(b)) {
e->length = size;
}
return ap_pass_brigade (f->next, b);
}
#endif
static int
mod_glfs_fixup_dir(request_rec *r)
{
glusterfs_dir_config_t *d;
char *dummy_ptr[1];
char **names_ptr;
int num_names;
int error_notfound = 0;
/* only handle requests against directories */
if (r->finfo.filetype != APR_DIR) {
return DECLINED;
}
if (!r->handler || strcmp (r->handler, GLUSTERFS_HANDLER)) {
return DECLINED;
}
/* Never tolerate path_info on dir requests */
if (r->path_info && *r->path_info) {
return DECLINED;
}
d = (glusterfs_dir_config_t *)ap_get_module_config(r->per_dir_config,
&glusterfs_module);
/* Redirect requests that are not '/' terminated */
if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] != '/')
{
char *ifile;
if (!d->do_slash) {
return DECLINED;
}
/* Only redirect non-get requests if we have no note to warn
* that this browser cannot handle redirs on non-GET requests
* (such as Microsoft's WebFolders).
*/
if ((r->method_number != M_GET)
&& apr_table_get(r->subprocess_env, "redirect-carefully")) {
return DECLINED;
}
if (r->args != NULL) {
ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
"/", "?", r->args, NULL);
}
else {
ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
"/", NULL);
}
apr_table_setn(r->headers_out, "Location",
ap_construct_url(r->pool, ifile, r));
return HTTP_MOVED_PERMANENTLY;
}
if (d->index_names) {
names_ptr = (char **)d->index_names->elts;
num_names = d->index_names->nelts;
}
else {
dummy_ptr[0] = AP_DEFAULT_INDEX;
names_ptr = dummy_ptr;
num_names = 1;
}
for (; num_names; ++names_ptr, --num_names) {
/* XXX: Is this name_ptr considered escaped yet, or not??? */
char *name_ptr = *names_ptr;
request_rec *rr;
/* Once upon a time args were handled _after_ the successful redirect.
* But that redirect might then _refuse_ the given r->args, creating
* a nasty tangle. It seems safer to consider the r->args while we
* determine if name_ptr is our viable index, and therefore set them
* up correctly on redirect.
*/
if (r->args != NULL) {
name_ptr = apr_pstrcat(r->pool, name_ptr, "?", r->args, NULL);
}
rr = ap_sub_req_lookup_uri(name_ptr, r, NULL);
/* The sub request lookup is very liberal, and the core map_to_storage
* handler will almost always result in HTTP_OK as /foo/index.html
* may be /foo with PATH_INFO="/index.html", or even / with
* PATH_INFO="/foo/index.html". To get around this we insist that the
* the index be a regular filetype.
*
* Another reason is that the core handler also makes the assumption
* that if r->finfo is still NULL by the time it gets called, the
* file does not exist.
*/
if (rr->status == HTTP_OK
&& ( (rr->handler && !strcmp(rr->handler, "proxy-server"))
|| rr->finfo.filetype == APR_REG)) {
ap_internal_fast_redirect(rr, r);
return OK;
}
/* If the request returned a redirect, propagate it to the client */
if (ap_is_HTTP_REDIRECT(rr->status)
|| (rr->status == HTTP_NOT_ACCEPTABLE && num_names == 1)
|| (rr->status == HTTP_UNAUTHORIZED && num_names == 1)) {
apr_pool_join(r->pool, rr->pool);
error_notfound = rr->status;
r->notes = apr_table_overlay(r->pool, r->notes, rr->notes);
r->headers_out = apr_table_overlay(r->pool, r->headers_out,
rr->headers_out);
r->err_headers_out = apr_table_overlay(r->pool, r->err_headers_out,
rr->err_headers_out);
return error_notfound;
}
/* If the request returned something other than 404 (or 200),
* it means the module encountered some sort of problem. To be
* secure, we should return the error, rather than allow autoindex
* to create a (possibly unsafe) directory index.
*
* So we store the error, and if none of the listed files
* exist, we return the last error response we got, instead
* of a directory listing.
*/
if (rr->status && rr->status != HTTP_NOT_FOUND
&& rr->status != HTTP_OK) {
error_notfound = rr->status;
}
ap_destroy_sub_req(rr);
}
if (error_notfound) {
return error_notfound;
}
/* nothing for us to do, pass on through */
return DECLINED;
}
static void
mod_glfs_register_hooks(apr_pool_t *p)
{
ap_hook_child_init (mod_glfs_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler (mod_glfs_handler, NULL, NULL, APR_HOOK_REALLY_FIRST);
ap_hook_map_to_storage (mod_glfs_map_to_storage, NULL, NULL, APR_HOOK_REALLY_FIRST);
ap_hook_fixups(mod_glfs_fixup_dir,NULL,NULL,APR_HOOK_LAST);
/* mod_glfs_output_filter_handle =
ap_register_output_filter ("MODGLFS", mod_glfs_output_filter,
NULL, AP_FTYPE_PROTOCOL); */
}
static const char *
cmd_add_index (cmd_parms *cmd, void *dummy, const char *arg)
{
glusterfs_dir_config_t *d = dummy;
if (!d->index_names) {
d->index_names = apr_array_make(cmd->pool, 2, sizeof(char *));
}
*(const char **)apr_array_push(d->index_names) = arg;
return NULL;
}
static const char *
cmd_configure_slash (cmd_parms *cmd, void *d_, int arg)
{
glusterfs_dir_config_t *d = d_;
d->do_slash = arg ? SLASH_ON : SLASH_OFF;
return NULL;
}
#define DIR_CMD_PERMS OR_INDEXES
static const
command_rec mod_glfs_cmds[] =
{
AP_INIT_TAKE1(
"GlusterfsLogfile",
cmd_add_logfile,
NULL,
ACCESS_CONF, /*FIXME: allow overriding in .htaccess files */
"Glusterfs logfile"
),
AP_INIT_TAKE1(
"GlusterfsLoglevel",
cmd_set_loglevel,
NULL,
ACCESS_CONF,
"Glusterfs loglevel:anyone of none, critical, error, warning, debug"
),
AP_INIT_TAKE1(
"GlusterfsCacheTimeout",
cmd_set_cache_timeout,
NULL,
ACCESS_CONF,
"Timeout value in seconds for lookup and stat cache of libglusterfsclient"
),
AP_INIT_TAKE1(
"GlusterfsVolumeSpecfile",
cmd_add_volume_specfile,
NULL,
ACCESS_CONF,
"Glusterfs Volume specfication file specifying filesystem under this directory"
),
AP_INIT_TAKE1(
"GlusterfsXattrFileSize",
cmd_add_xattr_file_size,
NULL,
ACCESS_CONF,
"Maximum size of the file that can be fetched through extended attribute interface of libglusterfsclient"
),
/* mod_dir cmds */
AP_INIT_ITERATE("DirectoryIndex", cmd_add_index,
NULL, DIR_CMD_PERMS,
"a list of file names"),
AP_INIT_FLAG("DirectorySlash", cmd_configure_slash,
NULL, DIR_CMD_PERMS,
"On or Off"),
/* autoindex cmds */
AP_INIT_ITERATE2("AddIcon", cmd_add_icon,
BY_PATH, DIR_CMD_PERMS,
"an icon URL followed by one or more filenames"),
AP_INIT_ITERATE2("AddIconByType", cmd_add_icon,
BY_TYPE, DIR_CMD_PERMS,
"an icon URL followed by one or more MIME types"),
AP_INIT_ITERATE2("AddIconByEncoding", cmd_add_icon,
BY_ENCODING, DIR_CMD_PERMS,
"an icon URL followed by one or more content encodings"),
AP_INIT_ITERATE2("AddAlt", cmd_add_alt, BY_PATH,
DIR_CMD_PERMS,
"alternate descriptive text followed by one or more "
"filenames"),
AP_INIT_ITERATE2("AddAltByType", cmd_add_alt,
BY_TYPE, DIR_CMD_PERMS,
"alternate descriptive text followed by one or more MIME "
"types"),
AP_INIT_ITERATE2("AddAltByEncoding", cmd_add_alt,
BY_ENCODING, DIR_CMD_PERMS,
"alternate descriptive text followed by one or more "
"content encodings"),
AP_INIT_TAKE_ARGV("IndexOptions", cmd_add_opts,
NULL, DIR_CMD_PERMS,
"one or more index options [+|-][]"),
AP_INIT_TAKE2("IndexOrderDefault", cmd_set_default_order,
NULL, DIR_CMD_PERMS,
"{Ascending,Descending} {Name,Size,Description,Date}"),
AP_INIT_ITERATE("IndexIgnore", cmd_add_ignore,
NULL, DIR_CMD_PERMS,
"one or more file extensions"),
AP_INIT_ITERATE2("AddDescription", cmd_add_desc,
BY_PATH, DIR_CMD_PERMS,
"Descriptive text followed by one or more filenames"),
AP_INIT_TAKE1("HeaderName", cmd_add_header,
NULL, DIR_CMD_PERMS,
"a filename"),
AP_INIT_TAKE1("ReadmeName", cmd_add_readme,
NULL, DIR_CMD_PERMS,
"a filename"),
AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated,
NULL, OR_ALL,
"The FancyIndexing directive is no longer supported. "
"Use IndexOptions FancyIndexing."),
AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
(void *)APR_OFFSETOF(glusterfs_dir_config_t, default_icon),
DIR_CMD_PERMS, "an icon URL"),
AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot,
(void *)APR_OFFSETOF(glusterfs_dir_config_t, style_sheet),
DIR_CMD_PERMS, "URL to style sheet"),
{NULL}
};
module AP_MODULE_DECLARE_DATA glusterfs_module =
{
STANDARD20_MODULE_STUFF,
mod_glfs_create_dir_config,
mod_glfs_merge_dir_config,
NULL, //mod_glfs_create_server_config,
NULL, //mod_glfs_merge_server_config,
mod_glfs_cmds,
mod_glfs_register_hooks,
};
|