mirror of
https://github.com/mirror/wget.git
synced 2026-08-19 17:33:28 +08:00
Compare commits
596 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd7f36705b | ||
|
|
e996e322ff | ||
|
|
2bdfc4f521 | ||
|
|
2c736abb4c | ||
|
|
7c0752c4cb | ||
|
|
302aa79abb | ||
|
|
5224d752a5 | ||
|
|
2aaf12990c | ||
|
|
2e6f629061 | ||
|
|
a952f81f3e | ||
|
|
42cc84b6b6 | ||
|
|
96ab9cad88 | ||
|
|
268163444d | ||
|
|
53800415a9 | ||
|
|
528770ca8b | ||
|
|
2f1c6a05c8 | ||
|
|
33d860e1ef | ||
|
|
99fc712f21 | ||
|
|
54746578e9 | ||
|
|
926e42d467 | ||
|
|
d286d5408b | ||
|
|
9883f9fb10 | ||
|
|
d26377053d | ||
|
|
722675553c | ||
|
|
281ad7dfb9 | ||
|
|
f3e63f0071 | ||
|
|
b916595168 | ||
|
|
76ef65b23c | ||
|
|
d7726f8a13 | ||
|
|
598445ebd1 | ||
|
|
7cb9efa668 | ||
|
|
44aedd8321 | ||
|
|
c28f51aadf | ||
|
|
7099f48998 | ||
|
|
75e5be7aad | ||
|
|
100da11312 | ||
|
|
cceb5932b4 | ||
|
|
cacac6f996 | ||
|
|
3056617e9c | ||
|
|
c190677cab | ||
|
|
4c2dc5010f | ||
|
|
b30500f0f4 | ||
|
|
59b920874d | ||
|
|
9a6e63bee9 | ||
|
|
cbbeca2af4 | ||
|
|
93c1517c40 | ||
|
|
bf5d7e9236 | ||
|
|
94d9b68db9 | ||
|
|
be7d19f478 | ||
|
|
358a3c330f | ||
|
|
478a584609 | ||
|
|
994c4dcce7 | ||
|
|
f65f522f58 | ||
|
|
be84711ea4 | ||
|
|
bf56bf4560 | ||
|
|
3eddf5c173 | ||
|
|
160f0e908f | ||
|
|
30b0705fa6 | ||
|
|
9933da2b9f | ||
|
|
df7cb9a1b9 | ||
|
|
636a5f9a1c | ||
|
|
44937634a3 | ||
|
|
2257d3ebf8 | ||
|
|
b0d2fa5748 | ||
|
|
ca0c272eae | ||
|
|
8977e63239 | ||
|
|
ad5a283528 | ||
|
|
3dd2e78256 | ||
|
|
81061571d1 | ||
|
|
4e37fb6191 | ||
|
|
218d81f6e5 | ||
|
|
46cd721c0f | ||
|
|
b1c7777037 | ||
|
|
8c12260d4b | ||
|
|
99aa7b4f5e | ||
|
|
76da642aaf | ||
|
|
2cfcadf5e6 | ||
|
|
08ece891b5 | ||
|
|
4ed540ddc7 | ||
|
|
d1a329536a | ||
|
|
2b418d1146 | ||
|
|
b041658451 | ||
|
|
6cdfc9c143 | ||
|
|
b14eeb5aee | ||
|
|
71979f1643 | ||
|
|
4ad201a7e7 | ||
|
|
3608c3001c | ||
|
|
d484b14174 | ||
|
|
b8ee370571 | ||
|
|
f5a63e3100 | ||
|
|
077e897819 | ||
|
|
1e7ccfe275 | ||
|
|
26fadc55c2 | ||
|
|
e51076e683 | ||
|
|
c387db6451 | ||
|
|
12dfc03116 | ||
|
|
3ea0beec6f | ||
|
|
b50300a7a2 | ||
|
|
f8901af4e0 | ||
|
|
e624732563 | ||
|
|
f2cb6e050a | ||
|
|
84b9abbf3c | ||
|
|
58917dcde1 | ||
|
|
ab47d9fa3a | ||
|
|
187edb604a | ||
|
|
b06fca60ac | ||
|
|
c809398e8c | ||
|
|
88a1a79bc1 | ||
|
|
398699c438 | ||
|
|
d3504b9261 | ||
|
|
6b5acff566 | ||
|
|
5c4489db9b | ||
|
|
7bed9a6f8f | ||
|
|
d080a70a3a | ||
|
|
2d2ddb25d8 | ||
|
|
030c3379d1 | ||
|
|
d3d8de8223 | ||
|
|
e04c5989ff | ||
|
|
12bae50b28 | ||
|
|
f71887bbe5 | ||
|
|
84c405e690 | ||
|
|
075d755696 | ||
|
|
7578e47d49 | ||
|
|
3a708f7ef8 | ||
|
|
474935665e | ||
|
|
f8519b52f0 | ||
|
|
98272d2c8d | ||
|
|
7e5079c40f | ||
|
|
e4db00d74d | ||
|
|
670eb924e7 | ||
|
|
5d55018ce6 | ||
|
|
4e56a91001 | ||
|
|
595f219a17 | ||
|
|
b6e242cd6f | ||
|
|
207006ef25 | ||
|
|
843634db59 | ||
|
|
54058d2b18 | ||
|
|
b60131a399 | ||
|
|
fc8a545bfd | ||
|
|
9e12b8ca39 | ||
|
|
4c3043d19d | ||
|
|
6064f21c66 | ||
|
|
97389a7497 | ||
|
|
225a87d4a2 | ||
|
|
92a889b278 | ||
|
|
1113e78534 | ||
|
|
70cbd59ed6 | ||
|
|
0e7aff7623 | ||
|
|
792dd09a87 | ||
|
|
a4f5ced797 | ||
|
|
05c30c3b1b | ||
|
|
37b58e3976 | ||
|
|
80303366ae | ||
|
|
bd0ffcf8bc | ||
|
|
25c9b462bf | ||
|
|
77f5a27e65 | ||
|
|
ae58d8a78b | ||
|
|
58702ffd4f | ||
|
|
103f940950 | ||
|
|
5f0818d9f1 | ||
|
|
c6ac51d5bc | ||
|
|
fd3a3245eb | ||
|
|
48acb6693d | ||
|
|
885eaaa214 | ||
|
|
8a8d138dcc | ||
|
|
0e8d2d4251 | ||
|
|
be4f91737a | ||
|
|
901bc98edf | ||
|
|
e397a48f6a | ||
|
|
83537f2415 | ||
|
|
8682c2612f | ||
|
|
b0820d553b | ||
|
|
b6b1388fb7 | ||
|
|
9b1dd6dab8 | ||
|
|
1cc835dc5b | ||
|
|
6b8dfe1d6e | ||
|
|
0e6d6ca963 | ||
|
|
3765a1b266 | ||
|
|
8654f7e2e7 | ||
|
|
566696cb82 | ||
|
|
bebe462a67 | ||
|
|
c579c7bf1e | ||
|
|
4dde3e200f | ||
|
|
8e0dd0d870 | ||
|
|
c6af2fddee | ||
|
|
e7e3227b34 | ||
|
|
5c5d45ae49 | ||
|
|
f4072e5d0b | ||
|
|
bef5945202 | ||
|
|
ac40b84ee1 | ||
|
|
45463eaad7 | ||
|
|
d03b40e31e | ||
|
|
268e6aef72 | ||
|
|
5efb24e4a2 | ||
|
|
eae8b1d565 | ||
|
|
045463b814 | ||
|
|
621c313b94 | ||
|
|
52a7d0ad85 | ||
|
|
59e9ef00e6 | ||
|
|
14bbc18512 | ||
|
|
8aa63e482e | ||
|
|
0bc2757713 | ||
|
|
f8abb9dd00 | ||
|
|
29850e77d0 | ||
|
|
799c545722 | ||
|
|
014b1d6041 | ||
|
|
8d4bb928b9 | ||
|
|
d0f406a13f | ||
|
|
87b52e510c | ||
|
|
cc9f76c5a4 | ||
|
|
53b22974cb | ||
|
|
7d5a7ef9ca | ||
|
|
735cc220e3 | ||
|
|
524f26a200 | ||
|
|
16f1fb1d1f | ||
|
|
b74ac4c7e0 | ||
|
|
91e9a20752 | ||
|
|
4a214bc9a3 | ||
|
|
b7b6d7fd89 | ||
|
|
3a00b37bc2 | ||
|
|
adcc793a26 | ||
|
|
d94d9cd98b | ||
|
|
882ed28d59 | ||
|
|
e316d253fa | ||
|
|
9dde436dd6 | ||
|
|
bf868e8840 | ||
|
|
5352eac8fa | ||
|
|
d419cd7c0c | ||
|
|
33c5d979ce | ||
|
|
9df2250f4c | ||
|
|
3d8e765c1d | ||
|
|
c83f344564 | ||
|
|
07a350d30c | ||
|
|
875d0819c4 | ||
|
|
b25fbe5afc | ||
|
|
4e8e159289 | ||
|
|
8705e27e20 | ||
|
|
a7e9a05a89 | ||
|
|
87f4fee8c9 | ||
|
|
5e3a760731 | ||
|
|
01d5177f7a | ||
|
|
103cbf1751 | ||
|
|
6f62bc5cd8 | ||
|
|
f6b28575cc | ||
|
|
5de8ab2a0b | ||
|
|
a8d437d827 | ||
|
|
fc336758ab | ||
|
|
9ee2fdd50d | ||
|
|
cfe7589397 | ||
|
|
15f18e7606 | ||
|
|
ee196f6fe5 | ||
|
|
0417ef8b50 | ||
|
|
56c0098063 | ||
|
|
712d607f9b | ||
|
|
32499e717d | ||
|
|
b147fb1638 | ||
|
|
365aeba704 | ||
|
|
b0893e84b3 | ||
|
|
f0de37cc27 | ||
|
|
05d73a926a | ||
|
|
ec5e0f421c | ||
|
|
0d9615292e | ||
|
|
6bc2620592 | ||
|
|
b0b1cde6e2 | ||
|
|
f37dd1aa2d | ||
|
|
b5778699f0 | ||
|
|
b8c567a3ef | ||
|
|
425368c602 | ||
|
|
1ca88a4208 | ||
|
|
26790c3583 | ||
|
|
fcd3b3c473 | ||
|
|
eb0789d43f | ||
|
|
ab2d5d83d2 | ||
|
|
cbaabe78e8 | ||
|
|
0a4826f4a1 | ||
|
|
71425f1bb3 | ||
|
|
f59dac3023 | ||
|
|
8b50cd4b61 | ||
|
|
a80986a8c9 | ||
|
|
94447e31a6 | ||
|
|
e6713474c0 | ||
|
|
aaefe8bc83 | ||
|
|
4b845615fa | ||
|
|
aeca2c33c0 | ||
|
|
11c6dcb705 | ||
|
|
ce088c2b9e | ||
|
|
d9ab65abd2 | ||
|
|
e4583ab364 | ||
|
|
4850e9c873 | ||
|
|
d9325f5db5 | ||
|
|
5d3b52d0b8 | ||
|
|
e194c1dfd3 | ||
|
|
3e609a1192 | ||
|
|
5edc97f3f8 | ||
|
|
007bee88d8 | ||
|
|
d87fdecd55 | ||
|
|
f0e7326c20 | ||
|
|
54227091b8 | ||
|
|
1853e425f5 | ||
|
|
fe0bfb5ee9 | ||
|
|
255133326b | ||
|
|
0c18773308 | ||
|
|
9217b864d8 | ||
|
|
5e2ecaf277 | ||
|
|
cd23c7fe0e | ||
|
|
ed996fe32f | ||
|
|
1b8e54b808 | ||
|
|
eab0f5d222 | ||
|
|
e94a542d0f | ||
|
|
b6de436547 | ||
|
|
c6b750061a | ||
|
|
b41a3a6568 | ||
|
|
f687547d6e | ||
|
|
841efb0108 | ||
|
|
09d47ead18 | ||
|
|
00203b2888 | ||
|
|
1553c70961 | ||
|
|
bc75d2ecdf | ||
|
|
e15ef0b4da | ||
|
|
b19d8032c2 | ||
|
|
3c51ad7f02 | ||
|
|
6a9b2d36e1 | ||
|
|
40f3613b67 | ||
|
|
acc76b1e02 | ||
|
|
e4be5e3b9a | ||
|
|
bfbc2866c5 | ||
|
|
d9f21b4b95 | ||
|
|
7b43510fe3 | ||
|
|
1356e90a14 | ||
|
|
f9646a0c14 | ||
|
|
1ce1a40f94 | ||
|
|
7a7a241e5b | ||
|
|
18fe274e1c | ||
|
|
c6ee033425 | ||
|
|
0c1bff841b | ||
|
|
f518d6cea1 | ||
|
|
50ec4d9c3d | ||
|
|
94b8458af1 | ||
|
|
db621341a4 | ||
|
|
2ece0cc425 | ||
|
|
0ae74cde39 | ||
|
|
2bac75dbc5 | ||
|
|
6ab8659ff5 | ||
|
|
bd8893a76c | ||
|
|
6c989c7131 | ||
|
|
425584b61e | ||
|
|
ff6fc1f8dd | ||
|
|
94805ad55a | ||
|
|
897ef07712 | ||
|
|
6e259b76b7 | ||
|
|
cf4991d602 | ||
|
|
176c2b17fc | ||
|
|
9823dc1989 | ||
|
|
2457715e7d | ||
|
|
a0c30fc72b | ||
|
|
e4a8fe84e2 | ||
|
|
170a469533 | ||
|
|
d81a8d5f56 | ||
|
|
831b9d1880 | ||
|
|
7259c30929 | ||
|
|
b6d8e1e707 | ||
|
|
43e5f022e2 | ||
|
|
51415ad5d6 | ||
|
|
e0f149d29d | ||
|
|
375b671f01 | ||
|
|
981c7456ff | ||
|
|
5e71d5aea1 | ||
|
|
c6300a3ac7 | ||
|
|
2303793a62 | ||
|
|
e52879514f | ||
|
|
fdd8b8c997 | ||
|
|
35bfcb34b0 | ||
|
|
8078adee7f | ||
|
|
9f83e0e13c | ||
|
|
f48be4e0c6 | ||
|
|
5ae5d2eaeb | ||
|
|
47d0d4c331 | ||
|
|
d272339fda | ||
|
|
297d040ce1 | ||
|
|
ea97693b54 | ||
|
|
fb8f81040a | ||
|
|
4ea40809cb | ||
|
|
64a3d521de | ||
|
|
c2bb6bc875 | ||
|
|
a5c6ae8f28 | ||
|
|
42333c4a5e | ||
|
|
a6c2ba73d9 | ||
|
|
9dd6ea7481 | ||
|
|
c81e3df2bc | ||
|
|
148065bc00 | ||
|
|
4152e98bb0 | ||
|
|
3e2c95b0dd | ||
|
|
605d9053e5 | ||
|
|
6092205538 | ||
|
|
9c34d4ed09 | ||
|
|
3eff3ad69a | ||
|
|
56a02c1a44 | ||
|
|
e5cb0f77e6 | ||
|
|
3697fd9451 | ||
|
|
b4440d96cf | ||
|
|
69c45cba43 | ||
|
|
18b0979357 | ||
|
|
c986ea790c | ||
|
|
3e3073ca7b | ||
|
|
796da8da3a | ||
|
|
7cd528a4e9 | ||
|
|
601b282cd8 | ||
|
|
bc347cc36f | ||
|
|
6fc11e46ec | ||
|
|
ff876a3710 | ||
|
|
21fc7546ef | ||
|
|
afbcaaecba | ||
|
|
b64fa2eb84 | ||
|
|
8c2d9afd08 | ||
|
|
b36c3e48c4 | ||
|
|
efe090df89 | ||
|
|
f8e9a64ec7 | ||
|
|
5753ed4a72 | ||
|
|
03f8babefe | ||
|
|
3858500de4 | ||
|
|
e29020e10c | ||
|
|
be78cba9e5 | ||
|
|
6cb857502f | ||
|
|
65fc59aefa | ||
|
|
8b83306d54 | ||
|
|
b89cda0a77 | ||
|
|
0606f1a133 | ||
|
|
c443399ab1 | ||
|
|
7cbe8141d1 | ||
|
|
eab853b7e6 | ||
|
|
3d7797c46e | ||
|
|
cae32d41c1 | ||
|
|
a44841cbe2 | ||
|
|
e43ae39dff | ||
|
|
c5f2c7fcef | ||
|
|
550cd6e9d2 | ||
|
|
97ce41b2d0 | ||
|
|
416d0e892c | ||
|
|
e2c8436e17 | ||
|
|
ebda24eb69 | ||
|
|
582e5d8ef7 | ||
|
|
601401da71 | ||
|
|
f3289f76ec | ||
|
|
26787225c1 | ||
|
|
104fd20ac3 | ||
|
|
ca402e2f81 | ||
|
|
8445279306 | ||
|
|
bb025955c3 | ||
|
|
08cedb953b | ||
|
|
c03855be40 | ||
|
|
3e8f9a6436 | ||
|
|
5a712b5bcf | ||
|
|
964ba0a0d5 | ||
|
|
ffccc7d3be | ||
|
|
d1ab00cab4 | ||
|
|
dd1b69c600 | ||
|
|
3b502901c0 | ||
|
|
a22cd7394b | ||
|
|
8a83a9d893 | ||
|
|
8e6de1fb5f | ||
|
|
8a919932a6 | ||
|
|
087e17be1c | ||
|
|
ee5b28367c | ||
|
|
4d77b190fd | ||
|
|
854ebbf4dd | ||
|
|
8624553a31 | ||
|
|
4eeabffee6 | ||
|
|
f2b9004e8f | ||
|
|
38a7829dcb | ||
|
|
351e438e51 | ||
|
|
6d4158122c | ||
|
|
8c2fd06ba8 | ||
|
|
67a4c6cf97 | ||
|
|
848d7537e1 | ||
|
|
6c572cbc33 | ||
|
|
97787110a2 | ||
|
|
226785838a | ||
|
|
320cfdcb65 | ||
|
|
d7ea21b2e7 | ||
|
|
c9bc854938 | ||
|
|
ed54c64ad2 | ||
|
|
701e407af5 | ||
|
|
dfa1f4e064 | ||
|
|
43c89ab7a5 | ||
|
|
5bb2f43165 | ||
|
|
605eafa792 | ||
|
|
d68295bdb1 | ||
|
|
59080465d1 | ||
|
|
b65b9cb8c5 | ||
|
|
593b59c697 | ||
|
|
b9e5c3e8b3 | ||
|
|
87186cbc2f | ||
|
|
f694b2ea24 | ||
|
|
d260ded060 | ||
|
|
70f7cdf1af | ||
|
|
351d328c07 | ||
|
|
3b6a3e84a0 | ||
|
|
fb23bc0611 | ||
|
|
cb358c0a84 | ||
|
|
12218d353b | ||
|
|
3832728138 | ||
|
|
38933de17c | ||
|
|
aed7d4163a | ||
|
|
42c15e47b4 | ||
|
|
c3835a425a | ||
|
|
8b2954e58a | ||
|
|
bba67890f3 | ||
|
|
0c9fb2b041 | ||
|
|
fbd9b9c16b | ||
|
|
1fd32c995c | ||
|
|
c289349684 | ||
|
|
1dec2028d0 | ||
|
|
7e85e9509e | ||
|
|
85dd2f7ce2 | ||
|
|
e1fc2057c7 | ||
|
|
eaf2fc9a4f | ||
|
|
e505664ef3 | ||
|
|
e6123ed645 | ||
|
|
5137cff125 | ||
|
|
42c78fdd71 | ||
|
|
a7df7ecc2f | ||
|
|
695f11304b | ||
|
|
a12bd59111 | ||
|
|
ffb94036f2 | ||
|
|
92035dbabd | ||
|
|
c19d76c024 | ||
|
|
a300f1e47d | ||
|
|
72b2c58983 | ||
|
|
c52bbad9e4 | ||
|
|
44ba49b31f | ||
|
|
eee1589ef3 | ||
|
|
e9cc8b2f7c | ||
|
|
b8f036d16c | ||
|
|
91f0f99e9a | ||
|
|
c78caecbb4 | ||
|
|
8760123cee | ||
|
|
c9c0e4c641 | ||
|
|
9e0d87a248 | ||
|
|
6a2d67b583 | ||
|
|
49f6d0ded8 | ||
|
|
4df7703d62 | ||
|
|
7f43748544 | ||
|
|
9d35f87218 | ||
|
|
90896e3314 | ||
|
|
5ce9389384 | ||
|
|
099d8ee3da | ||
|
|
e976d4f3dc | ||
|
|
ccd369d5f2 | ||
|
|
027d9f385d | ||
|
|
83837b0606 | ||
|
|
ae80fd2ec7 | ||
|
|
277785fa2a | ||
|
|
52dd6da6e0 | ||
|
|
550457bcad | ||
|
|
8dc52c6eaa | ||
|
|
54fd8de415 | ||
|
|
81409cb9c8 | ||
|
|
0e6f1c2dac | ||
|
|
7df4b05f0b | ||
|
|
bc2891f307 | ||
|
|
6c30653a1a | ||
|
|
edbeaa0c4e | ||
|
|
e3b3ea5120 | ||
|
|
50238e49b9 | ||
|
|
6443581d72 | ||
|
|
3be7e0a53c | ||
|
|
b56a528aea | ||
|
|
dcf667fb57 | ||
|
|
a2c0835007 | ||
|
|
3ebbd84518 | ||
|
|
b60ff61b75 | ||
|
|
2c1e0326a3 | ||
|
|
359dd16760 | ||
|
|
1e229375aa | ||
|
|
4f09a3118f | ||
|
|
b1838bdfd1 | ||
|
|
98f843f3cc | ||
|
|
9e8d899a35 | ||
|
|
5dcb116087 | ||
|
|
242ddfc74e | ||
|
|
13c6e7832a | ||
|
|
22bd8011e8 | ||
|
|
fe401688a6 | ||
|
|
6e4c3ab999 | ||
|
|
022dbcb343 | ||
|
|
7c0270cdb5 | ||
|
|
67e6027ea1 | ||
|
|
e9845d2813 | ||
|
|
959e5d1e90 | ||
|
|
74f6cb8884 | ||
|
|
e2cb2fa2e3 | ||
|
|
b718128b4f | ||
|
|
798f554773 | ||
|
|
06fc1edb54 | ||
|
|
85b98d0834 | ||
|
|
4759cf099f |
95
.gitignore
vendored
Normal file
95
.gitignore
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
# Project Root
|
||||
/.sc-start-sc_bindtextdomain
|
||||
/.sc-start-sc_prohibit_HAVE_MBRTOWC
|
||||
/.version
|
||||
/ABOUT-NLS
|
||||
/GNUmakefile
|
||||
/INSTALL
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
/aclocal.m4
|
||||
/autom4te.cache/
|
||||
/config.cache
|
||||
/config.log
|
||||
/config.status
|
||||
/configure
|
||||
/lib/
|
||||
/maint.mk
|
||||
# Wildcard Ignores
|
||||
*~
|
||||
po/*.gmo*
|
||||
po/*.po*
|
||||
src/*.o
|
||||
tests/*.log
|
||||
tests/*.trs
|
||||
testenv/*.log
|
||||
testenv/*.trs
|
||||
# build-aux/
|
||||
build-aux/.gitignore
|
||||
build-aux/ar-lib
|
||||
build-aux/compile
|
||||
build-aux/config.guess
|
||||
build-aux/config.sub
|
||||
build-aux/depcomp
|
||||
build-aux/install-sh
|
||||
build-aux/mdate-sh
|
||||
build-aux/missing
|
||||
build-aux/snippet/
|
||||
build-aux/test-driver
|
||||
build-aux/texinfo.tex
|
||||
# doc/
|
||||
doc/Makefile
|
||||
doc/Makefile.in
|
||||
doc/sample.wgetrc.munged_for_texi_inclusion
|
||||
doc/stamp-vti
|
||||
doc/version.texi
|
||||
doc/wget.1
|
||||
doc/wget.info
|
||||
doc/wget.pod
|
||||
# m4/
|
||||
m4/.gitignore
|
||||
m4/gnulib-cache.m4
|
||||
# po/
|
||||
po/.gitignore
|
||||
po/.reference/
|
||||
po/LINGUAS
|
||||
po/Makefile
|
||||
po/Makefile.in
|
||||
po/Makevars
|
||||
po/POTFILES
|
||||
po/wget.pot
|
||||
po/stamp-po
|
||||
# src/
|
||||
src/.deps/
|
||||
src/Makefile
|
||||
src/Makefile.in
|
||||
src/build_info.c
|
||||
src/config.h
|
||||
src/config.h.in
|
||||
src/cscope.out
|
||||
src/css.c
|
||||
src/css_.c
|
||||
src/libunittest.a
|
||||
src/stamp-h1
|
||||
src/tags
|
||||
src/version.c
|
||||
src/wget
|
||||
# testenv/
|
||||
testenv/conf/__pycache__/
|
||||
testenv/exc/__pycache__/
|
||||
testenv/misc/__pycache__/
|
||||
testenv/server/__pycache__/
|
||||
testenv/server/http/__pycache__/
|
||||
testenv/test/__pycache__/
|
||||
testenv/Makefile
|
||||
testenv/Makefile.in
|
||||
# tests/
|
||||
tests/Makefile
|
||||
tests/Makefile.in
|
||||
tests/unit-tests
|
||||
# util/
|
||||
util/Makefile
|
||||
util/Makefile.in
|
||||
# others
|
||||
/tags
|
||||
/cscope.out
|
||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "gnulib"]
|
||||
path = gnulib
|
||||
url = git://git.sv.gnu.org/gnulib.git
|
||||
50
.travis.yml
Normal file
50
.travis.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
sudo: no
|
||||
|
||||
language: c
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- darnir@gmail.com
|
||||
- bug-wget@gnu.org
|
||||
on_success: change
|
||||
on_failure: always
|
||||
|
||||
env:
|
||||
global:
|
||||
- PERLLIB=$PERLLIB:../../tests
|
||||
- PERL5LIB=$PERL5LIB:../../tests
|
||||
matrix:
|
||||
- SSL=""
|
||||
- SSL="openssl"
|
||||
- SSL="gnutls"
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- automake
|
||||
- autoconf
|
||||
- autopoint
|
||||
- flex
|
||||
- texinfo
|
||||
- pkg-config
|
||||
- libgnutls-dev
|
||||
- libssl-dev
|
||||
- make
|
||||
- libhttp-daemon-perl
|
||||
- libio-socket-ssl-perl
|
||||
- libidn11-dev
|
||||
- gettext
|
||||
- texlive
|
||||
- python3
|
||||
- valgrind
|
||||
- language-pack-tr
|
||||
- language-pack-ru
|
||||
|
||||
script:
|
||||
- make distclean || true
|
||||
- ./bootstrap
|
||||
- ./contrib/travis-ci $SSL
|
||||
21536
ChangeLog-2014-12-10
Normal file
21536
ChangeLog-2014-12-10
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
Please note that Wget has more than one ChangeLog file:
|
||||
|
||||
./ChangeLog: documents changes to files in the top-level directory
|
||||
and to files in subdirectories like po/ that don't have
|
||||
their own ChangeLogs
|
||||
|
||||
src/ChangeLog: documents only changes to files in the src directory
|
||||
|
||||
doc/ChangeLog: documents only changes to files in the doc directory
|
||||
|
||||
windows/ChangeLog: documents only changes to files in the windows directory
|
||||
|
||||
msdos/ChangeLog: documents only changes to files in the msdos directory
|
||||
|
||||
When checking to see if a patch you sent in has been applied, please
|
||||
look in the appropriate ChangeLog(s).
|
||||
10
MAILING-LIST
10
MAILING-LIST
@@ -23,15 +23,6 @@ Gmane archives conveniently include messages from both the current
|
||||
list, and the previous one. Messages also show up in the Gmane archives
|
||||
sooner than they do at `lists.gnu.org'.
|
||||
|
||||
Bug Notices List
|
||||
----------------
|
||||
|
||||
Additionally, there is the <wget-notify@addictivecode.org> mailing
|
||||
list. This is a non-discussion list that receives bug report
|
||||
notifications from the bug-tracker. To subscribe to this list, send an
|
||||
email to <wget-notify-join@addictivecode.org>, or visit
|
||||
`http://addictivecode.org/mailman/listinfo/wget-notify'.
|
||||
|
||||
Obsolete Lists
|
||||
--------------
|
||||
|
||||
@@ -47,4 +38,3 @@ for submitting and discussing patches to GNU Wget.
|
||||
|
||||
Messages from <wget-patches@sunsite.dk> are archived at
|
||||
`http://news.gmane.org/gmane.comp.web.wget.patches'.
|
||||
|
||||
|
||||
23
Makefile.am
23
Makefile.am
@@ -41,10 +41,10 @@ distuninstallcheck_listfiles = find . -type f | \
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
# subdirectories in the distribution
|
||||
SUBDIRS = lib src doc po tests util
|
||||
SUBDIRS = lib src doc po tests util testenv
|
||||
|
||||
EXTRA_DIST = ChangeLog.README MAILING-LIST \
|
||||
msdos/ChangeLog msdos/config.h msdos/Makefile.DJ \
|
||||
EXTRA_DIST = MAILING-LIST \
|
||||
msdos/config.h msdos/Makefile.DJ \
|
||||
msdos/Makefile.WC ABOUT-NLS \
|
||||
build-aux/build_info.pl build-aux/git-version-gen .version
|
||||
|
||||
@@ -60,5 +60,20 @@ clean-generic:
|
||||
|
||||
# Arrange so that .tarball-version appears only in the distribution
|
||||
# tarball, and never in a checked-out repository.
|
||||
dist-hook:
|
||||
dist-hook: gen-ChangeLog
|
||||
$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
|
||||
|
||||
gen_start_date = 2014-12-10
|
||||
.PHONY: gen-ChangeLog
|
||||
gen-ChangeLog:
|
||||
$(AM_V_GEN)if test -d .git; then \
|
||||
log_fix="$(srcdir)/build-aux/git-log-fix"; \
|
||||
test -e "$$log_fix" \
|
||||
|| amend_git_log=; \
|
||||
$(top_srcdir)/build-aux/gitlog-to-changelog \
|
||||
$$amend_git_log --since=$(gen_start_date) > $(distdir)/cl-t && \
|
||||
echo >> $(distdir)/cl-t && \
|
||||
cat ChangeLog-2014-12-10 >> $(distdir)/cl-t && \
|
||||
{ rm -f $(distdir)/ChangeLog && \
|
||||
mv $(distdir)/cl-t $(distdir)/ChangeLog; } \
|
||||
fi
|
||||
|
||||
220
NEWS
220
NEWS
@@ -1,11 +1,161 @@
|
||||
GNU Wget NEWS -- history of user-visible changes.
|
||||
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free
|
||||
Software Foundation, Inc.
|
||||
See the end for copying conditions.
|
||||
|
||||
Please send GNU Wget bug reports to <bug-wget@gnu.org>.
|
||||
|
||||
|
||||
* Changes in Wget 1.18
|
||||
|
||||
* By default, on server redirects to a FTP resource, use the original
|
||||
URL to get the local file name. Close CVE-2016-4971. This
|
||||
introduces a backward-incompatibility for HTTP->FTP redirects and
|
||||
any script that relies on the old behaviour must use
|
||||
--trust-server-names.
|
||||
|
||||
* Check the HSTS file is not world-writable before using it.
|
||||
|
||||
* Parse <img srcset> attributes on a recursive download.
|
||||
|
||||
* Fix problem with SNI server names having trailing dot(s)
|
||||
|
||||
* New options --bind-dns-address and --dns-servers.
|
||||
|
||||
* When Wget is built with libiconv, it now converts non-ASCII URIs to
|
||||
the locale's codeset when it creates files. The encoding of the
|
||||
remote files and URIs is taken from --remote-encoding, defaulting to
|
||||
UTF-8. The result is that non-ASCII URIs and files downloaded via
|
||||
HTTP/HTTPS and FTP will have names on the local filesystem that
|
||||
correspond to their remote names.
|
||||
|
||||
* Changes in Wget 1.17.1
|
||||
|
||||
* Fix compile error when IPv6 is disabled or SSL is not present.
|
||||
|
||||
* Fix HSTS memory leak.
|
||||
|
||||
* Fix progress output in non-C locales.
|
||||
|
||||
* Fix SIGSEGV when -N and --content-disposition are used together.
|
||||
|
||||
* Add --check-certificate=quiet to tell wget to not print any warning about
|
||||
invalid certificates.
|
||||
|
||||
* Changes in Wget 1.17
|
||||
|
||||
** Remove FTP passive to active fallback due to privacy concerns.
|
||||
|
||||
** Add support for --if-modified-since.
|
||||
|
||||
** Add support for metalink through --input-metalink and --metalink-over-http.
|
||||
|
||||
** Add support for HSTS through --hsts and --hsts-file.
|
||||
|
||||
** Add option to restrict filenames under VMS.
|
||||
|
||||
** Add support for --rejected-log which logs to a separate file the reasons why
|
||||
URLs are being rejected and some context around it.
|
||||
|
||||
** Add support for FTPS.
|
||||
|
||||
** Do not download/save file on error when --spider enabled
|
||||
|
||||
** Add --convert-file-only option. This option converts only the
|
||||
filename part of the URLs, leaving the rest of the URLs untouched.
|
||||
|
||||
* Changes in Wget 1.16.3
|
||||
|
||||
** Fix a regression introduced by wget 1.16.2 that --quiet is not
|
||||
really quiet anymore.
|
||||
|
||||
* Changes in Wget 1.16.2
|
||||
|
||||
** Native uuid generation on Windows
|
||||
|
||||
** Fix build on Solaris
|
||||
|
||||
** Allow progress bar on stderr when -o is used
|
||||
|
||||
** Accept 5-digit port numbers in FTP EPSV responses.
|
||||
|
||||
** Support older versions of flex.
|
||||
|
||||
** Updated translations.
|
||||
|
||||
* Changes in Wget 1.16.1
|
||||
|
||||
** Add --enable-assert configure option.
|
||||
|
||||
** Use pkg-config to check for libraries presence.
|
||||
|
||||
** Do not limit --secure-protocol=auto|pfs to TLSv1.0.
|
||||
|
||||
** Add --secure-protocol=TLSv1_1|TLSv1_2 .
|
||||
|
||||
** Full C89 source code compliance.
|
||||
|
||||
** Select and use the most secure authentication scheme with HTTP connections.
|
||||
|
||||
** Fix issues with turkish locales.
|
||||
|
||||
** Handle 504 Gateway Timeout.
|
||||
|
||||
** New option --crl-file to load Certificate Revocation Lists.
|
||||
|
||||
** Add valgrind support to tests suite.
|
||||
|
||||
** Fix an off-by-one problem in the progress bar (introduced in 1.16).
|
||||
|
||||
* Changes in Wget 1.16
|
||||
|
||||
** No longer create local symbolic links by default. Closes CVE-2014-4877.
|
||||
|
||||
** Use libpsl for verifying cookie domains.
|
||||
|
||||
** Default progress bar output changed.
|
||||
|
||||
** Introduce --show-progress to force display the progress bar.
|
||||
|
||||
** Introduce --no-config. The wgetrc files will not be read.
|
||||
|
||||
** Introduce --start-pos to allow starting downloads from a specified position.
|
||||
|
||||
** Fix a problem with ISA Server Proxy and keep-alive connections.
|
||||
|
||||
* Changes in Wget 1.15
|
||||
|
||||
** Add support for --method.
|
||||
|
||||
** Add support for file names longer than MAX_FILE.
|
||||
|
||||
** Support FTP listing for the FTP Server on Windows Server 2008 R2.
|
||||
|
||||
** Fix a regression when -c and --content-disposition are used together.
|
||||
|
||||
** Support shorthand URLs in an input file.
|
||||
|
||||
** Fix -c with servers that don't specify a content-length.
|
||||
|
||||
** Add support for MD5-SESS
|
||||
|
||||
** Do not fail on non fatal GNU TLS alerts during handshake.
|
||||
|
||||
** Add support for --https-only. When used wget will follow only
|
||||
HTTPS links in recursive mode.
|
||||
|
||||
** Support Perfect-Forward Secrecy in --secure-protocol.
|
||||
|
||||
** Fix a problem with some IRI links that are not followed when contained in a
|
||||
HTML document.
|
||||
|
||||
** Support some FTP servers that return an empty list with "LIST -a".
|
||||
|
||||
** Specify Host with the HTTP CONNECT method.
|
||||
|
||||
** Use the correct HTTP method on a redirection.
|
||||
|
||||
* Changes in Wget 1.14
|
||||
|
||||
** Add support for content-on-error. It allows to store the HTTP
|
||||
@@ -27,12 +177,12 @@ Please send GNU Wget bug reports to <bug-wget@gnu.org>.
|
||||
|
||||
** Add support for TLS Server Name Indication.
|
||||
|
||||
** Accept the arguments --accept-reject and --reject-regex.
|
||||
** Accept the arguments --accept-regex and --reject-regex.
|
||||
|
||||
** The GNU TLS backend honors correctly the timeout value.
|
||||
|
||||
** Add support for RFC 2617 Digest Access Authentication.
|
||||
|
||||
|
||||
* Changes in Wget 1.13.4
|
||||
|
||||
** Now --version and --help work again.
|
||||
@@ -45,7 +195,7 @@ Please send GNU Wget bug reports to <bug-wget@gnu.org>.
|
||||
is specified.
|
||||
|
||||
** Fix a segfault on an incomplete STYLE tag.
|
||||
|
||||
|
||||
* Changes in Wget 1.13.3
|
||||
|
||||
** Support HTTP/1.1
|
||||
@@ -111,7 +261,7 @@ Please send GNU Wget bug reports to <bug-wget@gnu.org>.
|
||||
|
||||
** Introduce `show_all_dns_entries' to print all IP addresses corresponding to
|
||||
a DNS name when it is resolved.
|
||||
|
||||
|
||||
* Changes in Wget 1.12
|
||||
|
||||
** Mailing list MOVED to bug-wget@gnu.org
|
||||
@@ -165,7 +315,7 @@ forces the percent-encoding of all non-ASCII bytes
|
||||
now documented: save_headers, spider, and user_agent,
|
||||
auth_no_challenge, and keep_session_cookies. Also added documentation
|
||||
for the "lowercase" and "uppercase" values for --restrict-file-names, which had been present since Wget 1.11.
|
||||
|
||||
|
||||
* Changes in Wget 1.11.4
|
||||
|
||||
** Fixed an issue (apparently a regression) where -O would refuse to
|
||||
@@ -179,13 +329,13 @@ locally with content.
|
||||
to a pointer-to-time_t.
|
||||
|
||||
** Translation updates for Catalan.
|
||||
|
||||
|
||||
* Changes in Wget 1.11.3
|
||||
|
||||
** Downgraded -N with -O to a warning, rather than an error.
|
||||
|
||||
** Translation updates
|
||||
|
||||
|
||||
* Changes in Wget 1.11.2
|
||||
|
||||
** Fixed a problem in authenticating over HTTPS through a proxy.
|
||||
@@ -207,7 +357,7 @@ multiple times. This has been fixed in 1.11.2.
|
||||
for improved conformance with RFC 3986. However, this behavior presents
|
||||
problems for some FTP setups, and so they are now preserved again, for
|
||||
FTP URLs only.
|
||||
|
||||
|
||||
* Changes in Wget 1.11.1.
|
||||
|
||||
** Interrupted downloads no longer result in renaming the file
|
||||
@@ -229,7 +379,7 @@ be surprising, and notes that they may change in the future.
|
||||
|
||||
** Documentation of --no-parents now explains how a trailing slash, or
|
||||
lack thereof, in the specified URL, will affect behavior.
|
||||
|
||||
|
||||
* Changes in Wget 1.11.
|
||||
|
||||
** Timestamping now uses the value from the most recent HTTP response,
|
||||
@@ -275,7 +425,7 @@ available at http://hg.addictivecode.org/. Prior to this, the source
|
||||
code was hosted on Subversion (migrated from the original CVS); you can
|
||||
still get access to older tags and branches for Wget in the Subversion
|
||||
repository at http://addictivecode.org/svn/wget/.
|
||||
|
||||
|
||||
* Changes in Wget 1.10.
|
||||
|
||||
** Downloading files larger than 2GB, sometimes referred to as "large
|
||||
@@ -386,9 +536,9 @@ http_password and proxy_password respectively. The login and passwd
|
||||
.wgetrc commands have been deprecated.
|
||||
|
||||
* `wget -b' now works correctly under Windows.
|
||||
|
||||
|
||||
* Wget 1.9.1 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Changes in Wget 1.9.
|
||||
|
||||
** It is now possible to specify that POST method be used for HTTP
|
||||
@@ -440,11 +590,11 @@ values "yes" and "no" along with the traditional "on" and "off".
|
||||
** It is now possible to specify decimal values for timeouts, waiting
|
||||
periods, and download rate. For instance, `--wait=0.5' now works as
|
||||
expected, as does `--dns-timeout=0.5' and even `--limit-rate=2.5k'.
|
||||
|
||||
|
||||
* Wget 1.8.2 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Wget 1.8.1 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Changes in Wget 1.8.
|
||||
|
||||
** A new progress indicator is now available and used by default.
|
||||
@@ -504,9 +654,9 @@ no longer translated to `?', nor `%2B' to `+'. Unsafe characters
|
||||
which are not reserved are still escaped, of course.
|
||||
|
||||
** No more than 20 successive redirections are allowed.
|
||||
|
||||
|
||||
* Wget 1.7.1 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Changes in Wget 1.7.
|
||||
|
||||
** SSL (`https') pages now work if you compile Wget with SSL support;
|
||||
@@ -548,7 +698,7 @@ large sites (thousands of documents).
|
||||
documentation. (The last version that shipped with a man page was
|
||||
1.4.5). To get this, you need to have pod2man from the Perl
|
||||
distribution installed on your system.
|
||||
|
||||
|
||||
* Changes in Wget 1.6
|
||||
|
||||
** Administrative changes.
|
||||
@@ -599,13 +749,13 @@ passive_ftp is the only .wgetrc command which takes a lockable Boolean.
|
||||
bound to multiple IP addresses.
|
||||
|
||||
** wget now accepts (illegal per HTTP spec) relative URLs in HTTP redirects.
|
||||
|
||||
|
||||
* Wget 1.5.3 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Wget 1.5.2 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Wget 1.5.1 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Changes in Wget 1.5.0
|
||||
|
||||
** Wget speaks many languages!
|
||||
@@ -640,7 +790,7 @@ ASCII type transfer:
|
||||
|
||||
wget "ftp://ftp.somewhere.com/welcome.msg;type=a"
|
||||
|
||||
** `--help' and `--version' options have been redone to to conform to
|
||||
** `--help' and `--version' options have been redone to conform to
|
||||
standards set by other GNU utilities.
|
||||
|
||||
** Wget should now be compilable under MS Windows environment. MS
|
||||
@@ -651,11 +801,11 @@ download.
|
||||
|
||||
** The manual page, now hopelessly out of date, is no longer
|
||||
distributed with Wget.
|
||||
|
||||
|
||||
* Wget 1.4.5 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Wget 1.4.4 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Changes in Wget 1.4.3
|
||||
|
||||
** Wget is now a GNU utility.
|
||||
@@ -671,7 +821,7 @@ distributed with Wget.
|
||||
** Global wgetrc now goes to /usr/local/etc (i.e. $sysconfdir).
|
||||
|
||||
** Lots of bugfixes.
|
||||
|
||||
|
||||
* Changes in Wget 1.4.2
|
||||
|
||||
** New mirror site at ftp://sunsite.auc.dk/pub/infosystems/wget/,
|
||||
@@ -689,7 +839,7 @@ files.
|
||||
** --convert-links should work now.
|
||||
|
||||
** Minor bugfixes.
|
||||
|
||||
|
||||
* Changes in Wget 1.4.1
|
||||
|
||||
** Minor bugfixes.
|
||||
@@ -697,7 +847,7 @@ files.
|
||||
** Added -I (the opposite of -X).
|
||||
|
||||
** Dot tracing is now customizable; try wget --dot-style=binary
|
||||
|
||||
|
||||
* Changes in Wget 1.4.0
|
||||
|
||||
** Wget 1.4.0 [formerly known as Geturl] is an extensive rewrite of
|
||||
@@ -778,7 +928,7 @@ turn on mirroring options).
|
||||
** Lots of small features I can't remember. :-)
|
||||
|
||||
** A host of bugfixes.
|
||||
|
||||
|
||||
* Changes in Geturl 1.3
|
||||
|
||||
** Added FTP globbing support (ftp://fly.cc.fer.hr/*)
|
||||
@@ -796,9 +946,9 @@ turn on mirroring options).
|
||||
** Added support for robots.txt
|
||||
|
||||
** Fixed some minor bugs
|
||||
|
||||
|
||||
* Geturl 1.2 is a bugfix release with no user-visible changes.
|
||||
|
||||
|
||||
* Changes in Geturl 1.1
|
||||
|
||||
** REST supported in FTP
|
||||
@@ -816,7 +966,7 @@ geturl -vo log http://fly.cc.fer.hr/
|
||||
** <base href="xxx"> supported
|
||||
|
||||
** autoconf supported
|
||||
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Copyright information:
|
||||
|
||||
|
||||
180
README.checkout
180
README.checkout
@@ -4,8 +4,9 @@ Compiling From Repository Sources
|
||||
does not contain automatically-generated files, even when these are
|
||||
normally present in the distribution tarballs. Therefore, to build GNU
|
||||
Wget from the sources in the repository, you'll need to have one or
|
||||
more of the following (note that gettext, OpenSSL, libidn and libiconv
|
||||
are not absolutely required):
|
||||
more of the following (note that gettext, OpenSSL, GnuTLS, libidn,
|
||||
libiconv, libpsl, libpcre, pkg-config, libmetalink and GnuPG are not
|
||||
absolutely required):
|
||||
|
||||
* [20]autoconf (currently, GNU Wget requires version 2.61). This is
|
||||
needed to generate the configure script from configure.in. This is
|
||||
@@ -23,12 +24,18 @@ Compiling From Repository Sources
|
||||
* [23]Perl, if you wish to generate the wget(1) manpage, or run the
|
||||
tests in the tests/ sub directory. Tarball distributions include an
|
||||
already-generated wget.1 manual. The command "make check" runs the
|
||||
test suite written in perl. To execute all the tests you need
|
||||
[24]libwww-perl perl library. If "perl -MCPAN -e 'install
|
||||
Bundle::LWP'" fails then you most likely don't have cpan module
|
||||
installed. First download [25]CPAN and [26]install it. Then execute
|
||||
"perl -MCPAN -e 'install Bundle::LWP'". Now "make check" should
|
||||
pass most of the tests in the test suite.
|
||||
test suite written in perl and python (see below). To execute all the tests
|
||||
you need libwww-perl and libio-socket-ssl-perl perl library.
|
||||
GNU/Linux distros likely have these two libraries packaged.
|
||||
If not, install them directly with "perl -MCPAN -e 'install Bundle::LWP'"[24].
|
||||
If that fails then you most likely don't have the CPAN module installed.
|
||||
First download [25]CPAN and [26]install it, then try again the above command.
|
||||
Now "make check" should pass most of the tests in the test suite.
|
||||
|
||||
* [45]Python, if you want to run the tests in the testenv/ subdirectory.
|
||||
Keep in mind that "make check" will try to run all the perl and python
|
||||
tests. More information about the test suite below in the section
|
||||
"Testing and development".
|
||||
|
||||
* [27]texinfo in order to generate Info, PostScript and/or HTML
|
||||
documentation. You don't need texinfo in order to generate the
|
||||
@@ -46,32 +53,61 @@ Compiling From Repository Sources
|
||||
to export M4=<new m4 path>, to be sure that autoconf/automake use
|
||||
it instead of the old one.
|
||||
|
||||
* [29]OpenSSL to handle encrypted web sessions. You almost certainly
|
||||
want this. It is not enough to have the library installed; you need
|
||||
to have the header files available to compile against as well. For
|
||||
GNU/Linux systems, this usually means installing a "developer"
|
||||
package for openssl (for example, [30]Debian systems require
|
||||
installation of the libssl-dev package). Alternatively, you can
|
||||
compile GNU Wget against the [31]GNUTLS library instead, by
|
||||
specifying --with-ssl=gnutls to the ./configure script; however,
|
||||
building against GNUTLS is currently experimental, and not
|
||||
officially supported. If you have OpenSSL and its development
|
||||
headers installed, but don't want to build Wget with it, specify
|
||||
--without-ssl to the ./configure script.
|
||||
* [29]GnuTLS to allow encrypted data transfer (HTTPS).
|
||||
You need the header files and the library installed.
|
||||
As an alternative, you can use [30]OpenSSL by specifying
|
||||
--with-ssl=openssl to the ./configure script.
|
||||
If you do not want HTTPS support, specify --without-ssl to the
|
||||
./configure script.
|
||||
If you want to compile+link a non-system library version use
|
||||
--with-libgnutls-prefix (or if having pkg-config: see description
|
||||
below).
|
||||
|
||||
* [32]libidn is required for IDN/IRI support (non-ASCII characters
|
||||
* [30]OpenSSL to allow encrypted data transfer (HTTPS) an
|
||||
alternative to [31]GnuTLS.
|
||||
You need the header files and the library installed.
|
||||
If you want to compile+link a non-system library version use
|
||||
--with-libssl-prefix (or if having pkg-config: see description below).
|
||||
|
||||
* [31]libidn is required for IDN/IRI support (non-ASCII characters
|
||||
within what would otherwise be URLs).
|
||||
|
||||
* [33]libiconv is required on non-GNU systems, for IDN/IRI support.
|
||||
* [32]libiconv is required on non-GNU systems, for IDN/IRI support.
|
||||
On GNU systems, the functionality provided by libiconv is already
|
||||
present in the system libraries.
|
||||
|
||||
* [34]git is used to fetch gnulib files trough the bootstrap.sh script.
|
||||
* [33]git is used to fetch gnulib files trough the bootstrap.sh script.
|
||||
|
||||
* [34]libpsl is required for using a public suffix list to check for valid
|
||||
cookie domains. You need the header files and the library installed.
|
||||
|
||||
* [35]libpcre is required for using Perl-compatible regular expressions
|
||||
with --accept-regex and --reject-regex. You need the header files and
|
||||
the library installed to compile and link Wget with PCRE support.
|
||||
|
||||
* [36]pkg-config helps the ./configure script to find installed libraries.
|
||||
Most libraries provide a pkg-config file (.pc extension) with
|
||||
information about dependencies, header file and library locations.
|
||||
Distributions deliver their specific .pc file to each library.
|
||||
If you want to compile+link against your own library version, make a
|
||||
copy of the appropriate .pc file and amend it to your needs (e.g. edit
|
||||
the line starting with prefix=). Before you execute the ./configure
|
||||
script, set (and export) PKG_CONFIG_PATH to the directory where you
|
||||
saved the .pc file. Example:
|
||||
$ PKG_CONFIG_PATH="." ./configure
|
||||
|
||||
* [46]libmetalink is needed to enable Metalink files support.
|
||||
|
||||
* [47]GnuPG with GPGME is used to verify GPG-signed Metalink resources.
|
||||
|
||||
* [48]libcares is needed to bind DNS resolving to a given IP address.
|
||||
The command line options --dns-servers and --bind-dns-address are
|
||||
only available when configured with --with-cares.
|
||||
|
||||
For those who might be confused as to what to do once they check out
|
||||
the source code, considering configure and Makefile do not yet exist at
|
||||
that point, a shell script called bootstrap.sh has been provided. After
|
||||
calling ./bootstrap.sh you're ready to build GNU Wget in the normal
|
||||
that point, a shell script called bootstrap has been provided. After
|
||||
calling ./bootstrap you're ready to build GNU Wget in the normal
|
||||
fashion, with ./configure and make.
|
||||
|
||||
So, to sum up, after checking out the source code as described above,
|
||||
@@ -80,15 +116,48 @@ Compiling From Repository Sources
|
||||
$ cd wget # assumes you've cloned a repository to "./wget"
|
||||
2. Generate all the automatically-generated files required prior to
|
||||
configuring the package:
|
||||
$ ./bootstrap.sh
|
||||
$ ./bootstrap
|
||||
3. Configure the package and compile it:
|
||||
$ ./configure [some_parameters]
|
||||
$ ./configure --enable-assert [some_parameters]
|
||||
$ make
|
||||
4. Hack, compile, test, hack, compile, test...
|
||||
$ src/wget --version
|
||||
GNU Wget 1.12-devel (9cb2563197bc)
|
||||
|
||||
Copyright © 2008,2010 Free Software Foundation, Inc.
|
||||
Testing and development
|
||||
|
||||
All developers are requested to enable the assertions on their development
|
||||
builds to ensure a stable codebase. Assertions are added to state certain
|
||||
assumptions about the code and its data which all developers should be mindful
|
||||
of. To enable assertions, run the configure command with the --enable-assert
|
||||
option, like this:
|
||||
|
||||
$ ./configure --enable-assert [other configure options]
|
||||
|
||||
Both the Perl and Python test suites (test/ and testenv/) include support for GDB and Valgrind.
|
||||
The environment variables GDB_TESTS and VALGRIND_TESTS are available to
|
||||
enable such wrappers. If specified, Wget would be run through either of them
|
||||
during the test. For example:
|
||||
|
||||
$ cd testenv
|
||||
$ VALGRIND_TESTS=1 ./Test-O.py
|
||||
|
||||
That would execute Test-O.py test case, but running Wget through Valgrind.
|
||||
|
||||
GDB has preference over Valgrind. If both variables have been asserted,
|
||||
Wget would be run through GDB.
|
||||
|
||||
If you run a test case through GDB, please bear in mind that it could give
|
||||
a false negative. This is because some tests that expect Wget to fail
|
||||
rely on Wget's return code. However, when run through GDB, its return code
|
||||
will always be zero, causing the test to claim failure. This wrapper for
|
||||
GDB is, however, very useful to tackle bugs, allowing one to write a test case
|
||||
for some specific bug and then using GDB to fix it more easily. Otherwise,
|
||||
a dedicated server would have to be set up and write a custom CGI just to reproduce
|
||||
that bug, which might be tedious. Tests should only be run through GDB for that purpose.
|
||||
|
||||
|
||||
Copyright (C) 2008,2010,2014,2015 Free Software Foundation, Inc.
|
||||
License GPLv3+: GNU GPL version 3 or later
|
||||
<http://www.gnu.org/licenses/gpl.html>.
|
||||
This is free software: you are free to change and redistribute it.
|
||||
@@ -96,21 +165,21 @@ Compiling From Repository Sources
|
||||
|
||||
Originally written by Hrvoje Niksic <hniksic@xemacs.org>.
|
||||
|
||||
* [35]Edit
|
||||
* [36]Comments
|
||||
* [37]Info
|
||||
* [38]Attachments
|
||||
* [36]Edit
|
||||
* [37]Comments
|
||||
* [38]Info
|
||||
* [39]Attachments
|
||||
* More Actions:
|
||||
[Raw Text................] Do
|
||||
|
||||
* [39]MoinMoin Powered
|
||||
* [40]Python Powered
|
||||
* [41]GPL licensed
|
||||
* [42]Valid HTML 4.01
|
||||
* [40]MoinMoin Powered
|
||||
* [41]Python Powered
|
||||
* [42]GPL licensed
|
||||
* [43]Valid HTML 4.01
|
||||
__________________________________________________________________
|
||||
|
||||
All content © 2007 Free Software Foundation. For terms of use,
|
||||
redistribution, and modification, please see the [43]WikiLicense page.
|
||||
All content (C) 2007 Free Software Foundation. For terms of use,
|
||||
redistribution, and modification, please see the [45]WikiLicense page.
|
||||
|
||||
References
|
||||
|
||||
@@ -123,18 +192,23 @@ References
|
||||
26. http://apthorpe.cynistar.net/code/configuring_cpan.html
|
||||
27. http://www.gnu.org/software/texinfo/
|
||||
28. http://www.gnu.org/software/gettext/
|
||||
29. http://www.openssl.org/
|
||||
30. http://www.debian.org/
|
||||
31. http://www.gnu.org/software/gnutls/
|
||||
32. http://www.gnu.org/software/libidn/
|
||||
33. http://www.gnu.org/software/libiconv/
|
||||
34. http://git-scm.com/
|
||||
35. http://wget.addictivecode.org/CompilingRepoSources?action=edit&editor=text
|
||||
36. http://wget.addictivecode.org/CompilingRepoSources
|
||||
37. http://wget.addictivecode.org/CompilingRepoSources?action=info
|
||||
38. http://wget.addictivecode.org/CompilingRepoSources?action=AttachFile
|
||||
39. http://moinmo.in/
|
||||
40. http://moinmo.in/Python
|
||||
41. http://moinmo.in/GPL
|
||||
42. http://validator.w3.org/check?uri=referer
|
||||
43. http://wget.addictivecode.org/WikiLicense
|
||||
29. http://www.gnu.org/software/gnutls/
|
||||
30. http://www.openssl.org/
|
||||
31. http://www.gnu.org/software/libidn/
|
||||
32. http://www.gnu.org/software/libiconv/
|
||||
33. http://git-scm.com/
|
||||
34. https://github.com/rockdaboot/libpsl
|
||||
35. http://www.pcre.org
|
||||
36. http://wget.addictivecode.org/CompilingRepoSources?action=edit&editor=text
|
||||
37. http://wget.addictivecode.org/CompilingRepoSources
|
||||
38. http://wget.addictivecode.org/CompilingRepoSources?action=info
|
||||
39. http://wget.addictivecode.org/CompilingRepoSources?action=AttachFile
|
||||
40. http://moinmo.in/
|
||||
41. http://moinmo.in/Python
|
||||
42. http://moinmo.in/GPL
|
||||
43. http://validator.w3.org/check?uri=referer
|
||||
44. http://wget.addictivecode.org/WikiLicense
|
||||
45. https://www.python.org/
|
||||
46. https://launchpad.net/libmetalink
|
||||
47. https://www.gnupg.org
|
||||
48. http://c-ares.haxx.se/
|
||||
|
||||
237
bootstrap
237
bootstrap
@@ -1,10 +1,10 @@
|
||||
#! /bin/sh
|
||||
# Print a version string.
|
||||
scriptversion=2012-07-06.11; # UTC
|
||||
scriptversion=2013-12-05.23; # UTC
|
||||
|
||||
# Bootstrap this package from checked-out sources.
|
||||
|
||||
# Copyright (C) 2003-2012 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2003-2014 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -77,15 +77,32 @@ Running without arguments will suffice in most cases.
|
||||
EOF
|
||||
}
|
||||
|
||||
warn()
|
||||
# warnf_ FORMAT-STRING ARG1...
|
||||
warnf_ ()
|
||||
{
|
||||
for i
|
||||
do
|
||||
echo "$i"
|
||||
done | sed -e "s/^/$me: /" >&2
|
||||
warnf_format_=$1
|
||||
shift
|
||||
nl='
|
||||
'
|
||||
case $* in
|
||||
*$nl*) me_=$(printf "$me"|tr "$nl|" '??')
|
||||
printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
|
||||
*) printf "$me: $warnf_format_" "$@" ;;
|
||||
esac >&2
|
||||
}
|
||||
|
||||
die() { warn "$@"; exit 1; }
|
||||
# warn_ WORD1...
|
||||
warn_ ()
|
||||
{
|
||||
# If IFS does not start with ' ', set it and emit the warning in a subshell.
|
||||
case $IFS in
|
||||
' '*) warnf_ '%s\n' "$*";;
|
||||
*) (IFS=' '; warn_ "$@");;
|
||||
esac
|
||||
}
|
||||
|
||||
# die WORD1...
|
||||
die() { warn_ "$@"; exit 1; }
|
||||
|
||||
# Configuration.
|
||||
|
||||
@@ -123,20 +140,21 @@ po_download_command_format2=\
|
||||
"wget --mirror -nd -q -np -A.po -P '%s' \
|
||||
http://translationproject.org/latest/%s/"
|
||||
|
||||
# Prefer a non-empty tarname (4th argument of AC_INIT if given), else
|
||||
# fall back to the package name (1st argument with munging)
|
||||
extract_package_name='
|
||||
/^AC_INIT(/{
|
||||
/.*,.*,.*, */{
|
||||
s///
|
||||
s/[][]//g
|
||||
s/)$//
|
||||
/^AC_INIT(\[*/{
|
||||
s///
|
||||
/^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{
|
||||
s//\1/
|
||||
s/[],)].*//
|
||||
p
|
||||
q
|
||||
}
|
||||
s/AC_INIT(\[*//
|
||||
s/]*,.*//
|
||||
s/[],)].*//
|
||||
s/^GNU //
|
||||
y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
|
||||
s/[^A-Za-z0-9_]/-/g
|
||||
s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g
|
||||
p
|
||||
}
|
||||
'
|
||||
@@ -191,12 +209,28 @@ bootstrap_sync=false
|
||||
# Use git to update gnulib sources
|
||||
use_git=true
|
||||
|
||||
check_exists() {
|
||||
if test "$1" = "--verbose"; then
|
||||
($2 --version </dev/null) >/dev/null 2>&1
|
||||
if test $? -ge 126; then
|
||||
# If not found, run with diagnostics as one may be
|
||||
# presented with env variables to set to find the right version
|
||||
($2 --version </dev/null)
|
||||
fi
|
||||
else
|
||||
($1 --version </dev/null) >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
test $? -lt 126
|
||||
}
|
||||
|
||||
# find_tool ENVVAR NAMES...
|
||||
# -------------------------
|
||||
# Search for a required program. Use the value of ENVVAR, if set,
|
||||
# otherwise find the first of the NAMES that can be run (i.e.,
|
||||
# supports --version). If found, set ENVVAR to the program name,
|
||||
# die otherwise.
|
||||
# otherwise find the first of the NAMES that can be run.
|
||||
# If found, set ENVVAR to the program name, die otherwise.
|
||||
#
|
||||
# FIXME: code duplication, see also gnu-web-doc-update.
|
||||
find_tool ()
|
||||
{
|
||||
find_tool_envvar=$1
|
||||
@@ -204,27 +238,21 @@ find_tool ()
|
||||
find_tool_names=$@
|
||||
eval "find_tool_res=\$$find_tool_envvar"
|
||||
if test x"$find_tool_res" = x; then
|
||||
for i
|
||||
do
|
||||
if ($i --version </dev/null) >/dev/null 2>&1; then
|
||||
find_tool_res=$i
|
||||
break
|
||||
for i; do
|
||||
if check_exists $i; then
|
||||
find_tool_res=$i
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
find_tool_error_prefix="\$$find_tool_envvar: "
|
||||
fi
|
||||
test x"$find_tool_res" != x \
|
||||
|| die "one of these is required: $find_tool_names"
|
||||
($find_tool_res --version </dev/null) >/dev/null 2>&1 \
|
||||
|| die "${find_tool_error_prefix}cannot run $find_tool_res --version"
|
||||
if test x"$find_tool_res" = x; then
|
||||
warn_ "one of these is required: $find_tool_names;"
|
||||
die "alternatively set $find_tool_envvar to a compatible tool"
|
||||
fi
|
||||
eval "$find_tool_envvar=\$find_tool_res"
|
||||
eval "export $find_tool_envvar"
|
||||
}
|
||||
|
||||
# Find sha1sum, named gsha1sum on MacPorts, and shasum on Mac OS X 10.6.
|
||||
find_tool SHA1SUM sha1sum gsha1sum shasum
|
||||
|
||||
# Override the default configuration, if necessary.
|
||||
# Make sure that bootstrap.conf is sourced from the current directory
|
||||
# if we were invoked as "sh bootstrap".
|
||||
@@ -236,12 +264,12 @@ esac
|
||||
# Extra files from gnulib, which override files from other sources.
|
||||
test -z "${gnulib_extra_files}" && \
|
||||
gnulib_extra_files="
|
||||
$build_aux/install-sh
|
||||
$build_aux/mdate-sh
|
||||
$build_aux/texinfo.tex
|
||||
$build_aux/depcomp
|
||||
$build_aux/config.guess
|
||||
$build_aux/config.sub
|
||||
build-aux/install-sh
|
||||
build-aux/mdate-sh
|
||||
build-aux/texinfo.tex
|
||||
build-aux/depcomp
|
||||
build-aux/config.guess
|
||||
build-aux/config.sub
|
||||
doc/INSTALL
|
||||
"
|
||||
|
||||
@@ -287,34 +315,34 @@ if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
|
||||
die "Bootstrapping from a non-checked-out distribution is risky."
|
||||
fi
|
||||
|
||||
# Ensure that lines starting with ! sort last, per gitignore conventions
|
||||
# for whitelisting exceptions after a more generic blacklist pattern.
|
||||
sort_patterns() {
|
||||
sort -u "$@" | sed '/^!/ {
|
||||
H
|
||||
d
|
||||
}
|
||||
$ {
|
||||
P
|
||||
x
|
||||
s/^\n//
|
||||
}' | sed '/^$/d'
|
||||
# Strip blank and comment lines to leave significant entries.
|
||||
gitignore_entries() {
|
||||
sed '/^#/d; /^$/d' "$@"
|
||||
}
|
||||
|
||||
# If $STR is not already on a line by itself in $FILE, insert it,
|
||||
# sorting the new contents of the file and replacing $FILE with the result.
|
||||
insert_sorted_if_absent() {
|
||||
# If $STR is not already on a line by itself in $FILE, insert it at the start.
|
||||
# Entries are inserted at the start of the ignore list to ensure existing
|
||||
# entries starting with ! are not overridden. Such entries support
|
||||
# whitelisting exceptions after a more generic blacklist pattern.
|
||||
insert_if_absent() {
|
||||
file=$1
|
||||
str=$2
|
||||
test -f $file || touch $file
|
||||
echo "$str" | sort_patterns - $file | cmp -s - $file > /dev/null \
|
||||
|| { echo "$str" | sort_patterns - $file > $file.bak \
|
||||
&& mv $file.bak $file; } \
|
||||
|| die "insert_sorted_if_absent $file $str: failed"
|
||||
test -r $file || die "Error: failed to read ignore file: $file"
|
||||
duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
|
||||
if [ "$duplicate_entries" ] ; then
|
||||
die "Error: Duplicate entries in $file: " $duplicate_entries
|
||||
fi
|
||||
linesold=$(gitignore_entries $file | wc -l)
|
||||
linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
|
||||
if [ $linesold != $linesnew ] ; then
|
||||
{ echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
|
||||
|| die "insert_if_absent $file $str: failed"
|
||||
fi
|
||||
}
|
||||
|
||||
# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
|
||||
# insert_sorted_if_absent.
|
||||
# insert_if_absent.
|
||||
insert_vc_ignore() {
|
||||
vc_ignore_file="$1"
|
||||
pattern="$2"
|
||||
@@ -325,7 +353,7 @@ insert_vc_ignore() {
|
||||
# .gitignore entry.
|
||||
pattern=$(echo "$pattern" | sed s,^,/,);;
|
||||
esac
|
||||
insert_sorted_if_absent "$vc_ignore_file" "$pattern"
|
||||
insert_if_absent "$vc_ignore_file" "$pattern"
|
||||
}
|
||||
|
||||
# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
|
||||
@@ -335,8 +363,7 @@ grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
|
||||
grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
|
||||
>/dev/null && found_aux_dir=yes
|
||||
test $found_aux_dir = yes \
|
||||
|| die "expected line not found in configure.ac. Add the following:" \
|
||||
" AC_CONFIG_AUX_DIR([$build_aux])"
|
||||
|| die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
|
||||
|
||||
# If $build_aux doesn't exist, create it now, otherwise some bits
|
||||
# below will malfunction. If creating it, also mark it as ignored.
|
||||
@@ -391,7 +418,7 @@ sort_ver() { # sort -V is not generally available
|
||||
get_version() {
|
||||
app=$1
|
||||
|
||||
$app --version >/dev/null 2>&1 || return 1
|
||||
$app --version >/dev/null 2>&1 || { $app --version; return 1; }
|
||||
|
||||
$app --version 2>&1 |
|
||||
sed -n '# Move version to start of line.
|
||||
@@ -442,7 +469,7 @@ check_versions() {
|
||||
automake-ng|aclocal-ng)
|
||||
app=${app%-ng}
|
||||
($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
|
||||
warn "Error: '$app' not found or not from Automake-NG"
|
||||
warn_ "Error: '$app' not found or not from Automake-NG"
|
||||
ret=1
|
||||
continue
|
||||
} ;;
|
||||
@@ -450,22 +477,22 @@ check_versions() {
|
||||
if [ "$req_ver" = "-" ]; then
|
||||
# Merely require app to exist; not all prereq apps are well-behaved
|
||||
# so we have to rely on $? rather than get_version.
|
||||
$app --version >/dev/null 2>&1
|
||||
if [ 126 -le $? ]; then
|
||||
warn "Error: '$app' not found"
|
||||
if ! check_exists --verbose $app; then
|
||||
warn_ "Error: '$app' not found"
|
||||
ret=1
|
||||
fi
|
||||
else
|
||||
# Require app to produce a new enough version string.
|
||||
inst_ver=$(get_version $app)
|
||||
if [ ! "$inst_ver" ]; then
|
||||
warn "Error: '$app' not found"
|
||||
warn_ "Error: '$app' not found"
|
||||
ret=1
|
||||
else
|
||||
latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
|
||||
if [ ! "$latest_ver" = "$inst_ver" ]; then
|
||||
warn "Error: '$app' version == $inst_ver is too old" \
|
||||
" '$app' version >= $req_ver is required"
|
||||
warnf_ '%s\n' \
|
||||
"Error: '$app' version == $inst_ver is too old" \
|
||||
" '$app' version >= $req_ver is required"
|
||||
ret=1
|
||||
fi
|
||||
fi
|
||||
@@ -483,6 +510,12 @@ print_versions() {
|
||||
# can't depend on column -t
|
||||
}
|
||||
|
||||
# Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
|
||||
# Also find the compatible sha1 utility on the BSDs
|
||||
if test x"$SKIP_PO" = x; then
|
||||
find_tool SHA1SUM sha1sum gsha1sum shasum sha1
|
||||
fi
|
||||
|
||||
use_libtool=0
|
||||
# We'd like to use grep -E, to see if any of LT_INIT,
|
||||
# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
|
||||
@@ -528,13 +561,21 @@ if ! printf "$buildreq" | check_versions; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Warn the user if autom4te appears to be broken; this causes known
|
||||
# issues with at least gettext 0.18.3.
|
||||
probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
|
||||
if test "x$probe" != xhi; then
|
||||
warn_ "WARNING: your autom4te wrapper eats stdin;"
|
||||
warn_ "if bootstrap fails, consider upgrading your autotools"
|
||||
fi
|
||||
|
||||
echo "$0: Bootstrapping from checked-out $package sources..."
|
||||
|
||||
# See if we can use gnulib's git-merge-changelog merge driver.
|
||||
if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
|
||||
if $use_git && test -d .git && check_exists git; then
|
||||
if git config merge.merge-changelog.driver >/dev/null ; then
|
||||
:
|
||||
elif (git-merge-changelog --version) >/dev/null 2>/dev/null ; then
|
||||
elif check_exists git-merge-changelog; then
|
||||
echo "$0: initializing git-merge-changelog driver"
|
||||
git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
|
||||
git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
|
||||
@@ -554,17 +595,21 @@ git_modules_config () {
|
||||
test -f .gitmodules && git config --file .gitmodules "$@"
|
||||
}
|
||||
|
||||
gnulib_path=$(git_modules_config submodule.gnulib.path)
|
||||
test -z "$gnulib_path" && gnulib_path=gnulib
|
||||
if $use_git; then
|
||||
gnulib_path=$(git_modules_config submodule.gnulib.path)
|
||||
test -z "$gnulib_path" && gnulib_path=gnulib
|
||||
fi
|
||||
|
||||
# Get gnulib files.
|
||||
# Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a
|
||||
# submodule, for use in the rest of the script.
|
||||
|
||||
case ${GNULIB_SRCDIR--} in
|
||||
-)
|
||||
# Note that $use_git is necessarily true in this case.
|
||||
if git_modules_config submodule.gnulib.url >/dev/null; then
|
||||
echo "$0: getting gnulib files..."
|
||||
git submodule init || exit $?
|
||||
git submodule update || exit $?
|
||||
git submodule init -- "$gnulib_path" || exit $?
|
||||
git submodule update -- "$gnulib_path" || exit $?
|
||||
|
||||
elif [ ! -d "$gnulib_path" ]; then
|
||||
echo "$0: getting gnulib files..."
|
||||
@@ -581,8 +626,8 @@ case ${GNULIB_SRCDIR--} in
|
||||
GNULIB_SRCDIR=$gnulib_path
|
||||
;;
|
||||
*)
|
||||
# Use GNULIB_SRCDIR as a reference.
|
||||
if test -d "$GNULIB_SRCDIR"/.git && \
|
||||
# Use GNULIB_SRCDIR directly or as a reference.
|
||||
if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
|
||||
git_modules_config submodule.gnulib.url >/dev/null; then
|
||||
echo "$0: getting gnulib files..."
|
||||
if git submodule -h|grep -- --reference > /dev/null; then
|
||||
@@ -593,13 +638,14 @@ case ${GNULIB_SRCDIR--} in
|
||||
# This fallback allows at least git 1.5.5.
|
||||
if test -f "$gnulib_path"/gnulib-tool; then
|
||||
# Since file already exists, assume submodule init already complete.
|
||||
git submodule update || exit $?
|
||||
git submodule update -- "$gnulib_path" || exit $?
|
||||
else
|
||||
# Older git can't clone into an empty directory.
|
||||
rmdir "$gnulib_path" 2>/dev/null
|
||||
git clone --reference "$GNULIB_SRCDIR" \
|
||||
"$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
|
||||
&& git submodule init && git submodule update \
|
||||
&& git submodule init -- "$gnulib_path" \
|
||||
&& git submodule update -- "$gnulib_path" \
|
||||
|| exit $?
|
||||
fi
|
||||
fi
|
||||
@@ -608,12 +654,19 @@ case ${GNULIB_SRCDIR--} in
|
||||
;;
|
||||
esac
|
||||
|
||||
# $GNULIB_SRCDIR now points to the version of gnulib to use, and
|
||||
# we no longer need to use git or $gnulib_path below here.
|
||||
|
||||
if $bootstrap_sync; then
|
||||
cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
|
||||
echo "$0: updating bootstrap and restarting..."
|
||||
case $(sh -c 'echo "$1"' -- a) in
|
||||
a) ignored=--;;
|
||||
*) ignored=ignored;;
|
||||
esac
|
||||
exec sh -c \
|
||||
'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
|
||||
-- "$GNULIB_SRCDIR/build-aux/bootstrap" \
|
||||
$ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
|
||||
"$0" "$@" --no-bootstrap-sync
|
||||
}
|
||||
fi
|
||||
@@ -661,11 +714,10 @@ update_po_files() {
|
||||
cksum_file="$ref_po_dir/$po.s1"
|
||||
if ! test -f "$cksum_file" ||
|
||||
! test -f "$po_dir/$po.po" ||
|
||||
! $SHA1SUM -c --status "$cksum_file" \
|
||||
< "$new_po" > /dev/null; then
|
||||
! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
|
||||
echo "$me: updated $po_dir/$po.po..."
|
||||
cp "$new_po" "$po_dir/$po.po" \
|
||||
&& $SHA1SUM < "$new_po" > "$cksum_file"
|
||||
&& $SHA1SUM < "$new_po" > "$cksum_file" || return
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -761,7 +813,7 @@ version_controlled_file() {
|
||||
grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
|
||||
grep '^/[^/]*/[0-9]' > /dev/null
|
||||
else
|
||||
warn "no version control for $file?"
|
||||
warn_ "no version control for $file?"
|
||||
false
|
||||
fi
|
||||
}
|
||||
@@ -870,20 +922,21 @@ find "$m4_base" "$source_base" \
|
||||
-depth \( -name '*.m4' -o -name '*.[ch]' \) \
|
||||
-type l -xtype l -delete > /dev/null 2>&1
|
||||
|
||||
# Invoke autoreconf with --force --install to ensure upgrades of tools
|
||||
# such as ylwrap.
|
||||
AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
|
||||
|
||||
# Some systems (RHEL 5) are using ancient autotools, for which the
|
||||
# --no-recursive option had not been invented. Detect that lack and
|
||||
# omit the option when it's not supported. FIXME in 2017: remove this
|
||||
# hack when RHEL 5 autotools are updated, or when they become irrelevant.
|
||||
no_recursive=
|
||||
case $($AUTORECONF --help) in
|
||||
*--no-recursive*) no_recursive=--no-recursive;;
|
||||
*--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
|
||||
esac
|
||||
|
||||
# Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
|
||||
echo "running: AUTOPOINT=true LIBTOOLIZE=true " \
|
||||
"$AUTORECONF --verbose --install $no_recursive -I $m4_base $ACLOCAL_FLAGS"
|
||||
AUTOPOINT=true LIBTOOLIZE=true \
|
||||
$AUTORECONF --verbose --install $no_recursive -I $m4_base $ACLOCAL_FLAGS \
|
||||
echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
|
||||
AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
|
||||
|| die "autoreconf failed"
|
||||
|
||||
# Get some extra files from gnulib, overriding existing files.
|
||||
|
||||
@@ -31,17 +31,25 @@ announce-gen
|
||||
base32
|
||||
bind
|
||||
c-ctype
|
||||
c-strcase
|
||||
c-strcasestr
|
||||
clock-time
|
||||
close
|
||||
connect
|
||||
dirname
|
||||
fcntl
|
||||
flock
|
||||
fnmatch
|
||||
futimens
|
||||
ftello
|
||||
getaddrinfo
|
||||
getline
|
||||
getopt-gnu
|
||||
getpass-gnu
|
||||
getpeername
|
||||
getsockname
|
||||
gettext
|
||||
gitlog-to-changelog
|
||||
git-version-gen
|
||||
gnupload
|
||||
ioctl
|
||||
@@ -49,12 +57,15 @@ iconv
|
||||
iconv-h
|
||||
listen
|
||||
maintainer-makefile
|
||||
mbiter
|
||||
mbtowc
|
||||
memrchr
|
||||
mkdir
|
||||
mkstemp
|
||||
mkostemp
|
||||
crypto/md5
|
||||
crypto/sha1
|
||||
pipe
|
||||
crypto/sha256
|
||||
quote
|
||||
quotearg
|
||||
recv
|
||||
@@ -66,16 +77,21 @@ sigprocmask
|
||||
sigpipe
|
||||
snprintf
|
||||
socket
|
||||
spawn-pipe
|
||||
stdbool
|
||||
strcasestr
|
||||
strcase
|
||||
strerror_r-posix
|
||||
strptime
|
||||
strtok_r
|
||||
strtoll
|
||||
timegm
|
||||
tmpdir
|
||||
unlocked-io
|
||||
update-copyright
|
||||
vasprintf
|
||||
vsnprintf
|
||||
write
|
||||
xstrndup
|
||||
"
|
||||
|
||||
gnulib_extra_files="
|
||||
@@ -101,4 +117,5 @@ perl 5.5
|
||||
rsync -
|
||||
tar -
|
||||
xz -
|
||||
flex -
|
||||
"
|
||||
|
||||
@@ -100,7 +100,7 @@ EOC
|
||||
EOC
|
||||
}
|
||||
print $fh <<EOC;
|
||||
#else
|
||||
#else
|
||||
"-$name",
|
||||
#endif
|
||||
|
||||
@@ -137,3 +137,4 @@ __DATA__
|
||||
|
||||
#include "wget.h"
|
||||
#include <stdio.h>
|
||||
#include "version.h"
|
||||
|
||||
8
cfg.mk
8
cfg.mk
@@ -4,7 +4,6 @@ local-checks-to-skip = \
|
||||
sc_const_long_option \
|
||||
sc_error_message_uppercase \
|
||||
sc_file_system \
|
||||
sc_makefile_TAB_only_indentation \
|
||||
sc_immutable_NEWS \
|
||||
sc_copyright_check \
|
||||
sc_makefile_path_separator_check \
|
||||
@@ -13,17 +12,18 @@ local-checks-to-skip = \
|
||||
sc_two_space_separator_in_usage \
|
||||
sc_useless_cpp_parens \
|
||||
\
|
||||
sc_space_tab \
|
||||
sc_prohibit_atoi_atof \
|
||||
sc_prohibit_strcmp \
|
||||
sc_makefile_check \
|
||||
sc_cast_of_alloca_return_value \
|
||||
sc_cast_of_x_alloc_return_value \
|
||||
sc_prohibit_S_IS_definition \
|
||||
\
|
||||
sc_program_name \
|
||||
|
||||
sc_makefile_at_at_check \
|
||||
sc_cast_of_argument_to_free \
|
||||
|
||||
#SHELL=bash -x
|
||||
show-vc-list-except:
|
||||
@$(VC_LIST_EXCEPT)
|
||||
|
||||
VC_LIST_ALWAYS_EXCLUDE_REGEX = ^ABOUT-NLS|((msdos|vms)/.*)|ChangeLog-2014-12-10$$
|
||||
|
||||
471
configure.ac
471
configure.ac
@@ -1,6 +1,6 @@
|
||||
dnl Template file for GNU Autoconf
|
||||
dnl Copyright (C) 1995, 1996, 1997, 2001, 2007, 2008, 2009, 2010, 2011
|
||||
dnl Free Software Foundation, Inc.
|
||||
dnl Copyright (C) 1995, 1996, 1997, 2001, 2007, 2008, 2009, 2010, 2011, 2012,
|
||||
dnl 2013, 2014 Free Software Foundation, Inc.
|
||||
|
||||
dnl This program is free software; you can redistribute it and/or modify
|
||||
dnl it under the terms of the GNU General Public License as published by
|
||||
@@ -57,38 +57,108 @@ AC_CANONICAL_HOST
|
||||
AC_DEFINE_UNQUOTED([OS_TYPE], "$host_os",
|
||||
[Define to be the name of the operating system.])
|
||||
|
||||
dnl Non-verbose make
|
||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
||||
|
||||
dnl
|
||||
dnl Process features.
|
||||
dnl Process External Libraries
|
||||
dnl
|
||||
|
||||
AC_ARG_WITH(ssl,
|
||||
[[ --without-ssl disable SSL autodetection
|
||||
--with-ssl={gnutls,openssl} specify the SSL backend. GNU TLS is the default.]])
|
||||
dnl Libpsl: Public Suffix List checking
|
||||
AC_ARG_WITH([libpsl],
|
||||
[AS_HELP_STRING([--without-libpsl], [disable support for libpsl cookie checking.])])
|
||||
|
||||
AC_ARG_WITH(zlib,
|
||||
[[ --without-zlib disable zlib ]])
|
||||
dnl SSL: Configure SSL backend to use
|
||||
AC_ARG_WITH([ssl],
|
||||
[AS_HELP_STRING([--with-ssl={gnutls,openssl}], [specify SSL backend. GNU TLS is the default.])])
|
||||
|
||||
AC_ARG_ENABLE(opie,
|
||||
[ --disable-opie disable support for opie or s/key FTP login],
|
||||
ENABLE_OPIE=$enableval, ENABLE_OPIE=yes)
|
||||
test x"${ENABLE_OPIE}" = xyes && AC_DEFINE([ENABLE_OPIE], 1,
|
||||
[Define if you want the Opie support for FTP compiled in.])
|
||||
dnl Zlib: Configure use of zlib for compression
|
||||
AC_ARG_WITH([zlib],
|
||||
[AS_HELP_STRING([--without-zlib], [disable zlib.])])
|
||||
|
||||
AC_ARG_ENABLE(digest,
|
||||
[ --disable-digest disable support for HTTP digest authorization],
|
||||
ENABLE_DIGEST=$enableval, ENABLE_DIGEST=yes)
|
||||
test x"${ENABLE_DIGEST}" = xyes && AC_DEFINE([ENABLE_DIGEST], 1,
|
||||
[Define if you want the HTTP Digest Authorization compiled in.])
|
||||
dnl Metalink: Configure use of the Metalink library
|
||||
AC_ARG_WITH([metalink],
|
||||
[AS_HELP_STRING([--with-metalink], [enable support for metalinks.])])
|
||||
|
||||
AC_ARG_ENABLE(ntlm,
|
||||
[ --disable-ntlm disable support for NTLM authorization],
|
||||
[ENABLE_NTLM=$enableval], [ENABLE_NTLM=auto])
|
||||
dnl C-Ares: Configure use of the c-ares library for DNS lookup
|
||||
AC_ARG_WITH(cares, AS_HELP_STRING([--with-cares], [enable support for C-Ares DNS lookup.]), with_cares=$withval, with_cares=no)
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
[ --disable-debug disable support for debugging output],
|
||||
ENABLE_DEBUG=$enableval, ENABLE_DEBUG=yes)
|
||||
test x"${ENABLE_DEBUG}" = xyes && AC_DEFINE([ENABLE_DEBUG], 1,
|
||||
[Define if you want the debug output support compiled in.])
|
||||
dnl
|
||||
dnl Process features
|
||||
dnl
|
||||
|
||||
dnl Opie: Support for opie s/key FTP logins
|
||||
AC_ARG_ENABLE([opie],
|
||||
[AS_HELP_STRING([--disable-opie], [disable support for opie or s/key FTP login])],
|
||||
[ENABLE_OPIE=$enableval],
|
||||
[ENABLE_OPIE=yes])
|
||||
|
||||
AS_IF([test "x$ENABLE_OPIE" = xyes],
|
||||
[AC_DEFINE([ENABLE_OPIE], [1], [Define if you want Opie support for FTP compiled in.])],
|
||||
[]
|
||||
)
|
||||
|
||||
|
||||
dnl Digest: Support for HTTP Digest Authentication
|
||||
AC_ARG_ENABLE([digest],
|
||||
[AS_HELP_STRING([--disable-digest], [disable support for HTTP digest authorization])],
|
||||
[ENABLE_DIGEST=$enableval],
|
||||
[ENABLE_DIGEST=yes])
|
||||
|
||||
AS_IF([test "x$ENABLE_DIGEST" = xyes],
|
||||
[AC_DEFINE([ENABLE_DIGEST], [1], [Define if you want the HTTP Digest Authorization compiled in.])],
|
||||
[]
|
||||
)
|
||||
|
||||
|
||||
dnl NTLM: Support for HTTP NTLM Authentication
|
||||
AC_ARG_ENABLE([ntlm],
|
||||
[AS_HELP_STRING([--disable-ntlm], [disable support for NTLM authorization])],
|
||||
[ENABLE_NTLM=$enableval],
|
||||
[ENABLE_NTLM=auto]
|
||||
)
|
||||
|
||||
|
||||
dnl Debug: Support for printing debugging output
|
||||
AC_ARG_ENABLE([debug],
|
||||
[AS_HELP_STRING([--disable-debug], [disable support for debugging output])],
|
||||
[ENABLE_DEBUG=$enableval],
|
||||
[ENABLE_DEBUG=yes])
|
||||
|
||||
AS_IF([test "x$ENABLE_DEBUG" = xyes],
|
||||
[AC_DEFINE([ENABLE_DEBUG], [1], [Define if you want the debug output support compiled in.])],
|
||||
[]
|
||||
)
|
||||
|
||||
dnl Valgrind-tests: Should test suite be run under valgrind?
|
||||
AC_ARG_ENABLE(valgrind-tests,
|
||||
[AS_HELP_STRING([--enable-valgrind-tests], [enable using Valgrind for tests])],
|
||||
[ENABLE_VALGRIND=$enableval],
|
||||
[ENABLE_VALGRIND=no])
|
||||
|
||||
AS_IF([test "x$ENABLE_VALGRIND" != xno], [
|
||||
AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
|
||||
AS_IF([test "x$HAVE_VALGRIND" = xyes], [
|
||||
VALGRIND_TESTS="1"
|
||||
AC_SUBST(VALGRIND_TESTS)
|
||||
VALGRIND_INFO="Test suite will be run under Valgrind"
|
||||
], [
|
||||
VALGRIND_INFO="Valgrind not found"
|
||||
])
|
||||
], [
|
||||
VALGRIND_INFO="Valgrind testing not enabled"
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(assert,
|
||||
[AS_HELP_STRING([--enable-assert], [enable assertions in code base])],
|
||||
[ENABLE_ASSERTION=$enableval],
|
||||
[ENABLE_ASSERTION=no]
|
||||
)
|
||||
|
||||
AS_IF([test "x$ENABLE_ASSERTION" != xyes], [
|
||||
CFLAGS="-DNDEBUG $CFLAGS"
|
||||
],
|
||||
[])
|
||||
|
||||
dnl
|
||||
dnl Find the compiler
|
||||
@@ -104,11 +174,17 @@ AC_AIX
|
||||
|
||||
gl_EARLY
|
||||
|
||||
dnl
|
||||
dnl Find python3
|
||||
dnl
|
||||
AM_PATH_PYTHON([3.0],,[:])
|
||||
AM_CONDITIONAL([HAVE_PYTHON3], [test "$PYTHON" != :])
|
||||
|
||||
dnl
|
||||
dnl Gettext
|
||||
dnl
|
||||
AM_GNU_GETTEXT([external],[need-ngettext])
|
||||
AM_GNU_GETTEXT_VERSION([0.17])
|
||||
AM_GNU_GETTEXT_VERSION([0.18.1])
|
||||
|
||||
AC_PROG_RANLIB
|
||||
|
||||
@@ -121,9 +197,11 @@ dnl if compiler is gcc, then
|
||||
dnl use -O2 and some warning flags
|
||||
dnl else
|
||||
dnl use os-specific flags or -O
|
||||
dnl
|
||||
dnl For these tests, the system considers clang to be gcc
|
||||
if test -n "$auto_cflags"; then
|
||||
if test -n "$GCC"; then
|
||||
CFLAGS="$CFLAGS -O2 -Wall"
|
||||
CFLAGS="$CFLAGS -O2 -Wall -Wextra"
|
||||
else
|
||||
case "$host_os" in
|
||||
*hpux*) CFLAGS="$CFLAGS +O3" ;;
|
||||
@@ -142,8 +220,7 @@ AC_C_VOLATILE
|
||||
|
||||
dnl Check for basic headers, even though we expect them to exist and
|
||||
dnl #include them unconditionally in the code. Their detection is
|
||||
dnl still needed because test programs used by Autoconf macros check
|
||||
dnl for STDC_HEADERS, HAVE_SYS_TYPES_H, etc. before using them.
|
||||
dnl still needed because test programs used by Autoconf macros check.
|
||||
dnl Without the checks they will fail to be included in test programs,
|
||||
dnl which will subsequently fail.
|
||||
AC_HEADER_STDC
|
||||
@@ -184,9 +261,7 @@ AC_CHECK_TYPES([uint32_t, uintptr_t, intptr_t, int64_t])
|
||||
AC_CHECK_TYPES(sig_atomic_t, [], [], [
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
#include <signal.h>
|
||||
])
|
||||
|
||||
@@ -198,9 +273,9 @@ dnl Checks for library functions.
|
||||
dnl
|
||||
AC_FUNC_MMAP
|
||||
AC_FUNC_FSEEKO
|
||||
AC_CHECK_FUNCS(strptime timegm vsnprintf vasprintf drand48)
|
||||
AC_CHECK_FUNCS(strptime timegm vsnprintf vasprintf drand48 pathconf)
|
||||
AC_CHECK_FUNCS(strtoll usleep ftello sigblock sigsetjmp memrchr wcwidth mbtowc)
|
||||
AC_CHECK_FUNCS(sleep symlink utime)
|
||||
AC_CHECK_FUNCS(sleep symlink utime strlcpy random)
|
||||
|
||||
if test x"$ENABLE_OPIE" = xyes; then
|
||||
AC_LIBOBJ([ftp-opie])
|
||||
@@ -237,14 +312,48 @@ dnl
|
||||
dnl Checks for libraries.
|
||||
dnl
|
||||
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
AS_IF([test "x$with_libpsl" != xno], [
|
||||
PKG_CHECK_MODULES([LIBPSL], libpsl, [
|
||||
with_libpsl=yes
|
||||
# correct $LIBPSL_LIBS (in libpsl <= 0.6.0)
|
||||
AS_IF([test "x$LIBPSL_LIBS" = "x-llibpsl "], [LIBPSL_LIBS="-lpsl"])
|
||||
LIBS="$LIBPSL_LIBS $LIBS"
|
||||
CFLAGS="$LIBPSL_CFLAGS $CFLAGS"
|
||||
AC_DEFINE([HAVE_LIBPSL], [1], [PSL support enabled])
|
||||
], [
|
||||
AC_SEARCH_LIBS(psl_builtin, psl,
|
||||
[with_libpsl=yes; AC_DEFINE([HAVE_LIBPSL], [1], [PSL support enabled])],
|
||||
[with_libpsl=no; AC_MSG_WARN(*** libpsl was not found. Fallback to builtin cookie checking.)])
|
||||
])
|
||||
])
|
||||
|
||||
AS_IF([test x"$with_zlib" != xno], [
|
||||
AC_CHECK_LIB(z, compress)
|
||||
with_zlib=yes
|
||||
PKG_CHECK_MODULES([ZLIB], zlib, [
|
||||
LIBS="$ZLIB_LIBS $LIBS"
|
||||
CFLAGS="$ZLIB_CFLAGS $CFLAGS"
|
||||
AC_DEFINE([HAVE_LIBZ], [1], [Define if using zlib.])
|
||||
], [
|
||||
AC_CHECK_LIB(z, compress)
|
||||
])
|
||||
])
|
||||
|
||||
AS_IF([test x"$with_ssl" = xopenssl], [
|
||||
dnl some versions of openssl use zlib compression
|
||||
AC_CHECK_LIB(z, compress)
|
||||
|
||||
if [test x"$with_libssl_prefix" = x]; then
|
||||
PKG_CHECK_MODULES([OPENSSL], [openssl], [
|
||||
AC_MSG_NOTICE([compiling in support for SSL via OpenSSL])
|
||||
AC_LIBOBJ([openssl])
|
||||
LIBS="$OPENSSL_LIBS $LIBS"
|
||||
CFLAGS="$OPENSSL_CFLAGS -DHAVE_LIBSSL $CFLAGS"
|
||||
LIBSSL=" " # ntlm check below wants this
|
||||
AC_CHECK_FUNCS([RAND_egd])
|
||||
AC_DEFINE([HAVE_LIBSSL], [1], [Define if using openssl.])
|
||||
ssl_found=yes
|
||||
])
|
||||
fi
|
||||
if [test x"$ssl_found" != xyes]; then
|
||||
dnl As of this writing (OpenSSL 0.9.6), the libcrypto shared library
|
||||
dnl doesn't record its dependency on libdl, so we need to make sure
|
||||
dnl -ldl ends up in LIBS on systems that have it. Most OSes use
|
||||
@@ -257,7 +366,7 @@ AS_IF([test x"$with_ssl" = xopenssl], [
|
||||
case $host_os in
|
||||
*mingw32* )
|
||||
dnl prefer link to openssl dlls if possible. if not then fallback on static libs. if not then error
|
||||
|
||||
|
||||
AC_CHECK_LIB(eay32, EVP_MD_CTX_init)
|
||||
if test x"$ac_cv_lib_eay32_EVP_MD_CTX_init" != xno
|
||||
then
|
||||
@@ -269,7 +378,7 @@ AS_IF([test x"$with_ssl" = xopenssl], [
|
||||
AC_DEFINE([HAVE_LIBSSL32], [1], [Define to 1 if you have the `ssl32' library (-lssl32).])
|
||||
],
|
||||
AC_MSG_ERROR([openssl not found: shared lib eay32 found but ssl32 not found]))
|
||||
|
||||
|
||||
else
|
||||
LIBS+=' -lgdi32'
|
||||
dnl fallback and test static libs
|
||||
@@ -278,55 +387,64 @@ AS_IF([test x"$with_ssl" = xopenssl], [
|
||||
;;
|
||||
esac
|
||||
|
||||
AS_IF([test x$ssl_found != xyes],
|
||||
[
|
||||
dnl Now actually check for -lssl if it wasn't already found
|
||||
AC_LIB_HAVE_LINKFLAGS([ssl], [crypto z], [
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/des.h>
|
||||
#include <openssl/md4.h>
|
||||
#include <openssl/md5.h>
|
||||
], [SSL_library_init ()])
|
||||
if test x"$LIBSSL" != x
|
||||
then
|
||||
ssl_found=yes
|
||||
AC_MSG_NOTICE([compiling in support for SSL via OpenSSL])
|
||||
AC_LIBOBJ([openssl])
|
||||
LIBS="$LIBSSL $LIBS"
|
||||
elif test x"$with_ssl" != x
|
||||
then
|
||||
AC_MSG_ERROR([--with-ssl=openssl was given, but SSL is not available.])
|
||||
fi
|
||||
])
|
||||
|
||||
], [
|
||||
# --with-ssl is not gnutls: check if it's no
|
||||
AS_IF([test x"$with_ssl" != xno], [
|
||||
dnl Now actually check for -lssl
|
||||
|
||||
AC_CHECK_LIB(z, compress)
|
||||
AC_CHECK_LIB(gpg-error, gpg_err_init)
|
||||
AC_CHECK_LIB(gcrypt, gcry_control)
|
||||
|
||||
dnl Now actually check for -lssl
|
||||
AC_LIB_HAVE_LINKFLAGS([gnutls], [], [
|
||||
#include <gnutls/gnutls.h>
|
||||
], [gnutls_global_init()])
|
||||
if test x"$LIBGNUTLS" != x
|
||||
then
|
||||
ssl_found=yes
|
||||
AC_MSG_NOTICE([compiling in support for SSL via GnuTLS])
|
||||
AC_LIBOBJ([gnutls])
|
||||
LIBS="$LIBGNUTLS $LIBS"
|
||||
else
|
||||
AC_MSG_ERROR([--with-ssl was given, but GNUTLS is not available.])
|
||||
AS_IF([test x$ssl_found != xyes], [
|
||||
dnl Now actually check for -lssl if it wasn't already found
|
||||
AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/des.h>
|
||||
#include <openssl/md4.h>
|
||||
#include <openssl/md5.h>
|
||||
], [SSL_library_init ()])
|
||||
if test x"$LIBSSL" != x
|
||||
then
|
||||
ssl_found=yes
|
||||
AC_MSG_NOTICE([compiling in support for SSL via OpenSSL])
|
||||
AC_LIBOBJ([openssl])
|
||||
LIBS="$LIBSSL $LIBS"
|
||||
AC_CHECK_FUNCS([RAND_egd])
|
||||
elif test x"$with_ssl" != x
|
||||
then
|
||||
AC_MSG_ERROR([--with-ssl=openssl was given, but SSL is not available.])
|
||||
fi
|
||||
])
|
||||
fi
|
||||
], [
|
||||
# --with-ssl is not openssl: check if it's no
|
||||
AS_IF([test x"$with_ssl" != xno], [
|
||||
dnl default is -lgnutls
|
||||
with_ssl=gnutls
|
||||
|
||||
AC_CHECK_FUNCS(gnutls_priority_set_direct)
|
||||
]) # endif: --with-ssl == no?
|
||||
dnl Now actually check for -lgnutls
|
||||
if [test x"$with_libgnutls_prefix" = x]; then
|
||||
PKG_CHECK_MODULES([GNUTLS], [gnutls], [
|
||||
AC_MSG_NOTICE([compiling in support for SSL via GnuTLS])
|
||||
AC_LIBOBJ([gnutls])
|
||||
LIBS="$GNUTLS_LIBS $LIBS"
|
||||
CFLAGS="$GNUTLS_CFLAGS -DHAVE_LIBGNUTLS $CFLAGS"
|
||||
AC_DEFINE([HAVE_LIBGNUTLS], [1], [Define if using gnutls.])
|
||||
ssl_found=yes
|
||||
])
|
||||
fi
|
||||
if [test x"$ssl_found" != xyes]; then
|
||||
AC_LIB_HAVE_LINKFLAGS([gnutls], [], [
|
||||
#include <gnutls/gnutls.h>
|
||||
], [gnutls_global_init()])
|
||||
if test x"$LIBGNUTLS" != x
|
||||
then
|
||||
ssl_found=yes
|
||||
AC_MSG_NOTICE([compiling in support for SSL via GnuTLS])
|
||||
AC_LIBOBJ([gnutls])
|
||||
LIBS="$LIBGNUTLS $LIBS"
|
||||
else
|
||||
AC_MSG_ERROR([GnuTLS has not been found. Use --with-ssl=openssl if you explicitly want OpenSSL.])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CHECK_FUNCS(gnutls_priority_set_direct)
|
||||
]) # endif: --with-ssl != no?
|
||||
]) # endif: --with-ssl == openssl?
|
||||
|
||||
dnl Enable NTLM if requested and if SSL is available.
|
||||
@@ -334,19 +452,65 @@ if test x"$LIBSSL" != x || test "$ac_cv_lib_ssl32_SSL_connect" = yes
|
||||
then
|
||||
if test x"$ENABLE_NTLM" != xno
|
||||
then
|
||||
ENABLE_NTLM=yes
|
||||
AC_DEFINE([ENABLE_NTLM], 1,
|
||||
[Define if you want the NTLM authorization support compiled in.])
|
||||
AC_LIBOBJ([http-ntlm])
|
||||
fi
|
||||
else
|
||||
dnl If SSL is unavailable and the user explicitly requested NTLM,
|
||||
dnl abort.
|
||||
if test x"$ENABLE_NTLM" = xyes
|
||||
AC_CHECK_LIB(nettle, nettle_md4_init, [HAVE_NETTLE=yes], [HAVE_NETTLE=no; AC_MSG_WARN(*** libnettle was not found. You will not be able to use NTLM)])
|
||||
|
||||
if test x"$HAVE_NETTLE" = xyes
|
||||
then
|
||||
AC_MSG_ERROR([NTLM authorization requested and OpenSSL not found; aborting])
|
||||
AC_SUBST(NETTLE_LIBS, "-lnettle")
|
||||
AC_DEFINE([HAVE_NETTLE], [1], [Use libnettle])
|
||||
if test x"$ENABLE_NTLM" != xno
|
||||
then
|
||||
ENABLE_NTLM=yes
|
||||
AC_DEFINE([ENABLE_NTLM], 1,
|
||||
[Define if you want the NTLM authorization support compiled in.])
|
||||
AC_LIBOBJ([http-ntlm])
|
||||
LIBS="$NETTLE_LIBS $LIBS"
|
||||
fi
|
||||
else
|
||||
dnl If SSL is unavailable and the user explicitly requested NTLM,
|
||||
dnl abort.
|
||||
if test x"$ENABLE_NTLM" = xyes
|
||||
then
|
||||
AC_MSG_ERROR([NTLM authorization requested and SSL not enabled; aborting])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl
|
||||
dnl Check for libmetalink
|
||||
dnl
|
||||
AS_IF([test x"$with_metalink" != xno], [
|
||||
PKG_CHECK_MODULES([METALINK], libmetalink, [
|
||||
LIBS="$METALINK_LIBS $LIBS"
|
||||
CFLAGS="$METALINK_CFLAGS $CFLAGS"
|
||||
AC_DEFINE([HAVE_METALINK], [1], [Define if using metalink.])
|
||||
with_metalink=yes
|
||||
], [
|
||||
with_metalink=no
|
||||
])
|
||||
|
||||
have_gpg=no
|
||||
AS_IF([test x"$with_metalink" = xyes], [
|
||||
dnl
|
||||
dnl Check for GPGME
|
||||
dnl
|
||||
m4_ifdef([AM_PATH_GPGME], [
|
||||
AM_PATH_GPGME([], [
|
||||
LIBS="$GPGME_LIBS $LIBS"
|
||||
CFLAGS="$GPGME_CFLAGS $CFLAGS"
|
||||
AC_DEFINE([HAVE_GPGME], [1], [Define if GPGME is available.])
|
||||
have_gpg=yes
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
|
||||
dnl **********************************************************************
|
||||
dnl Checks for IPv6
|
||||
dnl **********************************************************************
|
||||
@@ -524,36 +688,123 @@ dnl
|
||||
dnl Check for UUID
|
||||
dnl
|
||||
|
||||
AC_CHECK_HEADER(uuid/uuid.h,
|
||||
AC_CHECK_LIB(uuid, uuid_generate,
|
||||
[LIBS="${LIBS} -luuid"
|
||||
AC_DEFINE([HAVE_LIBUUID], 1,
|
||||
[Define if libuuid is available.])
|
||||
])
|
||||
)
|
||||
AC_ARG_WITH(libuuid, AC_HELP_STRING([--without-libuuid],
|
||||
[Generate UUIDs for WARC files via libuuid]))
|
||||
|
||||
AS_IF([test "x$with_libuuid" = xyes], [
|
||||
# libuuid was explicitly requested
|
||||
PKG_CHECK_MODULES([UUID], uuid, [
|
||||
LIBS="$UUID_LIBS $LIBS"
|
||||
CFLAGS="$UUID_CFLAGS $CFLAGS"
|
||||
uuid_mode=1
|
||||
], [
|
||||
AC_SEARCH_LIBS(uuid_generate, uuid,
|
||||
[uuid_mode=1],
|
||||
[AC_MSG_ERROR(*** libuuid was explicitly requested but wasn't found.)])
|
||||
])
|
||||
], [test "x$with_libuuid" = xno], [
|
||||
# libuuid was explicitly *not* requested
|
||||
AC_CHECK_HEADER(uuid.h,
|
||||
AC_CHECK_FUNC(uuid_create, [uuid_mode=2]))
|
||||
], [
|
||||
# default:
|
||||
AC_CHECK_HEADER(uuid.h, [
|
||||
AC_CHECK_FUNC(uuid_create, [uuid_mode=2])
|
||||
], [
|
||||
AC_CHECK_HEADER(uuid/uuid.h,
|
||||
AC_SEARCH_LIBS(uuid_generate, uuid, [uuid_mode=1]))
|
||||
])
|
||||
])
|
||||
|
||||
AS_IF([test "x$uuid_mode" = x1], [
|
||||
AC_DEFINE([HAVE_LIBUUID], [1], [Define if using libuuid.])
|
||||
], [test "x$uuid_mode" = x2], [
|
||||
AC_DEFINE([HAVE_UUID_CREATE], 1, [Define if uuid_create is available.])
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl Check for PCRE
|
||||
dnl
|
||||
|
||||
AC_CHECK_HEADER(pcre.h,
|
||||
AC_CHECK_LIB(pcre, pcre_compile,
|
||||
[LIBS="${LIBS} -lpcre"
|
||||
AC_DEFINE([HAVE_LIBPCRE], 1,
|
||||
[Define if libpcre is available.])
|
||||
])
|
||||
)
|
||||
AC_ARG_ENABLE(pcre, AC_HELP_STRING([--disable-pcre],
|
||||
[Disable PCRE style regular expressions]))
|
||||
|
||||
AS_IF([test "X$enable_pcre" != "Xno"],[
|
||||
PKG_CHECK_MODULES([PCRE], libpcre, [
|
||||
CFLAGS="$PCRE_CFLAGS $CFLAGS"
|
||||
AC_CHECK_HEADER(pcre.h, [
|
||||
LIBS="$PCRE_LIBS $LIBS"
|
||||
AC_DEFINE([HAVE_LIBPCRE], [1], [Define if libpcre is available.])
|
||||
])
|
||||
], [
|
||||
AC_CHECK_HEADER(pcre.h, [
|
||||
AC_CHECK_LIB(pcre, pcre_compile, [
|
||||
LIBS="${LIBS} -lpcre"
|
||||
AC_DEFINE([HAVE_LIBPCRE], 1, [Define if libpcre is available.])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl Check for libcares (resolver library)
|
||||
dnl
|
||||
|
||||
AS_IF([test "X$with_cares" == "Xyes"],[
|
||||
PKG_CHECK_MODULES([CARES], libcares, [
|
||||
CFLAGS="$CARES_CFLAGS $CFLAGS"
|
||||
AC_CHECK_HEADER(ares.h, [
|
||||
LIBS="$CARES_LIBS $LIBS"
|
||||
AC_DEFINE([HAVE_LIBCARES], [1], [Define if libcares is available.])
|
||||
RESOLVER_INFO="libcares, --bind-dns-address and --dns-servers available"
|
||||
])
|
||||
], [
|
||||
AC_CHECK_HEADER(ares.h, [
|
||||
AC_CHECK_LIB(cares, ares_set_local_ip4, [
|
||||
LIBS="-lcares ${LIBS}"
|
||||
AC_DEFINE([HAVE_LIBCARES], 1, [Define if libcares is available.])
|
||||
RESOLVER_INFO="libcares, --bind-dns-address and --dns-servers available"
|
||||
])
|
||||
])
|
||||
])
|
||||
], [
|
||||
RESOLVER_INFO="libc, --bind-dns-address and --dns-servers not available"
|
||||
])
|
||||
|
||||
|
||||
|
||||
dnl Needed by src/Makefile.am
|
||||
AM_CONDITIONAL([IRI_IS_ENABLED], [test "X$iri" != "Xno"])
|
||||
|
||||
AM_CONDITIONAL([WITH_SSL], [test "X$with_ssl" != "Xno"])
|
||||
AM_CONDITIONAL([METALINK_IS_ENABLED], [test "X$with_metalink" != "Xno"])
|
||||
|
||||
dnl
|
||||
dnl Create output
|
||||
dnl
|
||||
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile util/Makefile
|
||||
po/Makefile.in tests/Makefile tests/WgetTest.pm
|
||||
lib/Makefile])
|
||||
po/Makefile.in tests/Makefile
|
||||
lib/Makefile testenv/Makefile])
|
||||
AC_CONFIG_HEADERS([src/config.h])
|
||||
AC_OUTPUT
|
||||
|
||||
AC_MSG_NOTICE([Summary of build options:
|
||||
|
||||
Version: $PACKAGE_VERSION
|
||||
Host OS: $host_os
|
||||
Install prefix: $prefix
|
||||
Compiler: $CC
|
||||
CFlags: $CFLAGS $CPPFLAGS
|
||||
LDFlags: $LDFLAGS
|
||||
Libs: $LIBS
|
||||
SSL: $with_ssl
|
||||
Zlib: $with_zlib
|
||||
PSL: $with_libpsl
|
||||
Digest: $ENABLE_DIGEST
|
||||
NTLM: $ENABLE_NTLM
|
||||
OPIE: $ENABLE_OPIE
|
||||
Debugging: $ENABLE_DEBUG
|
||||
Assertions: $ENABLE_ASSERTION
|
||||
Valgrind: $VALGRIND_INFO
|
||||
Metalink: $with_metalink
|
||||
Resolver: $RESOLVER_INFO
|
||||
GPGME: $have_gpg
|
||||
])
|
||||
|
||||
54
contrib/check-hard
Executable file
54
contrib/check-hard
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Do some checking before 'git push'.
|
||||
|
||||
# Set a stricter bash mode
|
||||
set -e
|
||||
set -u
|
||||
|
||||
CORES=$(grep -c ^processor /proc/cpuinfo 2> /dev/null || echo 0)
|
||||
if [ $CORES -lt 1 ]; then CORES=1; fi
|
||||
|
||||
echo "Running: make distclean"
|
||||
make distclean > /dev/null || true
|
||||
|
||||
CFLAGS="-std=c89 -pedantic -O2 -g -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wwrite-strings -Wshadow -Wformat -Wformat-security -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition"
|
||||
|
||||
CACHEFILE=$PWD/config_check.cache
|
||||
|
||||
# measure time consumed and print it at the end of the script
|
||||
START=$(date +%s.%N)
|
||||
|
||||
echo "Running: ./bootstrap"
|
||||
./bootstrap > /dev/null
|
||||
echo
|
||||
|
||||
for CC in gcc clang; do
|
||||
export CC
|
||||
echo "*** Testing with CC=$CC"
|
||||
|
||||
# the compiler changed, so we have to remove the cache file here
|
||||
rm -f $CACHEFILE
|
||||
|
||||
for options in "" "--with-ssl=openssl"; do
|
||||
export DISTCHECK_CONFIGURE_FLAGS="-C --cache-file=$CACHEFILE $options"
|
||||
echo " ./configure $DISTCHECK_CONFIGURE_FLAGS"
|
||||
./configure $DISTCHECK_CONFIGURE_FLAGS CFLAGS="$CFLAGS" > /dev/null
|
||||
|
||||
for xVALGRIND in 0 1; do
|
||||
for xLCALL in C tr_TR.utf8; do
|
||||
export TESTS_ENVIRONMENT="LC_ALL=$xLCALL VALGRIND_TESTS=$xVALGRIND"
|
||||
echo " TESTS_ENVIRONMENT=\"$TESTS_ENVIRONMENT\"" make check -j$CORES
|
||||
make check -j$CORES > /dev/null
|
||||
done
|
||||
done
|
||||
|
||||
unset TESTS_ENVIRONMENT
|
||||
export TESTS_ENVIRONMENT
|
||||
echo " make distcheck CFLAGS=$CFLAGS -j$CORES"
|
||||
make distcheck CFLAGS="$CFLAGS" -j$CORES > /dev/null
|
||||
done
|
||||
done
|
||||
|
||||
END=$(date +%s.%N)
|
||||
echo "Duration: "$(echo "$END - $START" | bc)
|
||||
60
contrib/travis-ci
Executable file
60
contrib/travis-ci
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set a stricter bash mode
|
||||
set -e
|
||||
set -u
|
||||
|
||||
# Set up the subset of tests this Matrix instance will run.
|
||||
|
||||
# One instance is forked for each of the SSL library possibilities
|
||||
SSL=${1:-""}
|
||||
case $SSL in
|
||||
"") SSL_LIB="--without-ssl";;
|
||||
"openssl") SSL_LIB="--with-ssl=openssl";;
|
||||
"gnutls") SSL_LIB="--with-ssl=gnutls";;
|
||||
esac
|
||||
|
||||
# For some reason. /proc/cpuinfo reports 16 cores on Travis, while the docs
|
||||
# claim that each instance has only 2 cores. We believe the docs and force a
|
||||
# value of n+1 here.
|
||||
CORES=3
|
||||
|
||||
# Define a large number of Warning flags for the compiler. Hopefully, someone
|
||||
# will sit and analyze the output to clean the warnings from the codebase.
|
||||
CFLAGS="-std=c89 -pedantic -O2 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wwrite-strings -Wshadow -Wformat -Wformat-security -Wunreachable-code -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition"
|
||||
|
||||
# A cachefile for ./configure. Saves significant time when reconfiguring
|
||||
CACHEFILE=$PWD/config_check.cache
|
||||
|
||||
# measure time consumed and print it at the end of the script
|
||||
START=$(date +%s)
|
||||
|
||||
# Test different Permutations of Wget. Always under Valgrind
|
||||
#
|
||||
# Options:
|
||||
# - All Features Enabled
|
||||
# - C [Default Locale]
|
||||
# - Russian [Multibyte / Multicolumn Locale]
|
||||
# - Turkish [Special Test due to issues with language]
|
||||
# - IPv6 Disabled
|
||||
# - C
|
||||
for options in "" "--disable-ipv6"; do
|
||||
export DISTCHECK_CONFIGURE_FLAGS="-C --cache-file=$CACHEFILE --enable-assert --enable-valgrind-tests $SSL_LIB $options"
|
||||
echo " ./configure $DISTCHECK_CONFIGURE_FLAGS CFLAGS=\"$CFLAGS\""
|
||||
./configure $DISTCHECK_CONFIGURE_FLAGS CFLAGS="$CFLAGS"
|
||||
|
||||
if [[ -z $options ]]; then
|
||||
LANG_ARR=("ru_RU.UTF-8" "tr_TR.UTF-8" "C")
|
||||
else
|
||||
LANG_ARR=("C")
|
||||
fi
|
||||
|
||||
for xLCALL in "${LANG_ARR[@]}"; do
|
||||
export TESTS_ENVIRONMENT="LC_ALL=$xLCALL VALGRIND_TESTS=1"
|
||||
echo " TESTS_ENVIRONMENT=\"$TESTS_ENVIRONMENT\" make distcheck CFLAGS=$CFLAGS -j$CORES"
|
||||
make distcheck CFLAGS="$CFLAGS" -j$CORES
|
||||
done
|
||||
done
|
||||
|
||||
END=$(date +%s)
|
||||
echo "Duration: $((END-START))"
|
||||
90
contrib/tsocked-wget
Executable file
90
contrib/tsocked-wget
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script that executes wget using a socks proxy if the environment variable
|
||||
# socks_proxy is set.
|
||||
#
|
||||
# The socks_proxy variable shall have one of the forms:
|
||||
# socks://username:password@host:port
|
||||
# socks4://username:password@host:port
|
||||
# socks5://username:password@host:port
|
||||
# with username, password and port fields being optional
|
||||
#
|
||||
# As socksification applies to the whole process, domains defined in the
|
||||
# no_proxy setting are *not* excluded.
|
||||
#
|
||||
|
||||
# Requisites: bash (version 3.2.3 or later), tsocks and wget
|
||||
|
||||
####################################
|
||||
# Copyright (C) 2014 Ángel González
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
set -eu
|
||||
|
||||
# Binary to be executed. Use an absolute path if installing this script as 'wget'
|
||||
WGET=wget
|
||||
|
||||
if [ -z "${socks_proxy:-}" ]; then
|
||||
exec "$WGET" "$@"
|
||||
fi
|
||||
|
||||
CONFIG=""
|
||||
|
||||
if [[ "${socks_proxy}" =~ ^socks[45]?:// ]]; then
|
||||
if [[ "${socks_proxy:5:1}" != ":" ]]; then
|
||||
CONFIG+="server_type = ${socks_proxy:5:1}"
|
||||
socks_proxy="${socks_proxy:9}"
|
||||
else
|
||||
socks_proxy="${socks_proxy:8}"
|
||||
fi
|
||||
elif [[ "${socks_proxy}" =~ ^[[:alnum:]]*:// ]]; then
|
||||
echo "Bad value specified for socks_proxy: $socks_proxy" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ "${socks_proxy}" =~ ^([^@:]*)(:([^@]*))?@ ]]; then
|
||||
unset TSOCKS_USERNAME
|
||||
CONFIG+="
|
||||
default_user = ${BASH_REMATCH[1]}"
|
||||
|
||||
if [ ! -z "${BASH_REMATCH[3]}" ]; then
|
||||
unset TSOCKS_PASSWORD
|
||||
CONFIG+="
|
||||
default_pass = ${BASH_REMATCH[3]}"
|
||||
fi
|
||||
socks_proxy="${socks_proxy:${#BASH_REMATCH[0]}}"
|
||||
fi
|
||||
|
||||
|
||||
# Get rid of trailing slashes
|
||||
if [[ "${socks_proxy}" =~ ^([^/]*)/ ]]; then
|
||||
socks_proxy="${socks_proxy:0:${#BASH_REMATCH[1]}}"
|
||||
fi
|
||||
|
||||
if [[ "${socks_proxy}" =~ :([0-9]+)$ ]]; then
|
||||
CONFIG+="
|
||||
server_port = ${BASH_REMATCH[1]}"
|
||||
socks_proxy=${socks_proxy:0:${#socks_proxy} - ${#BASH_REMATCH[0]}}
|
||||
fi
|
||||
|
||||
CONFIG+="
|
||||
server = ${socks_proxy}"
|
||||
|
||||
TSOCKS_CONF_FILE=<(echo "$CONFIG") exec tsocks "$WGET" --no-proxy "$@"
|
||||
1498
doc/ChangeLog
1498
doc/ChangeLog
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
# Makefile for `wget' utility
|
||||
# Copyright (C) 1995, 1996, 1997, 2007, 2008, 2009, 2010, 2011 Free
|
||||
# Software Foundation, Inc.
|
||||
# Copyright (C) 1995, 1996, 1997, 2007, 2008, 2009, 2010, 2011, 2015
|
||||
# Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -57,7 +57,10 @@ wget.pod: $(srcdir)/wget.texi version.texi
|
||||
$(TEXI2POD) -D VERSION="$(VERSION)" $(srcdir)/wget.texi $@
|
||||
|
||||
$(MAN): wget.pod
|
||||
$(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" $? > $@
|
||||
$(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" --utf8 $? > $@; \
|
||||
if [ $? != 0 ]; then \
|
||||
$(POD2MAN) --center="GNU Wget" --release="GNU Wget @VERSION@" $? > $@; \
|
||||
fi
|
||||
|
||||
#wget.cat: $(MAN)
|
||||
# nroff -man $? > $@
|
||||
|
||||
27
doc/fdl.texi
27
doc/fdl.texi
@@ -5,8 +5,8 @@
|
||||
@c hence no sectioning command or @node.
|
||||
|
||||
@display
|
||||
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008, 2009, 2010, 2011
|
||||
Free Software Foundation, Inc.
|
||||
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
@uref{http://fsf.org/}
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
@@ -93,16 +93,16 @@ An image format is not Transparent if used for any substantial amount
|
||||
of text. A copy that is not ``Transparent'' is called ``Opaque''.
|
||||
|
||||
Examples of suitable formats for Transparent copies include plain
|
||||
@sc{ascii} without markup, Texinfo input format, La@TeX{} input
|
||||
format, @acronym{SGML} or @acronym{XML} using a publicly available
|
||||
@acronym{DTD}, and standard-conforming simple @acronym{HTML},
|
||||
PostScript or @acronym{PDF} designed for human modification. Examples
|
||||
of transparent image formats include @acronym{PNG}, @acronym{XCF} and
|
||||
@acronym{JPG}. Opaque formats include proprietary formats that can be
|
||||
read and edited only by proprietary word processors, @acronym{SGML} or
|
||||
@acronym{XML} for which the @acronym{DTD} and/or processing tools are
|
||||
not generally available, and the machine-generated @acronym{HTML},
|
||||
PostScript or @acronym{PDF} produced by some word processors for
|
||||
ASCII without markup, Texinfo input format, La@TeX{} input
|
||||
format, SGML or XML using a publicly available
|
||||
DTD, and standard-conforming simple HTML,
|
||||
PostScript or PDF designed for human modification. Examples
|
||||
of transparent image formats include PNG, XCF and
|
||||
JPG@. Opaque formats include proprietary formats that can be
|
||||
read and edited only by proprietary word processors, SGML or
|
||||
XML for which the DTD and/or processing tools are
|
||||
not generally available, and the machine-generated HTML,
|
||||
PostScript or PDF produced by some word processors for
|
||||
output purposes only.
|
||||
|
||||
The ``Title Page'' means, for a printed book, the title page itself,
|
||||
@@ -482,7 +482,7 @@ license notices just after the title page:
|
||||
@end smallexample
|
||||
|
||||
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
|
||||
replace the ``with@dots{}Texts.'' line with this:
|
||||
replace the ``with@dots{}Texts.''@: line with this:
|
||||
|
||||
@smallexample
|
||||
@group
|
||||
@@ -504,4 +504,3 @@ to permit their use in free software.
|
||||
@c Local Variables:
|
||||
@c ispell-local-pdict: "ispell-dict"
|
||||
@c End:
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
## You can use this file to change the default behaviour of wget or to
|
||||
## avoid having to type many many command-line options. This file does
|
||||
## not contain a comprehensive list of commands -- look at the manual
|
||||
## to find out what you can put into this file.
|
||||
## to find out what you can put into this file. You can find this here:
|
||||
## $ info wget.info 'Startup File'
|
||||
## Or online here:
|
||||
## https://www.gnu.org/software/wget/manual/wget.html#Startup-File
|
||||
##
|
||||
## Wget initialization file can reside in /usr/local/etc/wgetrc
|
||||
## (global, for all users) or $HOME/.wgetrc (for a single user).
|
||||
@@ -13,6 +16,9 @@
|
||||
## To use the settings in this file, you will have to uncomment them,
|
||||
## as well as change them, in most cases, as the values on the
|
||||
## commented-out lines are the default values (e.g. "off").
|
||||
##
|
||||
## Command are case-, underscore- and minus-insensitive.
|
||||
## For example ftp_proxy, ftp-proxy and ftpproxy are the same.
|
||||
|
||||
|
||||
##
|
||||
@@ -119,7 +125,13 @@
|
||||
#iri = off
|
||||
|
||||
# Force the default system encoding
|
||||
#locale = UTF-8
|
||||
#localencoding = UTF-8
|
||||
|
||||
# Force the default remote server encoding
|
||||
#remoteencoding = UTF-8
|
||||
|
||||
# Turn on to prevent following non-HTTPS links when in recursive mode
|
||||
#httpsonly = off
|
||||
|
||||
# Tune HTTPS security (auto, SSLv2, SSLv3, TLSv1, PFS)
|
||||
#secureprotocol = auto
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#! /usr/bin/env perl
|
||||
|
||||
# Copyright (C) 1999, 2000, 2001, 2003, 2007, 2009, 2010, 2011 Free
|
||||
# Software Foundation, Inc.
|
||||
# Copyright (C) 1999, 2000, 2001, 2003, 2007, 2009, 2010, 2011, 2015
|
||||
# Free Software Foundation, Inc.
|
||||
|
||||
# This file is part of GCC.
|
||||
|
||||
@@ -291,7 +291,7 @@ while(<$inf>) {
|
||||
if (defined $1) {
|
||||
my $thing = $1;
|
||||
if ($ic =~ /\@asis/) {
|
||||
$_ = "\n=item $thing\n";
|
||||
$_ = "\n=item C<$thing>\n";
|
||||
} else {
|
||||
# Entity escapes prevent munging by the <> processing below.
|
||||
$_ = "\n=item $ic\<$thing\>\n";
|
||||
@@ -315,6 +315,8 @@ die "No filename or title\n" unless defined $fn && defined $tl;
|
||||
$sects{NAME} = "$fn \- $tl\n";
|
||||
$sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES};
|
||||
|
||||
print "=encoding utf-8\n\n";
|
||||
|
||||
for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT EXITSTATUS
|
||||
FILES BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) {
|
||||
if(exists $sects{$sect}) {
|
||||
|
||||
695
doc/wget.texi
695
doc/wget.texi
File diff suppressed because it is too large
Load Diff
1
gnulib
Submodule
1
gnulib
Submodule
Submodule gnulib added at 55c6f22b80
@@ -51,8 +51,8 @@ dnl /usr/local/include (!), which GCC uses before /usr/include.
|
||||
|
||||
AC_DEFUN([WGET_FNMATCH], [
|
||||
AC_MSG_CHECKING([for working fnmatch.h])
|
||||
AC_COMPILE_IFELSE([#include <fnmatch.h>
|
||||
], [
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([#include <fnmatch.h>
|
||||
])], [
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE([HAVE_WORKING_FNMATCH_H], 1,
|
||||
[Define if fnmatch.h can be included.])
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
2009-09-06 Gisle Vanem <gvanem@broadpark.no>
|
||||
|
||||
* Makefile.WC: Added compilation of new file msdos.c.
|
||||
Simplified; no need to have explicit rules for files in ./lib and
|
||||
./md5. Just use the suffix search path mechanism in wmake.
|
||||
|
||||
2009-09-06 Gisle Vanem <gvanem@broadpark.no>
|
||||
|
||||
* Makefile.DJ: Added compilation of new file msdos.c.
|
||||
|
||||
2009-09-05 Gisle Vanem <gvanem@broadpark.no>
|
||||
|
||||
* config.h: Added 'HAVE_ALLOCA_H' for Watcom 1.5+. Added
|
||||
'USE_WATT32' since all DOS-targets use the Watt-32 tcp/ip stack.
|
||||
Added meaningless dummy LOCALEDIR.
|
||||
|
||||
* Makefile.WC: A much needed update. Added rules for many files
|
||||
in ./lib, css.c and version.c.
|
||||
|
||||
* Makefile.DJ: A much needed update. Added rules for css.c and
|
||||
version.c.
|
||||
|
||||
2008-01-25 Micah Cowan <micah@cowan.name>
|
||||
|
||||
* config.h: Updated copyright year.
|
||||
|
||||
2007-11-28 Micah Cowan <micah@cowan.name>
|
||||
|
||||
* config.h: Updated license exception for OpenSSL, per the SFLC.
|
||||
|
||||
2007-10-15 Gisle Vanem <gvanem@broadpark.no>
|
||||
|
||||
* config.h: Added some HAVE_* for djgpp 2.04 and Watcom 1.7+.
|
||||
|
||||
* Makefile.DJ: rewritten for including some files from ../lib.
|
||||
|
||||
* Makefile.WC: Ditto. Handling source-files out-of current
|
||||
directory makes compliation a bit more painfull. AFAICS, one
|
||||
must use explicit rules.
|
||||
|
||||
2007-10-02 Gisle Vanem <gvanem@broadpark.no>
|
||||
|
||||
* config.h: Removed unused defines, added needed 'HAVE_*' defines.
|
||||
|
||||
* Makefile.DJ: rewritten to be used from './src' directory.
|
||||
Added '-DOPENSSL_NO_KRB5' for OpenSSL build. Target is
|
||||
now wget.exe.
|
||||
|
||||
* Makefile.WC: Added for building with OpenWatcom targeting
|
||||
32-bit DOS (DOS32A extender).
|
||||
|
||||
2007-09-24 Gisle Vanem <giva@bgnett.no>
|
||||
|
||||
* Makefile.DJ, config.h: Added to support building on MS-DOS via
|
||||
DJGPP.
|
||||
@@ -87,4 +87,3 @@ depend: version.c
|
||||
sed -e 's/^\([a-zA-Z0-9_-]*\.o:\)/$$(OBJ_DIR)\/\1/' > depend.dj
|
||||
|
||||
-include depend.dj
|
||||
|
||||
|
||||
@@ -65,4 +65,3 @@ version.c: ..\msdos\Makefile.WC
|
||||
clean: .SYMBOLIC
|
||||
- rm $(OBJ_DIR)\*.obj wget.exe wget.map version.c css.c
|
||||
- rmdir $(OBJ_DIR)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Configuration header file for MS-DOS/Watt-32
|
||||
Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
Copyright (C) 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* MSDOS utility functions.
|
||||
Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 2009, 2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -105,4 +105,3 @@ getpass (const char *prompt)
|
||||
|
||||
return strdup (getpassbuf);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,13 @@
|
||||
|
||||
# Package source files
|
||||
lib/error.c
|
||||
lib/gai_strerror.c
|
||||
lib/getopt.c
|
||||
lib/quotearg.c
|
||||
lib/regcomp.c
|
||||
lib/spawn-pipe.c
|
||||
lib/w32spawn.h
|
||||
lib/wait-process.c
|
||||
lib/xalloc-die.c
|
||||
src/connect.c
|
||||
src/convert.c
|
||||
@@ -21,6 +26,7 @@ src/init.c
|
||||
src/iri.c
|
||||
src/log.c
|
||||
src/main.c
|
||||
src/metalink.c
|
||||
src/mswindows.c
|
||||
src/netrc.c
|
||||
src/openssl.c
|
||||
@@ -32,3 +38,4 @@ src/retr.c
|
||||
src/spider.c
|
||||
src/url.c
|
||||
src/utils.c
|
||||
src/warc.c
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
timestamp
|
||||
13528
src/ChangeLog
13528
src/ChangeLog
File diff suppressed because it is too large
Load Diff
@@ -56,4 +56,3 @@ MODS_OBJS_LIB_SRC_SSL =
|
||||
.ENDIF # CDEFS_SSL [else]
|
||||
|
||||
MODS_OBJS_LIB_SRC = $(MODS_OBJS_LIB_SRC_NOSSL) $(MODS_OBJS_LIB_SRC_SSL)
|
||||
|
||||
|
||||
@@ -32,4 +32,3 @@ CFLAGS_SPEC = /prefix_library_entries = \
|
||||
# Object library modules.
|
||||
|
||||
.INCLUDE DESCRIP_MODS.MMS
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for `wget' utility
|
||||
# Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
|
||||
# 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
# 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
# Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@@ -35,6 +35,10 @@ if IRI_IS_ENABLED
|
||||
IRI_OBJ = iri.c
|
||||
endif
|
||||
|
||||
if METALINK_IS_ENABLED
|
||||
METALINK_OBJ = metalink.c
|
||||
endif
|
||||
|
||||
# The following line is losing on some versions of make!
|
||||
DEFS = @DEFS@ -DSYSTEM_WGETRC=\"$(sysconfdir)/wgetrc\" -DLOCALEDIR=\"$(localedir)\"
|
||||
LIBS = @LIBICONV@ @LIBINTL@ @LIBS@ $(LIB_CLOCK_GETTIME)
|
||||
@@ -42,18 +46,18 @@ LIBS = @LIBICONV@ @LIBINTL@ @LIBS@ $(LIB_CLOCK_GETTIME)
|
||||
EXTRA_DIST = css.l css.c css_.c build_info.c.in
|
||||
|
||||
bin_PROGRAMS = wget
|
||||
wget_SOURCES = cmpt.c connect.c convert.c cookies.c ftp.c \
|
||||
css_.c css-url.c \
|
||||
ftp-basic.c ftp-ls.c hash.c host.c html-parse.c html-url.c \
|
||||
http.c init.c log.c main.c netrc.c progress.c ptimer.c \
|
||||
recur.c res.c retr.c spider.c url.c warc.c \
|
||||
utils.c exits.c build_info.c $(IRI_OBJ) \
|
||||
css-url.h css-tokens.h connect.h convert.h cookies.h \
|
||||
ftp.h hash.h host.h html-parse.h html-url.h \
|
||||
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
|
||||
options.h progress.h ptimer.h recur.h res.h retr.h \
|
||||
spider.h ssl.h sysdep.h url.h warc.h utils.h wget.h iri.h \
|
||||
exits.h gettext.h
|
||||
wget_SOURCES = connect.c convert.c cookies.c ftp.c \
|
||||
css_.c css-url.c \
|
||||
ftp-basic.c ftp-ls.c hash.c host.c hsts.c html-parse.c html-url.c \
|
||||
http.c init.c log.c main.c netrc.c progress.c ptimer.c \
|
||||
recur.c res.c retr.c spider.c url.c warc.c \
|
||||
utils.c exits.c build_info.c $(IRI_OBJ) $(METALINK_OBJ) \
|
||||
css-url.h css-tokens.h connect.h convert.h cookies.h \
|
||||
ftp.h hash.h host.h hsts.h html-parse.h html-url.h \
|
||||
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
|
||||
options.h progress.h ptimer.h recur.h res.h retr.h \
|
||||
spider.h ssl.h sysdep.h url.h warc.h utils.h wget.h iri.h \
|
||||
exits.h version.h metalink.h
|
||||
nodist_wget_SOURCES = version.c
|
||||
EXTRA_wget_SOURCES = iri.c
|
||||
LDADD = $(LIBOBJS) ../lib/libgnu.a
|
||||
@@ -74,6 +78,7 @@ version.c: $(wget_SOURCES) ../lib/libgnu.a
|
||||
echo '/* version.c */' > $@
|
||||
echo '/* Autogenerated by Makefile - DO NOT EDIT */' >> $@
|
||||
echo '' >> $@
|
||||
echo '#include "version.h"' >> $@
|
||||
echo 'const char *version_string = "@VERSION@";' >> $@
|
||||
echo 'const char *compilation_string = "'$(COMPILE)'";' \
|
||||
| $(ESCAPEQUOTE) >> $@
|
||||
@@ -82,7 +87,7 @@ version.c: $(wget_SOURCES) ../lib/libgnu.a
|
||||
| $(ESCAPEQUOTE) >> $@
|
||||
|
||||
css.c: $(srcdir)/css.l
|
||||
$(LEX) $(LFLAGS) -o $@ $^
|
||||
$(LEX) $(LFLAGS) -o$@ $^
|
||||
|
||||
css_.c: css.c
|
||||
echo '#include "wget.h"' > $@
|
||||
|
||||
@@ -2,11 +2,16 @@ digest defined ENABLE_DIGEST
|
||||
https defined HAVE_SSL
|
||||
ipv6 defined ENABLE_IPV6
|
||||
iri defined ENABLE_IRI
|
||||
large-file SIZEOF_OFF_T >= 8
|
||||
large-file SIZEOF_OFF_T >= 8 || defined WINDOWS
|
||||
|
||||
nls defined ENABLE_NLS
|
||||
ntlm defined ENABLE_NTLM
|
||||
opie defined ENABLE_OPIE
|
||||
psl defined HAVE_LIBPSL
|
||||
cares defined HAVE_LIBCARES
|
||||
|
||||
metalink defined HAVE_METALINK
|
||||
gpgme defined HAVE_GPGME
|
||||
|
||||
ssl choice:
|
||||
openssl defined HAVE_LIBSSL || defined HAVE_LIBSSL32
|
||||
|
||||
1427
src/cmpt.c
1427
src/cmpt.c
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/* Establishing and handling network connections.
|
||||
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
|
||||
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
@@ -54,15 +54,17 @@ as that of the covered work. */
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef ENABLE_IRI
|
||||
#include <idn-free.h>
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include "host.h"
|
||||
#include "connect.h"
|
||||
#include "hash.h"
|
||||
|
||||
/* Apparently needed for Interix: */
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
/* Define sockaddr_storage where unavailable (presumably on IPv4-only
|
||||
hosts). */
|
||||
@@ -171,7 +173,7 @@ sockaddr_size (const struct sockaddr *sa)
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Resolve the bind address specified via --bind-address and store it
|
||||
to SA. The resolved value is stored in a static variable and
|
||||
reused after the first invocation of this function.
|
||||
@@ -216,7 +218,7 @@ resolve_bind_address (struct sockaddr *sa)
|
||||
should_bind = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
struct cwt_context {
|
||||
int fd;
|
||||
const struct sockaddr *addr;
|
||||
@@ -253,7 +255,7 @@ connect_with_timeout (int fd, const struct sockaddr *addr, socklen_t addrlen,
|
||||
errno = ETIMEDOUT;
|
||||
return ctx.result;
|
||||
}
|
||||
|
||||
|
||||
/* Connect via TCP to the specified address and port.
|
||||
|
||||
If PRINT is non-NULL, it is the host name to print that we're
|
||||
@@ -273,7 +275,7 @@ connect_to_ip (const ip_address *ip, int port, const char *print)
|
||||
const char *txt_addr = print_address (ip);
|
||||
if (0 != strcmp (print, txt_addr))
|
||||
{
|
||||
char *str = NULL, *name;
|
||||
char *str = NULL, *name;
|
||||
|
||||
if (opt.enable_iri && (name = idn_decode ((char *) print)) != NULL)
|
||||
{
|
||||
@@ -281,22 +283,23 @@ connect_to_ip (const ip_address *ip, int port, const char *print)
|
||||
str = xmalloc (len);
|
||||
snprintf (str, len, "%s (%s)", name, print);
|
||||
str[len-1] = '\0';
|
||||
xfree (name);
|
||||
idn_free (name);
|
||||
}
|
||||
|
||||
logprintf (LOG_VERBOSE, _("Connecting to %s|%s|:%d... "),
|
||||
str ? str : escnonprint_uri (print), txt_addr, port);
|
||||
|
||||
if (str)
|
||||
xfree (str);
|
||||
xfree (str);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
if (ip->family == AF_INET)
|
||||
logprintf (LOG_VERBOSE, _("Connecting to %s:%d... "), txt_addr, port);
|
||||
#ifdef ENABLE_IPV6
|
||||
else if (ip->family == AF_INET6)
|
||||
logprintf (LOG_VERBOSE, _("Connecting to [%s]:%d... "), txt_addr, port);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Store the sockaddr info to SA. */
|
||||
@@ -366,9 +369,16 @@ connect_to_ip (const ip_address *ip, int port, const char *print)
|
||||
logprintf. */
|
||||
int save_errno = errno;
|
||||
if (sock >= 0)
|
||||
fd_close (sock);
|
||||
{
|
||||
#ifdef WIN32
|
||||
/* If the connection timed out, fd_close will hang in Gnulib's
|
||||
close_fd_maybe_socket, inside the call to WSAEnumNetworkEvents. */
|
||||
if (errno != ETIMEDOUT)
|
||||
#endif
|
||||
fd_close (sock);
|
||||
}
|
||||
if (print)
|
||||
logprintf (LOG_VERBOSE, _("failed: %s.\n"), strerror (errno));
|
||||
logprintf (LOG_NOTQUIET, _("failed: %s.\n"), strerror (errno));
|
||||
errno = save_errno;
|
||||
return -1;
|
||||
}
|
||||
@@ -430,7 +440,7 @@ connect_to_host (const char *host, int port)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Create a socket, bind it to local interface BIND_ADDRESS on port
|
||||
*PORT, set up a listen backlog, and return the resulting socket, or
|
||||
-1 in case of error.
|
||||
@@ -557,6 +567,7 @@ socket_ip_address (int sock, ip_address *ip, int endpoint)
|
||||
if (ret < 0)
|
||||
return false;
|
||||
|
||||
memset(ip, 0, sizeof(ip_address));
|
||||
ip->family = sockaddr->sa_family;
|
||||
switch (sockaddr->sa_family)
|
||||
{
|
||||
@@ -746,7 +757,7 @@ wget uses blocking sockets so we must convert them back to blocking
|
||||
or EOF/error. */
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Basic socket operations, mostly EINTR wrappers. */
|
||||
|
||||
static int
|
||||
@@ -794,7 +805,7 @@ sock_close (int fd)
|
||||
#undef read
|
||||
#undef write
|
||||
#undef close
|
||||
|
||||
|
||||
/* Reading and writing from the network. We build around the socket
|
||||
(file descriptor) API, but support "extended" operations for things
|
||||
that are not mere file descriptors under the hood, such as SSL
|
||||
@@ -845,7 +856,7 @@ void *
|
||||
fd_transport_context (int fd)
|
||||
{
|
||||
struct transport_info *info = hash_table_get (transport_map, (void *)(intptr_t) fd);
|
||||
return info->ctx;
|
||||
return info ? info->ctx : NULL;
|
||||
}
|
||||
|
||||
/* When fd_read/fd_write are called multiple times in a loop, they should
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Declarations for connect.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -32,7 +32,7 @@ as that of the covered work. */
|
||||
#ifndef CONNECT_H
|
||||
#define CONNECT_H
|
||||
|
||||
#include "host.h" /* for definition of ip_address */
|
||||
#include "host.h" /* for definition of ip_address */
|
||||
|
||||
/* Function declarations */
|
||||
|
||||
|
||||
142
src/convert.c
142
src/convert.c
@@ -1,6 +1,6 @@
|
||||
/* Conversion of links to local files.
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
||||
Free Software Foundation, Inc.
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
|
||||
2014, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -46,6 +46,7 @@ as that of the covered work. */
|
||||
#include "html-url.h"
|
||||
#include "css-url.h"
|
||||
#include "iri.h"
|
||||
#include "xstrndup.h"
|
||||
|
||||
static struct hash_table *dl_file_url_map;
|
||||
struct hash_table *dl_url_file_map;
|
||||
@@ -125,7 +126,7 @@ convert_links_in_hashtable (struct hash_table *downloaded_set,
|
||||
|
||||
u = url_parse (cur_url->url->url, NULL, pi, true);
|
||||
if (!u)
|
||||
continue;
|
||||
continue;
|
||||
|
||||
local_name = hash_table_get (dl_url_file_map, u->url);
|
||||
|
||||
@@ -136,8 +137,9 @@ convert_links_in_hashtable (struct hash_table *downloaded_set,
|
||||
form. We do this even if the URL already is in
|
||||
relative form, because our directory structure may
|
||||
not be identical to that on the server (think `-nd',
|
||||
`--cut-dirs', etc.) */
|
||||
cur_url->convert = CO_CONVERT_TO_RELATIVE;
|
||||
`--cut-dirs', etc.). If --convert-file-only was passed,
|
||||
we only convert the basename portion of the URL. */
|
||||
cur_url->convert = (opt.convert_file_only ? CO_CONVERT_BASENAME_ONLY : CO_CONVERT_TO_RELATIVE);
|
||||
cur_url->local_name = xstrdup (local_name);
|
||||
DEBUGP (("will convert url %s to local %s\n", u->url, local_name));
|
||||
}
|
||||
@@ -193,7 +195,7 @@ convert_all_links (void)
|
||||
convert_links_in_hashtable (downloaded_css_set, 1, &file_count);
|
||||
|
||||
secs = ptimer_measure (timer);
|
||||
logprintf (LOG_VERBOSE, _("Converted %d files in %s seconds.\n"),
|
||||
logprintf (LOG_VERBOSE, _("Converted links in %d files in %s seconds.\n"),
|
||||
file_count, print_decimal (secs));
|
||||
|
||||
ptimer_destroy (timer);
|
||||
@@ -206,6 +208,7 @@ static const char *replace_attr_refresh_hack (const char *, int, FILE *,
|
||||
const char *, int);
|
||||
static char *local_quote_string (const char *, bool);
|
||||
static char *construct_relative (const char *, const char *);
|
||||
static char *convert_basename (const char *, const struct urlpos *);
|
||||
|
||||
/* Change the links in one file. LINKS is a list of links in the
|
||||
document, along with their positions and the desired direction of
|
||||
@@ -221,7 +224,7 @@ convert_links (const char *file, struct urlpos *links)
|
||||
struct urlpos *link;
|
||||
int to_url_count = 0, to_file_count = 0;
|
||||
|
||||
logprintf (LOG_VERBOSE, _("Converting %s... "), file);
|
||||
logprintf (LOG_VERBOSE, _("Converting links in %s... "), file);
|
||||
|
||||
{
|
||||
/* First we do a "dry run": go through the list L and see whether
|
||||
@@ -305,7 +308,7 @@ convert_links (const char *file, struct urlpos *links)
|
||||
char *quoted_newname = local_quote_string (newname,
|
||||
link->link_css_p);
|
||||
|
||||
if (link->link_css_p)
|
||||
if (link->link_css_p || link->link_noquote_html_p)
|
||||
p = replace_plain (p, link->size, fp, quoted_newname);
|
||||
else if (!link->link_refresh_p)
|
||||
p = replace_attr (p, link->size, fp, quoted_newname);
|
||||
@@ -315,9 +318,32 @@ convert_links (const char *file, struct urlpos *links)
|
||||
|
||||
DEBUGP (("TO_RELATIVE: %s to %s at position %d in %s.\n",
|
||||
link->url->url, newname, link->pos, file));
|
||||
|
||||
xfree (newname);
|
||||
xfree (quoted_newname);
|
||||
++to_file_count;
|
||||
break;
|
||||
}
|
||||
case CO_CONVERT_BASENAME_ONLY:
|
||||
{
|
||||
char *newname = convert_basename (p, link);
|
||||
char *quoted_newname = local_quote_string (newname, link->link_css_p);
|
||||
|
||||
if (link->link_css_p || link->link_noquote_html_p)
|
||||
p = replace_plain (p, link->size, fp, quoted_newname);
|
||||
else if (!link->link_refresh_p)
|
||||
p = replace_attr (p, link->size, fp, quoted_newname);
|
||||
else
|
||||
p = replace_attr_refresh_hack (p, link->size, fp, quoted_newname,
|
||||
link->refresh_timeout);
|
||||
|
||||
DEBUGP (("Converted file part only: %s to %s at position %d in %s.\n",
|
||||
link->url->url, newname, link->pos, file));
|
||||
|
||||
xfree (newname);
|
||||
xfree (quoted_newname);
|
||||
++to_file_count;
|
||||
|
||||
break;
|
||||
}
|
||||
case CO_CONVERT_TO_COMPLETE:
|
||||
@@ -326,7 +352,7 @@ convert_links (const char *file, struct urlpos *links)
|
||||
char *newlink = link->url->url;
|
||||
char *quoted_newlink = html_quote_string (newlink);
|
||||
|
||||
if (link->link_css_p)
|
||||
if (link->link_css_p || link->link_noquote_html_p)
|
||||
p = replace_plain (p, link->size, fp, newlink);
|
||||
else if (!link->link_refresh_p)
|
||||
p = replace_attr (p, link->size, fp, quoted_newlink);
|
||||
@@ -336,6 +362,7 @@ convert_links (const char *file, struct urlpos *links)
|
||||
|
||||
DEBUGP (("TO_COMPLETE: <something> to %s at position %d in %s.\n",
|
||||
newlink, link->pos, file));
|
||||
|
||||
xfree (quoted_newlink);
|
||||
++to_url_count;
|
||||
break;
|
||||
@@ -414,14 +441,89 @@ construct_relative (const char *basefile, const char *linkfile)
|
||||
++basedirs;
|
||||
}
|
||||
|
||||
/* Construct LINK as explained above. */
|
||||
link = xmalloc (3 * basedirs + strlen (linkfile) + 1);
|
||||
for (i = 0; i < basedirs; i++)
|
||||
memcpy (link + 3 * i, "../", 3);
|
||||
strcpy (link + 3 * i, linkfile);
|
||||
if (!basedirs && (b = strpbrk (linkfile, "/:")) && *b == ':')
|
||||
{
|
||||
link = xmalloc (2 + strlen (linkfile) + 1);
|
||||
memcpy (link, "./", 2);
|
||||
strcpy (link + 2, linkfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Construct LINK as explained above. */
|
||||
link = xmalloc (3 * basedirs + strlen (linkfile) + 1);
|
||||
for (i = 0; i < basedirs; i++)
|
||||
memcpy (link + 3 * i, "../", 3);
|
||||
strcpy (link + 3 * i, linkfile);
|
||||
}
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
/* Construct and return a "transparent proxy" URL
|
||||
reflecting changes made by --adjust-extension to the file component
|
||||
(i.e., "basename") of the original URL, but leaving the "dirname"
|
||||
of the URL (protocol://hostname... portion) untouched.
|
||||
|
||||
Think: populating a squid cache via a recursive wget scrape, where
|
||||
changing URLs to work locally with "file://..." is NOT desirable.
|
||||
|
||||
Example:
|
||||
|
||||
if
|
||||
p = "//foo.com/bar.cgi?xyz"
|
||||
and
|
||||
link->local_name = "docroot/foo.com/bar.cgi?xyz.css"
|
||||
then
|
||||
|
||||
new_construct_func(p, link);
|
||||
will return
|
||||
"//foo.com/bar.cgi?xyz.css"
|
||||
|
||||
Essentially, we do s/$(basename orig_url)/$(basename link->local_name)/
|
||||
*/
|
||||
static char *
|
||||
convert_basename (const char *p, const struct urlpos *link)
|
||||
{
|
||||
int len = link->size;
|
||||
char *url = NULL;
|
||||
char *org_basename = NULL, *local_basename = NULL;
|
||||
char *result = NULL;
|
||||
|
||||
if (*p == '"' || *p == '\'')
|
||||
{
|
||||
len -= 2;
|
||||
p++;
|
||||
}
|
||||
|
||||
url = xstrndup (p, len);
|
||||
|
||||
org_basename = strrchr (url, '/');
|
||||
if (org_basename)
|
||||
org_basename++;
|
||||
else
|
||||
org_basename = url;
|
||||
|
||||
local_basename = strrchr (link->local_name, '/');
|
||||
if (local_basename)
|
||||
local_basename++;
|
||||
else
|
||||
local_basename = url;
|
||||
|
||||
/*
|
||||
* If the basenames differ, graft the adjusted basename (local_basename)
|
||||
* onto the original URL.
|
||||
*/
|
||||
if (strcmp (org_basename, local_basename) == 0)
|
||||
result = url;
|
||||
else
|
||||
{
|
||||
result = uri_merge (url, local_basename);
|
||||
xfree (url);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Used by write_backup_file to remember which files have been
|
||||
written. */
|
||||
static struct hash_table *converted_files;
|
||||
@@ -465,7 +567,7 @@ write_backup_file (const char *file, downloaded_file_t downloaded_file_return)
|
||||
converted_files = make_string_hash_table (0);
|
||||
|
||||
/* We can get called twice on the same URL thanks to the
|
||||
convert_all_links() call in main(). If we write the .orig file
|
||||
convert_all_links() call in main. If we write the .orig file
|
||||
each time in such a case, it'll end up containing the first-pass
|
||||
conversion, not the original file. So, see if we've already been
|
||||
called on this file. */
|
||||
@@ -626,6 +728,7 @@ local_quote_string (const char *file, bool no_html_quote)
|
||||
/* Allocate space assuming the worst-case scenario, each character
|
||||
having to be quoted. */
|
||||
to = newname = (char *)alloca (3 * strlen (file) + 1);
|
||||
newname[0] = '\0';
|
||||
for (from = file; *from; from++)
|
||||
switch (*from)
|
||||
{
|
||||
@@ -660,7 +763,7 @@ local_quote_string (const char *file, bool no_html_quote)
|
||||
|
||||
return no_html_quote ? strdup (newname) : html_quote_string (newname);
|
||||
}
|
||||
|
||||
|
||||
/* Book-keeping code for dl_file_url_map, dl_url_file_map,
|
||||
downloaded_html_list, and downloaded_html_set. Other code calls
|
||||
these functions to let us know that a file has been downloaded. */
|
||||
@@ -835,7 +938,7 @@ register_download (const char *url, const char *file)
|
||||
hash_table_put (dl_url_file_map, xstrdup (url), xstrdup (file));
|
||||
}
|
||||
|
||||
/* Register that FROM has been redirected to TO. This assumes that TO
|
||||
/* Register that FROM has been redirected to "TO". This assumes that TO
|
||||
is successfully downloaded and already registered using
|
||||
register_download() above. */
|
||||
|
||||
@@ -915,7 +1018,7 @@ convert_cleanup (void)
|
||||
if (converted_files)
|
||||
string_set_free (converted_files);
|
||||
}
|
||||
|
||||
|
||||
/* Book-keeping code for downloaded files that enables extension
|
||||
hacks. */
|
||||
|
||||
@@ -1011,7 +1114,7 @@ downloaded_files_free (void)
|
||||
downloaded_files_hash = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* The function returns the pointer to the malloc-ed quoted version of
|
||||
string s. It will recognize and quote numeric and special graphic
|
||||
entities, as per RFC1866:
|
||||
@@ -1087,4 +1190,3 @@ html_quote_string (const char *s)
|
||||
/*
|
||||
* vim: et ts=2 sw=2
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Declarations for convert.c
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010, 2011 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010, 2011, 2015 Free
|
||||
Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -31,18 +31,20 @@ as that of the covered work. */
|
||||
#ifndef CONVERT_H
|
||||
#define CONVERT_H
|
||||
|
||||
struct hash_table; /* forward decl */
|
||||
struct hash_table; /* forward decl */
|
||||
extern struct hash_table *dl_url_file_map;
|
||||
extern struct hash_table *downloaded_html_set;
|
||||
extern struct hash_table *downloaded_css_set;
|
||||
|
||||
enum convert_options {
|
||||
CO_NOCONVERT = 0, /* don't convert this URL */
|
||||
CO_CONVERT_TO_RELATIVE, /* convert to relative, e.g. to
|
||||
CO_NOCONVERT = 0, /* don't convert this URL */
|
||||
CO_CONVERT_TO_RELATIVE, /* convert to relative, e.g. to
|
||||
"../../otherdir/foo.gif" */
|
||||
CO_CONVERT_TO_COMPLETE, /* convert to absolute, e.g. to
|
||||
"http://orighost/somedir/bar.jpg". */
|
||||
CO_NULLIFY_BASE /* change to empty string. */
|
||||
CO_CONVERT_BASENAME_ONLY, /* convert the file portion only (basename)
|
||||
leaving the rest of the URL unchanged */
|
||||
CO_CONVERT_TO_COMPLETE, /* convert to absolute, e.g. to
|
||||
"http://orighost/somedir/bar.jpg". */
|
||||
CO_NULLIFY_BASE /* change to empty string. */
|
||||
};
|
||||
|
||||
struct url;
|
||||
@@ -51,36 +53,37 @@ struct url;
|
||||
position in an HTML document, etc. */
|
||||
|
||||
struct urlpos {
|
||||
struct url *url; /* the URL of the link, after it has
|
||||
been merged with the base */
|
||||
char *local_name; /* local file to which it was saved
|
||||
(used by convert_links) */
|
||||
struct url *url; /* the URL of the link, after it has
|
||||
been merged with the base */
|
||||
char *local_name; /* local file to which it was saved
|
||||
(used by convert_links) */
|
||||
|
||||
/* reserved for special links such as <base href="..."> which are
|
||||
used when converting links, but ignored when downloading. */
|
||||
unsigned int ignore_when_downloading :1;
|
||||
unsigned int ignore_when_downloading :1;
|
||||
|
||||
/* Information about the original link: */
|
||||
|
||||
unsigned int link_relative_p :1; /* the link was relative */
|
||||
unsigned int link_complete_p :1; /* the link was complete (had host name) */
|
||||
unsigned int link_base_p :1; /* the url came from <base href=...> */
|
||||
unsigned int link_inline_p :1; /* needed to render the page */
|
||||
unsigned int link_css_p :1; /* the url came from CSS */
|
||||
unsigned int link_expect_html :1; /* expected to contain HTML */
|
||||
unsigned int link_expect_css :1; /* expected to contain CSS */
|
||||
unsigned int link_relative_p :1; /* the link was relative */
|
||||
unsigned int link_complete_p :1; /* the link was complete (had host name) */
|
||||
unsigned int link_base_p :1; /* the url came from <base href=...> */
|
||||
unsigned int link_inline_p :1; /* needed to render the page */
|
||||
unsigned int link_css_p :1; /* the url came from CSS */
|
||||
unsigned int link_noquote_html_p :1; /* from HTML, but doesn't need " */
|
||||
unsigned int link_expect_html :1; /* expected to contain HTML */
|
||||
unsigned int link_expect_css :1; /* expected to contain CSS */
|
||||
|
||||
unsigned int link_refresh_p :1; /* link was received from
|
||||
<meta http-equiv=refresh content=...> */
|
||||
int refresh_timeout; /* for reconstructing the refresh. */
|
||||
unsigned int link_refresh_p :1; /* link was received from
|
||||
<meta http-equiv=refresh content=...> */
|
||||
int refresh_timeout; /* for reconstructing the refresh. */
|
||||
|
||||
/* Conversion requirements: */
|
||||
enum convert_options convert; /* is conversion required? */
|
||||
enum convert_options convert; /* is conversion required? */
|
||||
|
||||
/* URL's position in the buffer. */
|
||||
int pos, size;
|
||||
|
||||
struct urlpos *next; /* next list element */
|
||||
struct urlpos *next; /* next list element */
|
||||
};
|
||||
|
||||
/* downloaded_file() takes a parameter of this type and returns this type. */
|
||||
|
||||
137
src/cookies.c
137
src/cookies.c
@@ -1,6 +1,6 @@
|
||||
/* Support for cookies.
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
2010, 2011 Free Software Foundation, Inc.
|
||||
2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -51,11 +51,16 @@ as that of the covered work. */
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#ifdef HAVE_LIBPSL
|
||||
# include <libpsl.h>
|
||||
#endif
|
||||
#include "utils.h"
|
||||
#include "hash.h"
|
||||
#include "cookies.h"
|
||||
#include "http.h" /* for http_atotm */
|
||||
|
||||
#include "c-strcase.h"
|
||||
|
||||
|
||||
/* Declarations of `struct cookie' and the most basic functions. */
|
||||
|
||||
/* Cookie jar serves as cookie storage and a means of retrieving
|
||||
@@ -95,7 +100,7 @@ struct cookie {
|
||||
int port; /* port number */
|
||||
char *path; /* path prefix of the cookie */
|
||||
|
||||
unsigned discard_requested :1; /* whether cookie was created to
|
||||
unsigned discard_requested :1;/* whether cookie was created to
|
||||
request discarding another
|
||||
cookie. */
|
||||
|
||||
@@ -148,13 +153,13 @@ cookie_expired_p (const struct cookie *c)
|
||||
static void
|
||||
delete_cookie (struct cookie *cookie)
|
||||
{
|
||||
xfree_null (cookie->domain);
|
||||
xfree_null (cookie->path);
|
||||
xfree_null (cookie->attr);
|
||||
xfree_null (cookie->value);
|
||||
xfree (cookie->domain);
|
||||
xfree (cookie->path);
|
||||
xfree (cookie->attr);
|
||||
xfree (cookie->value);
|
||||
xfree (cookie);
|
||||
}
|
||||
|
||||
|
||||
/* Functions for storing cookies.
|
||||
|
||||
All cookies can be reached beginning with jar->chains. The key in
|
||||
@@ -299,7 +304,12 @@ discard_matching_cookie (struct cookie_jar *jar, struct cookie *cookie)
|
||||
|
||||
res = hash_table_get_pair (jar->chains, victim->domain,
|
||||
&chain_key, NULL);
|
||||
assert (res != 0);
|
||||
|
||||
if (res == 0)
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("Unable to get cookie for %s\n"),
|
||||
victim->domain);
|
||||
}
|
||||
if (!victim->next)
|
||||
{
|
||||
/* VICTIM was the only cookie in the chain. Destroy the
|
||||
@@ -314,7 +324,7 @@ discard_matching_cookie (struct cookie_jar *jar, struct cookie *cookie)
|
||||
DEBUGP (("Discarded old cookie.\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Functions for parsing the `Set-Cookie' header, and creating new
|
||||
cookies from the wire. */
|
||||
|
||||
@@ -346,7 +356,7 @@ parse_set_cookie (const char *set_cookie, bool silent)
|
||||
struct cookie *cookie = cookie_new ();
|
||||
param_token name, value;
|
||||
|
||||
if (!extract_param (&ptr, &name, &value, ';'))
|
||||
if (!extract_param (&ptr, &name, &value, ';', NULL))
|
||||
goto error;
|
||||
if (!value.b)
|
||||
goto error;
|
||||
@@ -360,13 +370,13 @@ parse_set_cookie (const char *set_cookie, bool silent)
|
||||
cookie->attr = strdupdelim (name.b, name.e);
|
||||
cookie->value = strdupdelim (value.b, value.e);
|
||||
|
||||
while (extract_param (&ptr, &name, &value, ';'))
|
||||
while (extract_param (&ptr, &name, &value, ';', NULL))
|
||||
{
|
||||
if (TOKEN_IS (name, "domain"))
|
||||
{
|
||||
if (!TOKEN_NON_EMPTY (value))
|
||||
goto error;
|
||||
xfree_null (cookie->domain);
|
||||
xfree (cookie->domain);
|
||||
/* Strictly speaking, we should set cookie->domain_exact if the
|
||||
domain doesn't begin with a dot. But many sites set the
|
||||
domain to "foo.com" and expect "subhost.foo.com" to get the
|
||||
@@ -379,7 +389,7 @@ parse_set_cookie (const char *set_cookie, bool silent)
|
||||
{
|
||||
if (!TOKEN_NON_EMPTY (value))
|
||||
goto error;
|
||||
xfree_null (cookie->path);
|
||||
xfree (cookie->path);
|
||||
cookie->path = strdupdelim (value.b, value.e);
|
||||
}
|
||||
else if (TOKEN_IS (name, "expires"))
|
||||
@@ -393,7 +403,7 @@ parse_set_cookie (const char *set_cookie, bool silent)
|
||||
|
||||
/* Check if expiration spec is valid.
|
||||
If not, assume default (cookie doesn't expire, but valid only for
|
||||
this session.) */
|
||||
this session.) */
|
||||
expires = http_atotm (value_copy);
|
||||
if (expires != (time_t) -1)
|
||||
{
|
||||
@@ -453,16 +463,16 @@ parse_set_cookie (const char *set_cookie, bool silent)
|
||||
|
||||
#undef TOKEN_IS
|
||||
#undef TOKEN_NON_EMPTY
|
||||
|
||||
|
||||
/* Sanity checks. These are important, otherwise it is possible for
|
||||
mailcious attackers to destroy important cookie information and/or
|
||||
violate your privacy. */
|
||||
|
||||
|
||||
#define REQUIRE_DIGITS(p) do { \
|
||||
if (!c_isdigit (*p)) \
|
||||
if (!c_isdigit (*p)) \
|
||||
return false; \
|
||||
for (++p; c_isdigit (*p); p++) \
|
||||
for (++p; c_isdigit (*p); p++) \
|
||||
; \
|
||||
} while (0)
|
||||
|
||||
@@ -498,19 +508,61 @@ numeric_address_p (const char *addr)
|
||||
/* Check whether COOKIE_DOMAIN is an appropriate domain for HOST.
|
||||
Originally I tried to make the check compliant with rfc2109, but
|
||||
the sites deviated too often, so I had to fall back to "tail
|
||||
matching", as defined by the original Netscape's cookie spec. */
|
||||
matching", as defined by the original Netscape's cookie spec.
|
||||
|
||||
Wget now uses libpsl to check domain names against a public suffix
|
||||
list to see if they are valid. However, since we don't provide a
|
||||
psl on our own, if libpsl is compiled without a public suffix list,
|
||||
fall back to using the original "tail matching" heuristic. Also if
|
||||
libpsl is unable to convert the domain to lowercase, which means that
|
||||
it doesnt have any runtime conversion support, we again fall back to
|
||||
"tail matching" since libpsl states the results are unpredictable with
|
||||
upper case strings.
|
||||
*/
|
||||
|
||||
static bool
|
||||
check_domain_match (const char *cookie_domain, const char *host)
|
||||
{
|
||||
|
||||
#ifdef HAVE_LIBPSL
|
||||
char *cookie_domain_lower = NULL;
|
||||
char *host_lower = NULL;
|
||||
const psl_ctx_t *psl;
|
||||
int is_acceptable;
|
||||
|
||||
DEBUGP (("cdm: 1"));
|
||||
if (!(psl = psl_builtin()))
|
||||
{
|
||||
DEBUGP (("\nlibpsl not built with a public suffix list. "
|
||||
"Falling back to simple heuristics.\n"));
|
||||
goto no_psl;
|
||||
}
|
||||
|
||||
/* Numeric address requires exact match. It also requires HOST to
|
||||
be an IP address. */
|
||||
if (numeric_address_p (cookie_domain))
|
||||
return 0 == strcmp (cookie_domain, host);
|
||||
if (psl_str_to_utf8lower (cookie_domain, NULL, NULL, &cookie_domain_lower) == PSL_SUCCESS &&
|
||||
psl_str_to_utf8lower (host, NULL, NULL, &host_lower) == PSL_SUCCESS)
|
||||
{
|
||||
is_acceptable = psl_is_cookie_domain_acceptable (psl, host_lower, cookie_domain_lower);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUGP (("libpsl unable to parse domain name. "
|
||||
"Falling back to simple heuristics.\n"));
|
||||
goto no_psl;
|
||||
}
|
||||
|
||||
DEBUGP ((" 2"));
|
||||
xfree (cookie_domain_lower);
|
||||
xfree (host_lower);
|
||||
|
||||
return is_acceptable == 1;
|
||||
|
||||
no_psl:
|
||||
/* Cleanup the PSL pointers first */
|
||||
xfree (cookie_domain_lower);
|
||||
xfree (host_lower);
|
||||
#endif
|
||||
|
||||
/* For efficiency make some elementary checks first */
|
||||
DEBUGP (("cdm: 2"));
|
||||
|
||||
/* For the sake of efficiency, check for exact match first. */
|
||||
if (0 == strcasecmp (cookie_domain, host))
|
||||
@@ -647,7 +699,7 @@ check_path_match (const char *cookie_path, const char *path)
|
||||
s = PS_newstr; \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
/* Process the HTTP `Set-Cookie' header. This results in storing the
|
||||
cookie or discarding a matching one, or ignoring it completely, all
|
||||
depending on the contents. */
|
||||
@@ -673,9 +725,6 @@ cookie_handle_set_cookie (struct cookie_jar *jar,
|
||||
|
||||
if (!cookie->domain)
|
||||
{
|
||||
copy_domain:
|
||||
/* If the domain was not provided, we use the one we're talking
|
||||
to, and set exact match. */
|
||||
cookie->domain = xstrdup (host);
|
||||
cookie->domain_exact = 1;
|
||||
/* Set the port, but only if it's non-default. */
|
||||
@@ -687,11 +736,12 @@ cookie_handle_set_cookie (struct cookie_jar *jar,
|
||||
if (!check_domain_match (cookie->domain, host))
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("Cookie coming from %s attempted to set domain to %s\n"),
|
||||
quotearg_style (escape_quoting_style, host),
|
||||
_("Cookie coming from %s attempted to set domain to "),
|
||||
quotearg_style (escape_quoting_style, host));
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("%s\n"),
|
||||
quotearg_style (escape_quoting_style, cookie->domain));
|
||||
xfree (cookie->domain);
|
||||
goto copy_domain;
|
||||
cookie->discard_requested = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -733,7 +783,7 @@ cookie_handle_set_cookie (struct cookie_jar *jar,
|
||||
if (cookie)
|
||||
delete_cookie (cookie);
|
||||
}
|
||||
|
||||
|
||||
/* Support for sending out cookies in HTTP requests, based on
|
||||
previously stored cookies. Entry point is
|
||||
`build_cookies_request'. */
|
||||
@@ -1064,7 +1114,7 @@ cookie_header (struct cookie_jar *jar, const char *host,
|
||||
assert (pos == result_size);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Support for loading and saving cookies. The format used for
|
||||
loading and saving should be the format of the `cookies.txt' file
|
||||
used by Netscape and Mozilla, at least the Unix versions.
|
||||
@@ -1131,7 +1181,9 @@ domain_port (const char *domain_b, const char *domain_e,
|
||||
void
|
||||
cookie_jar_load (struct cookie_jar *jar, const char *file)
|
||||
{
|
||||
char *line;
|
||||
char *line = NULL;
|
||||
size_t bufsize = 0;
|
||||
|
||||
FILE *fp = fopen (file, "r");
|
||||
if (!fp)
|
||||
{
|
||||
@@ -1139,9 +1191,10 @@ cookie_jar_load (struct cookie_jar *jar, const char *file)
|
||||
quote (file), strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
cookies_now = time (NULL);
|
||||
|
||||
for (; ((line = read_whole_line (fp)) != NULL); xfree (line))
|
||||
while (getline (&line, &bufsize, fp) > 0)
|
||||
{
|
||||
struct cookie *cookie;
|
||||
char *p = line;
|
||||
@@ -1235,6 +1288,8 @@ cookie_jar_load (struct cookie_jar *jar, const char *file)
|
||||
abort_cookie:
|
||||
delete_cookie (cookie);
|
||||
}
|
||||
|
||||
xfree(line);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
@@ -1298,7 +1353,7 @@ cookie_jar_save (struct cookie_jar *jar, const char *file)
|
||||
|
||||
DEBUGP (("Done saving cookies.\n"));
|
||||
}
|
||||
|
||||
|
||||
/* Clean up cookie-related data. */
|
||||
|
||||
void
|
||||
@@ -1321,7 +1376,7 @@ cookie_jar_delete (struct cookie_jar *jar)
|
||||
hash_table_destroy (jar->chains);
|
||||
xfree (jar);
|
||||
}
|
||||
|
||||
|
||||
/* Test cases. Currently this is only tests parse_set_cookies. To
|
||||
use, recompile Wget with -DTEST_COOKIES and call test_cookies()
|
||||
from main. */
|
||||
@@ -1374,7 +1429,7 @@ test_cookies (void)
|
||||
param_token name, value;
|
||||
const char *ptr = data;
|
||||
int j = 0;
|
||||
while (extract_param (&ptr, &name, &value, ';'))
|
||||
while (extract_param (&ptr, &name, &value, ';', NULL))
|
||||
{
|
||||
char *n = strdupdelim (name.b, name.e);
|
||||
char *v = strdupdelim (value.b, value.e);
|
||||
@@ -1390,8 +1445,8 @@ test_cookies (void)
|
||||
printf ("Invalid value %d for '%s' (expected '%s', got '%s')\n",
|
||||
j / 2 + 1, data, expected[j + 1], v);
|
||||
j += 2;
|
||||
free (n);
|
||||
free (v);
|
||||
xfree (n);
|
||||
xfree (v);
|
||||
}
|
||||
if (expected[j])
|
||||
printf ("Too few parameters for '%s'\n", data);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Support for cookies.
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
2010, 2011 Free Software Foundation, Inc.
|
||||
2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -37,9 +37,9 @@ struct cookie_jar *cookie_jar_new (void);
|
||||
void cookie_jar_delete (struct cookie_jar *);
|
||||
|
||||
void cookie_handle_set_cookie (struct cookie_jar *, const char *, int,
|
||||
const char *, const char *);
|
||||
const char *, const char *);
|
||||
char *cookie_header (struct cookie_jar *, const char *, int,
|
||||
const char *, bool);
|
||||
const char *, bool);
|
||||
|
||||
void cookie_jar_load (struct cookie_jar *, const char *);
|
||||
void cookie_jar_save (struct cookie_jar *, const char *);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* Declarations for css.lex
|
||||
Copyright (C) 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 2006, 2009, 2010, 2011, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Collect URLs from CSS source.
|
||||
Copyright (C) 1998, 2000, 2001, 2002, 2003, 2009, 2010, 2011 Free
|
||||
Software Foundation, Inc.
|
||||
Copyright (C) 1998, 2000, 2001, 2002, 2003, 2009, 2010, 2011, 2014,
|
||||
2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -41,11 +41,7 @@ as that of the covered work. */
|
||||
#include <wget.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@@ -56,6 +52,7 @@ as that of the covered work. */
|
||||
#include "html-url.h"
|
||||
#include "css-tokens.h"
|
||||
#include "css-url.h"
|
||||
#include "xstrndup.h"
|
||||
|
||||
/* from lex.yy.c */
|
||||
extern char *yytext;
|
||||
@@ -64,41 +61,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
||||
extern YY_BUFFER_STATE yy_scan_bytes (const char *bytes,int len );
|
||||
extern int yylex (void);
|
||||
|
||||
#if 1
|
||||
const char *token_names[] = {
|
||||
"CSSEOF",
|
||||
"S",
|
||||
"CDO",
|
||||
"CDC",
|
||||
"INCLUDES",
|
||||
"DASHMATCH",
|
||||
"LBRACE",
|
||||
"PLUS",
|
||||
"GREATER",
|
||||
"COMMA",
|
||||
"STRING",
|
||||
"INVALID",
|
||||
"IDENT",
|
||||
"HASH",
|
||||
"IMPORT_SYM",
|
||||
"PAGE_SYM",
|
||||
"MEDIA_SYM",
|
||||
"CHARSET_SYM",
|
||||
"IMPORTANT_SYM",
|
||||
"EMS",
|
||||
"EXS",
|
||||
"LENGTH",
|
||||
"ANGLE",
|
||||
"TIME",
|
||||
"FREQ",
|
||||
"DIMENSION",
|
||||
"PERCENTAGE",
|
||||
"NUMBER",
|
||||
"URI",
|
||||
"FUNCTION"
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
Given a detected URI token, get only the URI specified within.
|
||||
Also adjust the starting position and length of the string.
|
||||
@@ -111,12 +73,6 @@ const char *token_names[] = {
|
||||
static char *
|
||||
get_uri_string (const char *at, int *pos, int *length)
|
||||
{
|
||||
char *uri;
|
||||
/*char buf[1024];
|
||||
strncpy(buf,at + *pos, *length);
|
||||
buf[*length] = '\0';
|
||||
DEBUGP (("get_uri_string: \"%s\"\n", buf));*/
|
||||
|
||||
if (0 != strncasecmp (at + *pos, "url(", 4))
|
||||
return NULL;
|
||||
|
||||
@@ -142,14 +98,7 @@ get_uri_string (const char *at, int *pos, int *length)
|
||||
*length -= 2;
|
||||
}
|
||||
|
||||
uri = xmalloc (*length + 1);
|
||||
if (uri)
|
||||
{
|
||||
strncpy (uri, at + *pos, *length);
|
||||
uri[*length] = '\0';
|
||||
}
|
||||
|
||||
return uri;
|
||||
return xstrndup (at + *pos, *length);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -161,12 +110,6 @@ get_urls_css (struct map_context *ctx, int offset, int buf_length)
|
||||
int pos, length;
|
||||
char *uri;
|
||||
|
||||
/*
|
||||
strncpy(tmp,ctx->text + offset, buf_length);
|
||||
tmp[buf_length] = '\0';
|
||||
DEBUGP (("get_urls_css: \"%s\"\n", tmp));
|
||||
*/
|
||||
|
||||
/* tell flex to scan from this buffer */
|
||||
yy_scan_bytes (ctx->text + offset, buf_length);
|
||||
|
||||
@@ -200,7 +143,7 @@ get_urls_css (struct map_context *ctx, int offset, int buf_length)
|
||||
pos++;
|
||||
length -= 2;
|
||||
uri = xmalloc (length + 1);
|
||||
strncpy (uri, yytext + 1, length);
|
||||
memcpy (uri, yytext + 1, length);
|
||||
uri[length] = '\0';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* Declarations for css-url.c.
|
||||
Copyright (C) 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 2006, 2009, 2010, 2011, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
%{
|
||||
/* Lex source for CSS tokenizing.
|
||||
Taken from http://www.w3.org/TR/CSS21/grammar.html#q2
|
||||
Copyright (C) 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 2006, 2009, 2010, 2011, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
|
||||
int main( void)
|
||||
{
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
/* Set the current locale. */
|
||||
setlocale (LC_ALL, "");
|
||||
/* Set the text message domain. */
|
||||
bindtextdomain ("wget", LOCALEDIR);
|
||||
textdomain ("wget");
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
#ifdef __VMS_VERSION
|
||||
printf( " __VMS_VERSION: >%s<.\n", __VMS_VERSION);
|
||||
#else /* def __VMS_VERSION */
|
||||
|
||||
30
src/exits.c
30
src/exits.c
@@ -1,5 +1,6 @@
|
||||
/* Exit status handling.
|
||||
Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||
Copyright (C) 2009, 2010, 2011, 2012, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -20,24 +21,6 @@
|
||||
#include "wget.h"
|
||||
#include "exits.h"
|
||||
|
||||
/* Final exit code possibilities. Exit codes 1 and 2 are reserved
|
||||
* for situations that lead to direct exits from Wget, not using the
|
||||
* value of final_exit_status. */
|
||||
enum
|
||||
{
|
||||
WGET_EXIT_SUCCESS = 0,
|
||||
|
||||
WGET_EXIT_MINIMUM = 3,
|
||||
WGET_EXIT_IO_FAIL = WGET_EXIT_MINIMUM,
|
||||
WGET_EXIT_NETWORK_FAIL = 4,
|
||||
WGET_EXIT_SSL_AUTH_FAIL = 5,
|
||||
WGET_EXIT_SERVER_AUTH_FAIL = 6,
|
||||
WGET_EXIT_PROTOCOL_ERROR = 7,
|
||||
WGET_EXIT_SERVER_ERROR = 8,
|
||||
|
||||
WGET_EXIT_UNKNOWN
|
||||
};
|
||||
|
||||
static int final_exit_status = WGET_EXIT_SUCCESS;
|
||||
|
||||
/* XXX: I don't like that newly-added uerr_t codes will doubtless fall
|
||||
@@ -58,7 +41,7 @@ get_status_for_err (uerr_t err)
|
||||
case RETROK:
|
||||
return WGET_EXIT_SUCCESS;
|
||||
case FOPENERR: case FOPEN_EXCL_ERR: case FWRITEERR: case WRITEFAILED:
|
||||
case UNLINKERR: case CLOSEFAILED:
|
||||
case UNLINKERR: case CLOSEFAILED: case FILEBADFILE:
|
||||
return WGET_EXIT_IO_FAIL;
|
||||
case NOCONERROR: case HOSTERR: case CONSOCKERR: case CONERROR:
|
||||
case CONSSLERR: case CONIMPOSSIBLE: case FTPRERR: case FTPINVPASV:
|
||||
@@ -68,15 +51,15 @@ get_status_for_err (uerr_t err)
|
||||
return WGET_EXIT_SSL_AUTH_FAIL;
|
||||
case FTPLOGINC: case FTPLOGREFUSED: case AUTHFAILED:
|
||||
return WGET_EXIT_SERVER_AUTH_FAIL;
|
||||
case HEOF: case HERR:
|
||||
case HEOF: case HERR: case ATTRMISSING:
|
||||
return WGET_EXIT_PROTOCOL_ERROR;
|
||||
case WRONGCODE: case FTPPORTERR: case FTPSYSERR:
|
||||
case FTPNSFOD: case FTPUNKNOWNTYPE: case FTPSRVERR:
|
||||
case FTPRETRINT: case FTPRESTFAIL: case FTPNOPASV:
|
||||
case CONTNOTSUPPORTED: case RANGEERR: case RETRBADPATTERN:
|
||||
case PROXERR:
|
||||
case PROXERR: case GATEWAYTIMEOUT:
|
||||
return WGET_EXIT_SERVER_ERROR;
|
||||
case URLERROR: case QUOTEXC: case SSLINITFAILED:
|
||||
case URLERROR: case QUOTEXC: case SSLINITFAILED: case UNKNOWNATTR:
|
||||
default:
|
||||
return WGET_EXIT_UNKNOWN;
|
||||
}
|
||||
@@ -108,4 +91,3 @@ get_exit_status (void)
|
||||
? 1
|
||||
: final_exit_status;
|
||||
}
|
||||
|
||||
|
||||
20
src/exits.h
20
src/exits.h
@@ -1,5 +1,6 @@
|
||||
/* Exit status related declarations.
|
||||
Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||
Copyright (C) 2009, 2010, 2011, 2012, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -21,6 +22,23 @@ along with Wget. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "wget.h"
|
||||
|
||||
/* Final exit code possibilities. Exit codes 1 and 2 are reserved
|
||||
* for situations that lead to direct exits from Wget, not using the
|
||||
* value of final_exit_status. */
|
||||
enum
|
||||
{
|
||||
WGET_EXIT_SUCCESS = 0,
|
||||
WGET_EXIT_GENERIC_ERROR = 1,
|
||||
WGET_EXIT_PARSE_ERROR = 2,
|
||||
WGET_EXIT_IO_FAIL = 3,
|
||||
WGET_EXIT_NETWORK_FAIL = 4,
|
||||
WGET_EXIT_SSL_AUTH_FAIL = 5,
|
||||
WGET_EXIT_SERVER_AUTH_FAIL = 6,
|
||||
WGET_EXIT_PROTOCOL_ERROR = 7,
|
||||
WGET_EXIT_SERVER_ERROR = 8,
|
||||
|
||||
WGET_EXIT_UNKNOWN
|
||||
};
|
||||
|
||||
void inform_exit_status (uerr_t err);
|
||||
|
||||
|
||||
233
src/ftp-basic.c
233
src/ftp-basic.c
@@ -1,7 +1,7 @@
|
||||
/* Basic FTP routines.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -43,10 +43,9 @@ as that of the covered work. */
|
||||
#include "host.h"
|
||||
#include "ftp.h"
|
||||
#include "retr.h"
|
||||
#include "c-strcase.h"
|
||||
|
||||
char ftp_last_respline[128];
|
||||
|
||||
|
||||
/* Get the response of FTP server and allocate enough room to handle
|
||||
it. <CR> and <LF> characters are stripped from the line, and the
|
||||
line is 0-terminated. All the response lines but the last one are
|
||||
@@ -84,8 +83,6 @@ ftp_response (int fd, char **ret_line)
|
||||
if (c_isdigit (line[0]) && c_isdigit (line[1]) && c_isdigit (line[2])
|
||||
&& line[3] == ' ')
|
||||
{
|
||||
strncpy (ftp_last_respline, line, sizeof (ftp_last_respline));
|
||||
ftp_last_respline[sizeof (ftp_last_respline) - 1] = '\0';
|
||||
*ret_line = line;
|
||||
return FTPOK;
|
||||
}
|
||||
@@ -138,6 +135,23 @@ ftp_request (const char *command, const char *value)
|
||||
return res;
|
||||
}
|
||||
|
||||
uerr_t
|
||||
ftp_greeting (int csock)
|
||||
{
|
||||
uerr_t err = FTPOK;
|
||||
char *response = NULL;
|
||||
|
||||
err = ftp_response (csock, &response);
|
||||
if (err != FTPOK)
|
||||
goto bail;
|
||||
if (*response != '2')
|
||||
err = FTPSRVERR;
|
||||
|
||||
bail:
|
||||
if (response)
|
||||
xfree (response);
|
||||
return err;
|
||||
}
|
||||
/* Sends the USER and PASS commands to the server, to control
|
||||
connection socket csock. */
|
||||
uerr_t
|
||||
@@ -147,16 +161,6 @@ ftp_login (int csock, const char *acc, const char *pass)
|
||||
char *request, *respline;
|
||||
int nwritten;
|
||||
|
||||
/* Get greeting. */
|
||||
err = ftp_response (csock, &respline);
|
||||
if (err != FTPOK)
|
||||
return err;
|
||||
if (*respline != '2')
|
||||
{
|
||||
xfree (respline);
|
||||
return FTPSRVERR;
|
||||
}
|
||||
xfree (respline);
|
||||
/* Send USER username. */
|
||||
request = ftp_request ("USER", acc);
|
||||
nwritten = fd_write (csock, request, strlen (request), -1);
|
||||
@@ -194,7 +198,7 @@ ftp_login (int csock, const char *acc, const char *pass)
|
||||
for (i = 0; i < countof (skey_head); i++)
|
||||
{
|
||||
int l = strlen (skey_head[i]);
|
||||
if (0 == strncasecmp (skey_head[i], respline, l))
|
||||
if (0 == c_strncasecmp (skey_head[i], respline, l))
|
||||
{
|
||||
seed = respline + l;
|
||||
break;
|
||||
@@ -484,6 +488,119 @@ ftp_eprt (int csock, int *local_sock)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
/*
|
||||
* The following three functions defined into this #ifdef block
|
||||
* wrap the extended FTP commands defined in RFC 2228 (FTP Security Extensions).
|
||||
* Currently, only FTPS is supported, so these functions are only compiled when SSL
|
||||
* support is available, because there's no point in using FTPS when there's no SSL.
|
||||
* Shall someone add new secure FTP protocols in the future, feel free to remove this
|
||||
* #ifdef, or add new constants to it.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Sends an AUTH command as defined by RFC 2228,
|
||||
* deriving its argument from the scheme. For example, if the provided scheme
|
||||
* is SCHEME_FTPS, the command sent will be "AUTH TLS". Currently, this is the only
|
||||
* scheme supported, so this function will return FTPNOAUTH when supplied a different
|
||||
* one. It will also return FTPNOAUTH if the target server does not support FTPS.
|
||||
*/
|
||||
uerr_t
|
||||
ftp_auth (int csock, enum url_scheme scheme)
|
||||
{
|
||||
uerr_t err = 0;
|
||||
int written = 0;
|
||||
char *request = NULL, *response = NULL;
|
||||
|
||||
if (scheme == SCHEME_FTPS)
|
||||
{
|
||||
request = ftp_request ("AUTH", "TLS");
|
||||
written = fd_write (csock, request, strlen (request), -1);
|
||||
if (written < 0)
|
||||
{
|
||||
err = WRITEFAILED;
|
||||
goto bail;
|
||||
}
|
||||
err = ftp_response (csock, &response);
|
||||
if (err != FTPOK)
|
||||
goto bail;
|
||||
if (*response != '2')
|
||||
err = FTPNOAUTH;
|
||||
}
|
||||
else
|
||||
err = FTPNOAUTH;
|
||||
|
||||
bail:
|
||||
xfree (request);
|
||||
xfree (response);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
uerr_t
|
||||
ftp_pbsz (int csock, int pbsz)
|
||||
{
|
||||
uerr_t err = 0;
|
||||
int written = 0;
|
||||
char spbsz[5];
|
||||
char *request = NULL, *response = NULL;
|
||||
|
||||
snprintf (spbsz, 5, "%d", pbsz);
|
||||
request = ftp_request ("PBSZ", spbsz);
|
||||
written = fd_write (csock, request, strlen (request), -1);
|
||||
if (written < 0)
|
||||
{
|
||||
err = WRITEFAILED;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
err = ftp_response (csock, &response);
|
||||
if (err != FTPOK)
|
||||
goto bail;
|
||||
if (*response != '2')
|
||||
err = FTPNOPBSZ;
|
||||
|
||||
bail:
|
||||
xfree (request);
|
||||
xfree (response);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
uerr_t
|
||||
ftp_prot (int csock, enum prot_level prot)
|
||||
{
|
||||
uerr_t err = 0;
|
||||
int written = 0;
|
||||
char *request = NULL, *response = NULL;
|
||||
/* value must be a single character value */
|
||||
char value[2];
|
||||
|
||||
value[0] = prot;
|
||||
value[1] = '\0';
|
||||
|
||||
request = ftp_request ("PROT", value);
|
||||
written = fd_write (csock, request, strlen (request), -1);
|
||||
if (written < 0)
|
||||
{
|
||||
err = WRITEFAILED;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
err = ftp_response (csock, &response);
|
||||
if (err != FTPOK)
|
||||
goto bail;
|
||||
if (*response != '2')
|
||||
err = FTPNOPROT;
|
||||
|
||||
bail:
|
||||
xfree (request);
|
||||
xfree (response);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif /* HAVE_SSL */
|
||||
|
||||
/* Similar to ftp_port, but uses `PASV' to initiate the passive FTP
|
||||
transfer. Reads the response from server and parses it. Reads the
|
||||
host and port addresses and returns them. */
|
||||
@@ -788,16 +905,8 @@ ftp_epsv (int csock, ip_address *ip, int *port)
|
||||
}
|
||||
|
||||
/* Finally, get the port number */
|
||||
tport = 0;
|
||||
for (i = 1; c_isdigit (*s); s++)
|
||||
{
|
||||
if (i > 5)
|
||||
{
|
||||
xfree (respline);
|
||||
return FTPINVPASV;
|
||||
}
|
||||
for (tport = 0, i = 0; i < 5 && c_isdigit (*s); i++, s++)
|
||||
tport = (*s - '0') + 10 * tport;
|
||||
}
|
||||
|
||||
/* Make sure that the response terminates correcty */
|
||||
if (*s++ != delim)
|
||||
@@ -960,23 +1069,34 @@ ftp_retr (int csock, const char *file)
|
||||
/* Sends the LIST command to the server. If FILE is NULL, send just
|
||||
`LIST' (no space). */
|
||||
uerr_t
|
||||
ftp_list (int csock, const char *file, enum stype rs)
|
||||
ftp_list (int csock, const char *file, bool avoid_list_a, bool avoid_list,
|
||||
bool *list_a_used)
|
||||
{
|
||||
char *request, *respline;
|
||||
int nwritten;
|
||||
uerr_t err;
|
||||
bool ok = false;
|
||||
size_t i = 0;
|
||||
/* Try `LIST -a' first and revert to `LIST' in case of failure. */
|
||||
const char *list_commands[] = { "LIST -a",
|
||||
"LIST" };
|
||||
|
||||
/* 2008-01-29 SMS. For a VMS FTP server, where "LIST -a" may not
|
||||
fail, but will never do what is desired here, skip directly to the
|
||||
simple "LIST" command (assumed to be the last one in the list).
|
||||
*/
|
||||
if (rs == ST_VMS)
|
||||
i = countof (list_commands)- 1;
|
||||
/* 2013-10-12 Andrea Urbani (matfanjol)
|
||||
For more information about LIST and "LIST -a" please look at ftp.c,
|
||||
function getftp, text "__LIST_A_EXPLANATION__".
|
||||
|
||||
If somebody changes the following commands, please, checks also the
|
||||
later "i" variable. */
|
||||
static const char *list_commands[] = {
|
||||
"LIST -a",
|
||||
"LIST"
|
||||
};
|
||||
|
||||
*list_a_used = false;
|
||||
|
||||
if (avoid_list_a)
|
||||
{
|
||||
i = countof (list_commands)- 1;
|
||||
DEBUGP (("(skipping \"LIST -a\")"));
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
/* Send request. */
|
||||
@@ -1000,6 +1120,8 @@ ftp_list (int csock, const char *file, enum stype rs)
|
||||
{
|
||||
err = FTPOK;
|
||||
ok = true;
|
||||
/* Which list command was used? */
|
||||
*list_a_used = (i == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1008,6 +1130,12 @@ ftp_list (int csock, const char *file, enum stype rs)
|
||||
xfree (respline);
|
||||
}
|
||||
++i;
|
||||
if ((avoid_list) && (i == 1))
|
||||
{
|
||||
/* I skip LIST */
|
||||
++i;
|
||||
DEBUGP (("(skipping \"LIST\")"));
|
||||
}
|
||||
} while (i < countof (list_commands) && !ok);
|
||||
|
||||
return err;
|
||||
@@ -1015,11 +1143,12 @@ ftp_list (int csock, const char *file, enum stype rs)
|
||||
|
||||
/* Sends the SYST command to the server. */
|
||||
uerr_t
|
||||
ftp_syst (int csock, enum stype *server_type)
|
||||
ftp_syst (int csock, enum stype *server_type, enum ustype *unix_type)
|
||||
{
|
||||
char *request, *respline;
|
||||
int nwritten;
|
||||
uerr_t err;
|
||||
char *ftp_last_respline;
|
||||
|
||||
/* Send SYST request. */
|
||||
request = ftp_request ("SYST", NULL);
|
||||
@@ -1041,6 +1170,8 @@ ftp_syst (int csock, enum stype *server_type)
|
||||
return FTPSRVERR;
|
||||
}
|
||||
|
||||
ftp_last_respline = strdup (respline);
|
||||
|
||||
/* Skip the number (215, but 200 (!!!) in case of VMS) */
|
||||
strtok (respline, " ");
|
||||
|
||||
@@ -1048,22 +1179,34 @@ ftp_syst (int csock, enum stype *server_type)
|
||||
first word of the server response)? */
|
||||
request = strtok (NULL, " ");
|
||||
|
||||
*unix_type = UST_OTHER;
|
||||
|
||||
if (request == NULL)
|
||||
*server_type = ST_OTHER;
|
||||
else if (!strcasecmp (request, "VMS"))
|
||||
else if (!c_strcasecmp (request, "VMS"))
|
||||
*server_type = ST_VMS;
|
||||
else if (!strcasecmp (request, "UNIX"))
|
||||
*server_type = ST_UNIX;
|
||||
else if (!strcasecmp (request, "WINDOWS_NT")
|
||||
|| !strcasecmp (request, "WINDOWS2000"))
|
||||
else if (!c_strcasecmp (request, "UNIX"))
|
||||
{
|
||||
*server_type = ST_UNIX;
|
||||
/* 2013-10-17 Andrea Urbani (matfanjol)
|
||||
I check more in depth the system type */
|
||||
if (!c_strncasecmp (ftp_last_respline, "215 UNIX Type: L8", 17))
|
||||
*unix_type = UST_TYPE_L8;
|
||||
else if (!c_strncasecmp (ftp_last_respline,
|
||||
"215 UNIX MultiNet Unix Emulation V5.3(93)", 41))
|
||||
*unix_type = UST_MULTINET;
|
||||
}
|
||||
else if (!c_strcasecmp (request, "WINDOWS_NT")
|
||||
|| !c_strcasecmp (request, "WINDOWS2000"))
|
||||
*server_type = ST_WINNT;
|
||||
else if (!strcasecmp (request, "MACOS"))
|
||||
else if (!c_strcasecmp (request, "MACOS"))
|
||||
*server_type = ST_MACOS;
|
||||
else if (!strcasecmp (request, "OS/400"))
|
||||
else if (!c_strcasecmp (request, "OS/400"))
|
||||
*server_type = ST_OS400;
|
||||
else
|
||||
*server_type = ST_OTHER;
|
||||
|
||||
xfree (ftp_last_respline);
|
||||
xfree (respline);
|
||||
/* All OK. */
|
||||
return FTPOK;
|
||||
@@ -1107,7 +1250,7 @@ ftp_pwd (int csock, char **pwd)
|
||||
goto err;
|
||||
|
||||
/* Has the `pwd' been already allocated? Free! */
|
||||
xfree_null (*pwd);
|
||||
xfree (*pwd);
|
||||
|
||||
*pwd = xstrdup (request);
|
||||
|
||||
|
||||
207
src/ftp-ls.c
207
src/ftp-ls.c
@@ -1,7 +1,7 @@
|
||||
/* Parsing FTP `ls' output.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -42,6 +42,7 @@ as that of the covered work. */
|
||||
#include "url.h"
|
||||
#include "convert.h" /* for html_quote_string prototype */
|
||||
#include "retr.h" /* for output_stream */
|
||||
#include "c-strcase.h"
|
||||
|
||||
/* Converts symbolic permissions to number-style ones, e.g. string
|
||||
rwxr-xr-x to 755. For now, it knows nothing of
|
||||
@@ -68,16 +69,17 @@ symperms (const char *s)
|
||||
replaces all <TAB> character with <SPACE>. Returns the length of the
|
||||
modified line. */
|
||||
static int
|
||||
clean_line(char *line)
|
||||
clean_line (char *line, int len)
|
||||
{
|
||||
int len = strlen (line);
|
||||
if (!len) return 0;
|
||||
if (line[len - 1] == '\n')
|
||||
if (len <= 0) return 0;
|
||||
|
||||
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
|
||||
line[--len] = '\0';
|
||||
|
||||
if (!len) return 0;
|
||||
if (line[len - 1] == '\r')
|
||||
line[--len] = '\0';
|
||||
|
||||
for ( ; *line ; line++ ) if (*line == '\t') *line = ' ';
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -102,9 +104,10 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
||||
int hour, min, sec, ptype;
|
||||
struct tm timestruct, *tnow;
|
||||
time_t timenow;
|
||||
size_t bufsize = 0;
|
||||
|
||||
char *line, *tok, *ptok; /* tokenizer */
|
||||
struct fileinfo *dir, *l, cur; /* list creation */
|
||||
char *line = NULL, *tok, *ptok; /* tokenizer */
|
||||
struct fileinfo *dir, *l, cur; /* list creation */
|
||||
|
||||
fp = fopen (file, "rb");
|
||||
if (!fp)
|
||||
@@ -115,22 +118,16 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
||||
dir = l = NULL;
|
||||
|
||||
/* Line loop to end of file: */
|
||||
while ((line = read_whole_line (fp)) != NULL)
|
||||
while ((len = getline (&line, &bufsize, fp)) > 0)
|
||||
{
|
||||
len = clean_line (line);
|
||||
len = clean_line (line, len);
|
||||
/* Skip if total... */
|
||||
if (!strncasecmp (line, "total", 5))
|
||||
{
|
||||
xfree (line);
|
||||
continue;
|
||||
}
|
||||
if (!c_strncasecmp (line, "total", 5))
|
||||
continue;
|
||||
/* Get the first token (permissions). */
|
||||
tok = strtok (line, " ");
|
||||
if (!tok)
|
||||
{
|
||||
xfree (line);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
|
||||
cur.name = NULL;
|
||||
cur.linkto = NULL;
|
||||
@@ -203,7 +200,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
||||
if (next < 0) /* a month name was not encountered */
|
||||
{
|
||||
for (i = 0; i < 12; i++)
|
||||
if (!strcmp (tok, months[i]))
|
||||
if (!c_strcasecmp (tok, months[i]))
|
||||
break;
|
||||
/* If we got a month, it means the token before it is the
|
||||
size, and the filename is three tokens away. */
|
||||
@@ -366,9 +363,8 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
||||
if (error || ignore)
|
||||
{
|
||||
DEBUGP (("Skipping.\n"));
|
||||
xfree_null (cur.name);
|
||||
xfree_null (cur.linkto);
|
||||
xfree (line);
|
||||
xfree (cur.name);
|
||||
xfree (cur.linkto);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -416,10 +412,9 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
||||
timestruct.tm_isdst = -1;
|
||||
l->tstamp = mktime (×truct); /* store the time-stamp */
|
||||
l->ptype = ptype;
|
||||
|
||||
xfree (line);
|
||||
}
|
||||
|
||||
xfree (line);
|
||||
fclose (fp);
|
||||
return dir;
|
||||
}
|
||||
@@ -431,9 +426,11 @@ ftp_parse_winnt_ls (const char *file)
|
||||
int len;
|
||||
int year, month, day; /* for time analysis */
|
||||
int hour, min;
|
||||
size_t bufsize = 0;
|
||||
struct tm timestruct;
|
||||
|
||||
char *line, *tok; /* tokenizer */
|
||||
char *line = NULL, *tok; /* tokenizer */
|
||||
char *filename;
|
||||
struct fileinfo *dir, *l, cur; /* list creation */
|
||||
|
||||
fp = fopen (file, "rb");
|
||||
@@ -445,43 +442,53 @@ ftp_parse_winnt_ls (const char *file)
|
||||
dir = l = NULL;
|
||||
|
||||
/* Line loop to end of file: */
|
||||
while ((line = read_whole_line (fp)) != NULL)
|
||||
while ((len = getline (&line, &bufsize, fp)) > 0)
|
||||
{
|
||||
len = clean_line (line);
|
||||
len = clean_line (line, len);
|
||||
|
||||
/* Extracting name is a bit of black magic and we have to do it
|
||||
before `strtok' inserted extra \0 characters in the line
|
||||
string. For the moment let us just suppose that the name starts at
|
||||
column 39 of the listing. This way we could also recognize
|
||||
filenames that begin with a series of space characters (but who
|
||||
really wants to use such filenames anyway?). */
|
||||
if (len < 40) goto continue_loop;
|
||||
tok = line + 39;
|
||||
cur.name = xstrdup(tok);
|
||||
DEBUGP (("Name: '%s'\n", cur.name));
|
||||
/* Name begins at 39 column of the listing if date presented in `mm-dd-yy'
|
||||
format or at 41 column if date presented in `mm-dd-yyyy' format. Thus,
|
||||
we cannot extract name before we parse date. Using this information we
|
||||
also can recognize filenames that begin with a series of space
|
||||
characters (but who really wants to use such filenames anyway?). */
|
||||
if (len < 40) continue;
|
||||
filename = line + 39;
|
||||
|
||||
/* First column: mm-dd-yy. Should atoi() on the month fail, january
|
||||
will be assumed. */
|
||||
/* First column: mm-dd-yy or mm-dd-yyyy. Should atoi() on the month fail,
|
||||
january will be assumed. */
|
||||
tok = strtok(line, "-");
|
||||
if (tok == NULL) goto continue_loop;
|
||||
if (tok == NULL) continue;
|
||||
month = atoi(tok) - 1;
|
||||
if (month < 0) month = 0;
|
||||
tok = strtok(NULL, "-");
|
||||
if (tok == NULL) goto continue_loop;
|
||||
if (tok == NULL) continue;
|
||||
day = atoi(tok);
|
||||
tok = strtok(NULL, " ");
|
||||
if (tok == NULL) goto continue_loop;
|
||||
if (tok == NULL) continue;
|
||||
year = atoi(tok);
|
||||
/* Assuming the epoch starting at 1.1.1970 */
|
||||
if (year <= 70) year += 100;
|
||||
if (year <= 70)
|
||||
{
|
||||
year += 100;
|
||||
}
|
||||
else if (year >= 1900)
|
||||
{
|
||||
year -= 1900;
|
||||
filename += 2;
|
||||
}
|
||||
/* Now it is possible to determine the position of the first symbol in
|
||||
filename. */
|
||||
cur.name = xstrdup(filename);
|
||||
DEBUGP (("Name: '%s'\n", cur.name));
|
||||
|
||||
|
||||
/* Second column: hh:mm[AP]M, listing does not contain value for
|
||||
seconds */
|
||||
tok = strtok(NULL, ":");
|
||||
if (tok == NULL) goto continue_loop;
|
||||
if (tok == NULL) continue;
|
||||
hour = atoi(tok);
|
||||
tok = strtok(NULL, "M");
|
||||
if (tok == NULL) goto continue_loop;
|
||||
if (tok == NULL) continue;
|
||||
min = atoi(tok);
|
||||
/* Adjust hour from AM/PM. Just for the record, the sequence goes
|
||||
11:00AM, 12:00PM, 01:00PM ... 11:00PM, 12:00AM, 01:00AM . */
|
||||
@@ -512,9 +519,9 @@ ftp_parse_winnt_ls (const char *file)
|
||||
directories as the listing does not give us a clue) and filetype
|
||||
here. */
|
||||
tok = strtok(NULL, " ");
|
||||
if (tok == NULL) goto continue_loop;
|
||||
if (tok == NULL) continue;
|
||||
while ((tok != NULL) && (*tok == '\0')) tok = strtok(NULL, " ");
|
||||
if (tok == NULL) goto continue_loop;
|
||||
if (tok == NULL) continue;
|
||||
if (*tok == '<')
|
||||
{
|
||||
cur.type = FT_DIRECTORY;
|
||||
@@ -553,11 +560,9 @@ ftp_parse_winnt_ls (const char *file)
|
||||
memcpy (l, &cur, sizeof (cur));
|
||||
l->next = NULL;
|
||||
}
|
||||
|
||||
continue_loop:
|
||||
xfree (line);
|
||||
}
|
||||
|
||||
xfree (line);
|
||||
fclose(fp);
|
||||
return dir;
|
||||
}
|
||||
@@ -678,11 +683,12 @@ ftp_parse_vms_ls (const char *file)
|
||||
FILE *fp;
|
||||
int dt, i, j, len;
|
||||
int perms;
|
||||
size_t bufsize = 0;
|
||||
time_t timenow;
|
||||
struct tm *timestruct;
|
||||
char date_str[ 32];
|
||||
|
||||
char *line, *tok; /* tokenizer */
|
||||
char *line = NULL, *tok; /* tokenizer */
|
||||
struct fileinfo *dir, *l, cur; /* list creation */
|
||||
|
||||
fp = fopen (file, "r");
|
||||
@@ -695,52 +701,34 @@ ftp_parse_vms_ls (const char *file)
|
||||
|
||||
/* Skip blank lines, Directory heading, and more blank lines. */
|
||||
|
||||
j = 0; /* Expecting initial blank line(s). */
|
||||
while (1)
|
||||
for (j = 0; (i = getline (&line, &bufsize, fp)) > 0; )
|
||||
{
|
||||
line = read_whole_line (fp);
|
||||
if (line == NULL)
|
||||
i = clean_line (line, i);
|
||||
if (i <= 0)
|
||||
continue; /* Ignore blank line. */
|
||||
|
||||
if ((j == 0) && (line[i - 1] == ']'))
|
||||
{
|
||||
break;
|
||||
/* Found Directory heading line. Next non-blank line
|
||||
is significant. */
|
||||
j = 1;
|
||||
}
|
||||
else if (!strncmp (line, "Total of ", 9))
|
||||
{
|
||||
/* Found "Total of ..." footing line. No valid data
|
||||
will follow (empty directory). */
|
||||
i = 0; /* Arrange for early exit. */
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = clean_line (line);
|
||||
if (i <= 0)
|
||||
{
|
||||
xfree (line); /* Free useless line storage. */
|
||||
continue; /* Blank line. Keep looking. */
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((j == 0) && (line[ i- 1] == ']'))
|
||||
{
|
||||
/* Found Directory heading line. Next non-blank line
|
||||
is significant.
|
||||
*/
|
||||
j = 1;
|
||||
}
|
||||
else if (!strncmp (line, "Total of ", 9))
|
||||
{
|
||||
/* Found "Total of ..." footing line. No valid data
|
||||
will follow (empty directory).
|
||||
*/
|
||||
xfree (line); /* Free useless line storage. */
|
||||
line = NULL; /* Arrange for early exit. */
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break; /* Must be significant data. */
|
||||
}
|
||||
}
|
||||
xfree (line); /* Free useless line storage. */
|
||||
break; /* Must be significant data. */
|
||||
}
|
||||
}
|
||||
|
||||
/* Read remainder of file until the next blank line or EOF. */
|
||||
|
||||
while (line != NULL)
|
||||
while (i > 0)
|
||||
{
|
||||
char *p;
|
||||
|
||||
@@ -788,14 +776,14 @@ ftp_parse_vms_ls (const char *file)
|
||||
what will work in a CWD command.
|
||||
*/
|
||||
len = strlen (tok);
|
||||
if (!strncasecmp((tok + (len - 4)), ".DIR", 4))
|
||||
if (!c_strncasecmp((tok + (len - 4)), ".DIR", 4))
|
||||
{
|
||||
*(tok+ (len - 4)) = '\0'; /* Discard ".DIR". */
|
||||
cur.type = FT_DIRECTORY;
|
||||
cur.perms = VMS_DEFAULT_PROT_DIR;
|
||||
DEBUGP (("Directory (nv)\n"));
|
||||
}
|
||||
else if (!strncasecmp ((tok + (len - 6)), ".DIR;1", 6))
|
||||
else if (!c_strncasecmp ((tok + (len - 6)), ".DIR;1", 6))
|
||||
{
|
||||
*(tok+ (len - 6)) = '\0'; /* Discard ".DIR;1". */
|
||||
cur.type = FT_DIRECTORY;
|
||||
@@ -831,9 +819,8 @@ ftp_parse_vms_ls (const char *file)
|
||||
if (tok == NULL)
|
||||
{
|
||||
DEBUGP (("Getting additional line.\n"));
|
||||
xfree (line);
|
||||
line = read_whole_line (fp);
|
||||
if (!line)
|
||||
i = getline (&line, &bufsize, fp);
|
||||
if (i <= 0)
|
||||
{
|
||||
DEBUGP (("EOF. Leaving listing parser.\n"));
|
||||
break;
|
||||
@@ -842,14 +829,14 @@ ftp_parse_vms_ls (const char *file)
|
||||
/* Second line must begin with " ". Otherwise, it's a first
|
||||
line (and we may be confused).
|
||||
*/
|
||||
i = clean_line (line, i);
|
||||
if (i <= 0)
|
||||
{
|
||||
/* Blank line. End of significant file listing. */
|
||||
DEBUGP (("Blank line. Leaving listing parser.\n"));
|
||||
xfree (line); /* Free useless line storage. */
|
||||
break;
|
||||
}
|
||||
else if (line[ 0] != ' ')
|
||||
else if (line[0] != ' ')
|
||||
{
|
||||
DEBUGP (("Non-blank in column 1. Must be a new file name?\n"));
|
||||
continue;
|
||||
@@ -861,7 +848,6 @@ ftp_parse_vms_ls (const char *file)
|
||||
{
|
||||
/* Unexpected non-empty but apparently blank line. */
|
||||
DEBUGP (("Null token. Leaving listing parser.\n"));
|
||||
xfree (line); /* Free useless line storage. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -900,7 +886,7 @@ ftp_parse_vms_ls (const char *file)
|
||||
(sizeof( date_str)- strlen (date_str) - 1));
|
||||
DEBUGP (("Date time: >%s<\n", date_str));
|
||||
}
|
||||
else if (strchr ( tok, '[') != NULL)
|
||||
else if (strchr (tok, '[') != NULL)
|
||||
{
|
||||
/* Owner. (Ignore.) */
|
||||
DEBUGP (("Owner.\n"));
|
||||
@@ -910,7 +896,8 @@ ftp_parse_vms_ls (const char *file)
|
||||
/* Protections (permissions). */
|
||||
perms = 0;
|
||||
j = 0;
|
||||
for (i = 0; i < strlen( tok); i++)
|
||||
/*FIXME: Should not be using the variable like this. */
|
||||
for (i = 0; i < (int) strlen(tok); i++)
|
||||
{
|
||||
switch (tok[ i])
|
||||
{
|
||||
@@ -1004,21 +991,19 @@ ftp_parse_vms_ls (const char *file)
|
||||
l->next = NULL;
|
||||
}
|
||||
|
||||
/* Free old line storage. Read a new line. */
|
||||
xfree (line);
|
||||
line = read_whole_line (fp);
|
||||
if (line != NULL)
|
||||
i = getline (&line, &bufsize, fp);
|
||||
if (i > 0)
|
||||
{
|
||||
i = clean_line (line);
|
||||
i = clean_line (line, i);
|
||||
if (i <= 0)
|
||||
{
|
||||
{
|
||||
/* Blank line. End of significant file listing. */
|
||||
xfree (line); /* Free useless line storage. */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xfree (line);
|
||||
fclose (fp);
|
||||
return dir;
|
||||
}
|
||||
@@ -1067,7 +1052,7 @@ Unsupported listing type, trying Unix listing parser.\n"));
|
||||
return ftp_parse_unix_ls (file, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Stuff for creating FTP index. */
|
||||
|
||||
/* The function creates an HTML index containing references to given
|
||||
@@ -1104,7 +1089,7 @@ ftp_index (const char *file, struct url *u, struct fileinfo *f)
|
||||
else
|
||||
upwd = concat_strings (tmpu, "@", (char *) 0);
|
||||
xfree (tmpu);
|
||||
xfree_null (tmpp);
|
||||
xfree (tmpp);
|
||||
}
|
||||
else
|
||||
upwd = xstrdup ("");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Opie (s/key) support for FTP.
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
2007, 2008, 2009, 2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
|
||||
91
src/ftp.h
91
src/ftp.h
@@ -1,7 +1,7 @@
|
||||
/* Declarations for FTP support.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -33,6 +33,7 @@ as that of the covered work. */
|
||||
#define FTP_H
|
||||
|
||||
#include "host.h"
|
||||
#include "url.h"
|
||||
|
||||
/* System types. */
|
||||
enum stype
|
||||
@@ -45,12 +46,35 @@ enum stype
|
||||
ST_OTHER
|
||||
};
|
||||
|
||||
extern char ftp_last_respline[];
|
||||
/* Extensions of the ST_UNIX */
|
||||
enum ustype
|
||||
{
|
||||
UST_TYPE_L8,
|
||||
UST_MULTINET,
|
||||
UST_OTHER
|
||||
};
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
/* Data channel protection levels (to be used with PBSZ) */
|
||||
enum prot_level
|
||||
{
|
||||
PROT_CLEAR = 'C',
|
||||
PROT_SAFE = 'S',
|
||||
PROT_CONFIDENTIAL = 'E',
|
||||
PROT_PRIVATE = 'P'
|
||||
};
|
||||
#endif
|
||||
|
||||
uerr_t ftp_response (int, char **);
|
||||
uerr_t ftp_greeting (int);
|
||||
uerr_t ftp_login (int, const char *, const char *);
|
||||
uerr_t ftp_port (int, int *);
|
||||
uerr_t ftp_pasv (int, ip_address *, int *);
|
||||
#ifdef HAVE_SSL
|
||||
uerr_t ftp_auth (int, enum url_scheme);
|
||||
uerr_t ftp_pbsz (int, int);
|
||||
uerr_t ftp_prot (int, enum prot_level);
|
||||
#endif
|
||||
#ifdef ENABLE_IPV6
|
||||
uerr_t ftp_lprt (int, int *);
|
||||
uerr_t ftp_lpsv (int, ip_address *, int *);
|
||||
@@ -61,8 +85,8 @@ uerr_t ftp_type (int, int);
|
||||
uerr_t ftp_cwd (int, const char *);
|
||||
uerr_t ftp_retr (int, const char *);
|
||||
uerr_t ftp_rest (int, wgint);
|
||||
uerr_t ftp_list (int, const char *, enum stype);
|
||||
uerr_t ftp_syst (int, enum stype *);
|
||||
uerr_t ftp_list (int, const char *, bool, bool, bool *);
|
||||
uerr_t ftp_syst (int, enum stype *, enum ustype *);
|
||||
uerr_t ftp_pwd (int, char **);
|
||||
uerr_t ftp_size (int, const char *, wgint *);
|
||||
|
||||
@@ -98,38 +122,55 @@ enum parsetype
|
||||
/* Information about one filename in a linked list. */
|
||||
struct fileinfo
|
||||
{
|
||||
enum ftype type; /* file type */
|
||||
char *name; /* file name */
|
||||
wgint size; /* file size */
|
||||
long tstamp; /* time-stamp */
|
||||
enum parsetype ptype; /* time parsing */
|
||||
int perms; /* file permissions */
|
||||
char *linkto; /* link to which file points */
|
||||
struct fileinfo *prev; /* previous... */
|
||||
struct fileinfo *next; /* ...and next structure. */
|
||||
enum ftype type; /* file type */
|
||||
char *name; /* file name */
|
||||
wgint size; /* file size */
|
||||
long tstamp; /* time-stamp */
|
||||
enum parsetype ptype; /* time parsing */
|
||||
int perms; /* file permissions */
|
||||
char *linkto; /* link to which file points */
|
||||
struct fileinfo *prev; /* previous... */
|
||||
struct fileinfo *next; /* ...and next structure. */
|
||||
};
|
||||
|
||||
/* Commands for FTP functions. */
|
||||
enum wget_ftp_command
|
||||
{
|
||||
DO_LOGIN = 0x0001, /* Connect and login to the server. */
|
||||
DO_CWD = 0x0002, /* Change current directory. */
|
||||
DO_RETR = 0x0004, /* Retrieve the file. */
|
||||
DO_LIST = 0x0008, /* Retrieve the directory list. */
|
||||
LEAVE_PENDING = 0x0010 /* Do not close the socket. */
|
||||
DO_LOGIN = 0x0001, /* Connect and login to the server. */
|
||||
DO_CWD = 0x0002, /* Change current directory. */
|
||||
DO_RETR = 0x0004, /* Retrieve the file. */
|
||||
DO_LIST = 0x0008, /* Retrieve the directory list. */
|
||||
LEAVE_PENDING = 0x0010 /* Do not close the socket. */
|
||||
};
|
||||
|
||||
enum wget_ftp_fstatus
|
||||
{
|
||||
NOTHING = 0x0000, /* Nothing done yet. */
|
||||
ON_YOUR_OWN = 0x0001, /* The ftp_loop_internal sets the
|
||||
defaults. */
|
||||
DONE_CWD = 0x0002 /* The current working directory is
|
||||
correct. */
|
||||
NOTHING = 0x0000, /* Nothing done yet. */
|
||||
ON_YOUR_OWN = 0x0001, /* The ftp_loop_internal sets the
|
||||
defaults. */
|
||||
DONE_CWD = 0x0002, /* The current working directory is
|
||||
correct. */
|
||||
|
||||
/* 2013-10-17 Andrea Urbani (matfanjol)
|
||||
For more information about the following entries, please,
|
||||
look at ftp.c, function getftp, text "__LIST_A_EXPLANATION__". */
|
||||
AVOID_LIST_A = 0x0004, /* It tells us if during this
|
||||
session we have to avoid the use
|
||||
of "LIST -a".*/
|
||||
AVOID_LIST = 0x0008, /* It tells us if during this
|
||||
session we have to avoid to use
|
||||
"LIST". */
|
||||
LIST_AFTER_LIST_A_CHECK_DONE = 0x0010,
|
||||
/* It tells us if we have already
|
||||
checked "LIST" after the first
|
||||
"LIST -a" to handle the case of
|
||||
file/folders named "-a". */
|
||||
DATA_CHANNEL_SECURITY = 0x0020 /* Establish a secure data channel */
|
||||
};
|
||||
|
||||
struct fileinfo *ftp_parse_ls (const char *, const enum stype);
|
||||
uerr_t ftp_loop (struct url *, char **, int *, struct url *, bool, bool);
|
||||
uerr_t ftp_loop (struct url *, struct url *, char **, int *, struct url *,
|
||||
bool, bool);
|
||||
|
||||
uerr_t ftp_index (const char *, struct url *, struct fileinfo *);
|
||||
|
||||
|
||||
272
src/gettext.h
272
src/gettext.h
@@ -1,272 +0,0 @@
|
||||
/* Convenience header for conditional use of GNU <libintl.h>.
|
||||
Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004, 2005,
|
||||
2006, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
USA. */
|
||||
|
||||
#ifndef _LIBGETTEXT_H
|
||||
#define _LIBGETTEXT_H 1
|
||||
|
||||
/* NLS can be disabled through the configure --disable-nls option. */
|
||||
#if ENABLE_NLS
|
||||
|
||||
/* Get declarations of GNU message catalog functions. */
|
||||
# include <libintl.h>
|
||||
|
||||
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
|
||||
the gettext() and ngettext() macros. This is an alternative to calling
|
||||
textdomain(), and is useful for libraries. */
|
||||
# ifdef DEFAULT_TEXT_DOMAIN
|
||||
# undef gettext
|
||||
# define gettext(Msgid) \
|
||||
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
|
||||
# undef ngettext
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
|
||||
chokes if dcgettext is defined as a macro. So include it now, to make
|
||||
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
|
||||
as well because people using "gettext.h" will not include <libintl.h>,
|
||||
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
|
||||
is OK. */
|
||||
#if defined(__sun)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
|
||||
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
|
||||
it now, to make later inclusions of <libintl.h> a NOP. */
|
||||
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
|
||||
# include <cstdlib>
|
||||
# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Disabled NLS.
|
||||
The casts to 'const char *' serve the purpose of producing warnings
|
||||
for invalid uses of the value returned from these functions.
|
||||
On pre-ANSI systems without 'const', the config.h file is supposed to
|
||||
contain "#define const". */
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
|
||||
# define dcgettext(Domainname, Msgid, Category) \
|
||||
((void) (Category), dgettext (Domainname, Msgid))
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
((N) == 1 \
|
||||
? ((void) (Msgid2), (const char *) (Msgid1)) \
|
||||
: ((void) (Msgid1), (const char *) (Msgid2)))
|
||||
# define dngettext(Domainname, Msgid1, Msgid2, N) \
|
||||
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
|
||||
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
|
||||
((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
|
||||
# define textdomain(Domainname) ((const char *) (Domainname))
|
||||
# define bindtextdomain(Domainname, Dirname) \
|
||||
((void) (Domainname), (const char *) (Dirname))
|
||||
# define bind_textdomain_codeset(Domainname, Codeset) \
|
||||
((void) (Domainname), (const char *) (Codeset))
|
||||
|
||||
#endif
|
||||
|
||||
/* A pseudo function call that serves as a marker for the automated
|
||||
extraction of messages, but does not call gettext(). The run-time
|
||||
translation is done at a different place in the code.
|
||||
The argument, String, should be a literal string. Concatenated strings
|
||||
and other string expressions won't work.
|
||||
The macro's expansion is not parenthesized, so that it is suitable as
|
||||
initializer for static 'char[]' or 'const char[]' variables. */
|
||||
#define gettext_noop(String) String
|
||||
|
||||
/* The separator between msgctxt and msgid in a .mo file. */
|
||||
#define GETTEXT_CONTEXT_GLUE "\004"
|
||||
|
||||
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
|
||||
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
|
||||
short and rarely need to change.
|
||||
The letter 'p' stands for 'particular' or 'special'. */
|
||||
#ifdef DEFAULT_TEXT_DOMAIN
|
||||
# define pgettext(Msgctxt, Msgid) \
|
||||
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
||||
#else
|
||||
# define pgettext(Msgctxt, Msgid) \
|
||||
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
||||
#endif
|
||||
#define dpgettext(Domainname, Msgctxt, Msgid) \
|
||||
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
||||
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
|
||||
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
|
||||
#ifdef DEFAULT_TEXT_DOMAIN
|
||||
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
|
||||
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#else
|
||||
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
|
||||
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#endif
|
||||
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
|
||||
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
|
||||
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
|
||||
|
||||
#ifdef __GNUC__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
pgettext_aux (const char *domain,
|
||||
const char *msg_ctxt_id, const char *msgid,
|
||||
int category)
|
||||
{
|
||||
const char *translation = dcgettext (domain, msg_ctxt_id, category);
|
||||
if (translation == msg_ctxt_id)
|
||||
return msgid;
|
||||
else
|
||||
return translation;
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
npgettext_aux (const char *domain,
|
||||
const char *msg_ctxt_id, const char *msgid,
|
||||
const char *msgid_plural, unsigned long int n,
|
||||
int category)
|
||||
{
|
||||
const char *translation =
|
||||
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
|
||||
if (translation == msg_ctxt_id || translation == msgid_plural)
|
||||
return (n == 1 ? msgid : msgid_plural);
|
||||
else
|
||||
return translation;
|
||||
}
|
||||
|
||||
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
|
||||
can be arbitrary expressions. But for string literals these macros are
|
||||
less efficient than those above. */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
|
||||
(((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
|
||||
/* || __STDC_VERSION__ >= 199901L */ )
|
||||
|
||||
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define pgettext_expr(Msgctxt, Msgid) \
|
||||
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
|
||||
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
|
||||
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
|
||||
|
||||
#ifdef __GNUC__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
dcpgettext_expr (const char *domain,
|
||||
const char *msgctxt, const char *msgid,
|
||||
int category)
|
||||
{
|
||||
size_t msgctxt_len = strlen (msgctxt) + 1;
|
||||
size_t msgid_len = strlen (msgid) + 1;
|
||||
const char *translation;
|
||||
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
char msg_ctxt_id[msgctxt_len + msgid_len];
|
||||
#else
|
||||
char buf[1024];
|
||||
char *msg_ctxt_id =
|
||||
(msgctxt_len + msgid_len <= sizeof (buf)
|
||||
? buf
|
||||
: (char *) malloc (msgctxt_len + msgid_len));
|
||||
if (msg_ctxt_id != NULL)
|
||||
#endif
|
||||
{
|
||||
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
|
||||
msg_ctxt_id[msgctxt_len - 1] = '\004';
|
||||
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
|
||||
translation = dcgettext (domain, msg_ctxt_id, category);
|
||||
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
if (msg_ctxt_id != buf)
|
||||
free (msg_ctxt_id);
|
||||
#endif
|
||||
if (translation != msg_ctxt_id)
|
||||
return translation;
|
||||
}
|
||||
return msgid;
|
||||
}
|
||||
|
||||
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
|
||||
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
|
||||
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
|
||||
|
||||
#ifdef __GNUC__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static const char *
|
||||
dcnpgettext_expr (const char *domain,
|
||||
const char *msgctxt, const char *msgid,
|
||||
const char *msgid_plural, unsigned long int n,
|
||||
int category)
|
||||
{
|
||||
size_t msgctxt_len = strlen (msgctxt) + 1;
|
||||
size_t msgid_len = strlen (msgid) + 1;
|
||||
const char *translation;
|
||||
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
char msg_ctxt_id[msgctxt_len + msgid_len];
|
||||
#else
|
||||
char buf[1024];
|
||||
char *msg_ctxt_id =
|
||||
(msgctxt_len + msgid_len <= sizeof (buf)
|
||||
? buf
|
||||
: (char *) malloc (msgctxt_len + msgid_len));
|
||||
if (msg_ctxt_id != NULL)
|
||||
#endif
|
||||
{
|
||||
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
|
||||
msg_ctxt_id[msgctxt_len - 1] = '\004';
|
||||
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
|
||||
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
|
||||
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
||||
if (msg_ctxt_id != buf)
|
||||
free (msg_ctxt_id);
|
||||
#endif
|
||||
if (!(translation == msg_ctxt_id || translation == msgid_plural))
|
||||
return translation;
|
||||
}
|
||||
return (n == 1 ? msgid : msgid_plural);
|
||||
}
|
||||
|
||||
#endif /* _LIBGETTEXT_H */
|
||||
470
src/gnutls.c
470
src/gnutls.c
@@ -1,6 +1,6 @@
|
||||
/* SSL support via GnuTLS library.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2015
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -30,14 +30,15 @@ as that of the covered work. */
|
||||
|
||||
#include "wget.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
#include <gnutls/abstract.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
#include <gnutls/x509.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -46,6 +47,7 @@ as that of the covered work. */
|
||||
#include "connect.h"
|
||||
#include "url.h"
|
||||
#include "ptimer.h"
|
||||
#include "hash.h"
|
||||
#include "ssl.h"
|
||||
|
||||
#include <sys/fcntl.h>
|
||||
@@ -56,6 +58,9 @@ as that of the covered work. */
|
||||
|
||||
#include "host.h"
|
||||
|
||||
static int
|
||||
_do_handshake (gnutls_session_t session, int fd, double timeout);
|
||||
|
||||
static int
|
||||
key_type_to_gnutls_type (enum keyfile_type type)
|
||||
{
|
||||
@@ -81,59 +86,116 @@ ssl_init (void)
|
||||
{
|
||||
/* Becomes true if GnuTLS is initialized. */
|
||||
static bool ssl_initialized = false;
|
||||
const char *ca_directory;
|
||||
DIR *dir;
|
||||
int ncerts = -1;
|
||||
|
||||
/* GnuTLS should be initialized only once. */
|
||||
if (ssl_initialized)
|
||||
return true;
|
||||
|
||||
const char *ca_directory;
|
||||
DIR *dir;
|
||||
|
||||
gnutls_global_init ();
|
||||
gnutls_certificate_allocate_credentials (&credentials);
|
||||
gnutls_certificate_set_verify_flags(credentials,
|
||||
GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
|
||||
gnutls_certificate_set_verify_flags (credentials,
|
||||
GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
|
||||
|
||||
ca_directory = opt.ca_directory ? opt.ca_directory : "/etc/ssl/certs";
|
||||
#if GNUTLS_VERSION_MAJOR >= 3
|
||||
if (!opt.ca_directory)
|
||||
ncerts = gnutls_certificate_set_x509_system_trust (credentials);
|
||||
#endif
|
||||
|
||||
dir = opendir (ca_directory);
|
||||
if (dir == NULL)
|
||||
/* If GnuTLS version is too old or CA loading failed, fallback to old behaviour.
|
||||
* Also use old behaviour if the CA directory is user-provided. */
|
||||
if (ncerts <= 0)
|
||||
{
|
||||
if (opt.ca_directory)
|
||||
logprintf (LOG_NOTQUIET, _("ERROR: Cannot open directory %s.\n"),
|
||||
opt.ca_directory);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct dirent *dent;
|
||||
while ((dent = readdir (dir)) != NULL)
|
||||
ca_directory = opt.ca_directory ? opt.ca_directory : "/etc/ssl/certs";
|
||||
if ((dir = opendir (ca_directory)) == NULL)
|
||||
{
|
||||
struct stat st;
|
||||
char *ca_file;
|
||||
asprintf (&ca_file, "%s/%s", ca_directory, dent->d_name);
|
||||
if (opt.ca_directory && *opt.ca_directory)
|
||||
logprintf (LOG_NOTQUIET, _("ERROR: Cannot open directory %s.\n"),
|
||||
opt.ca_directory);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct hash_table *inode_map = hash_table_new (196, NULL, NULL);
|
||||
struct dirent *dent;
|
||||
size_t dirlen = strlen(ca_directory);
|
||||
int rc;
|
||||
|
||||
stat (ca_file, &st);
|
||||
ncerts = 0;
|
||||
|
||||
if (S_ISREG (st.st_mode))
|
||||
gnutls_certificate_set_x509_trust_file (credentials, ca_file,
|
||||
GNUTLS_X509_FMT_PEM);
|
||||
while ((dent = readdir (dir)) != NULL)
|
||||
{
|
||||
struct stat st;
|
||||
size_t ca_file_length = dirlen + strlen(dent->d_name) + 2;
|
||||
char *ca_file = alloca(ca_file_length);
|
||||
|
||||
free (ca_file);
|
||||
snprintf (ca_file, ca_file_length, "%s/%s", ca_directory, dent->d_name);
|
||||
if (stat (ca_file, &st) != 0)
|
||||
continue;
|
||||
|
||||
if (! S_ISREG (st.st_mode))
|
||||
continue;
|
||||
|
||||
/* avoid loading the same file twice by checking the inode. */
|
||||
if (hash_table_contains (inode_map, (void *)(intptr_t) st.st_ino))
|
||||
continue;
|
||||
|
||||
hash_table_put (inode_map, (void *)(intptr_t) st.st_ino, NULL);
|
||||
if ((rc = gnutls_certificate_set_x509_trust_file (credentials, ca_file,
|
||||
GNUTLS_X509_FMT_PEM)) <= 0)
|
||||
DEBUGP (("WARNING: Failed to open cert %s: (%d).\n", ca_file, rc));
|
||||
else
|
||||
ncerts += rc;
|
||||
}
|
||||
|
||||
hash_table_destroy (inode_map);
|
||||
closedir (dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (opt.ca_cert)
|
||||
{
|
||||
int rc;
|
||||
|
||||
ncerts = 0;
|
||||
|
||||
if ((rc = gnutls_certificate_set_x509_trust_file (credentials, opt.ca_cert,
|
||||
GNUTLS_X509_FMT_PEM)) <= 0)
|
||||
logprintf (LOG_NOTQUIET, _ ("ERROR: Failed to open cert %s: (%d).\n"),
|
||||
opt.ca_cert, rc);
|
||||
else
|
||||
{
|
||||
ncerts += rc;
|
||||
logprintf (LOG_NOTQUIET, _ ("Loaded CA certificate '%s'\n"), opt.ca_cert);
|
||||
}
|
||||
}
|
||||
|
||||
if (opt.crl_file)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if ((rc = gnutls_certificate_set_x509_crl_file (credentials, opt.crl_file, GNUTLS_X509_FMT_PEM)) <= 0)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("ERROR: Failed to load CRL file '%s': (%d)\n"), opt.crl_file, rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
closedir (dir);
|
||||
logprintf (LOG_NOTQUIET, _ ("Loaded CRL file '%s'\n"), opt.crl_file);
|
||||
}
|
||||
|
||||
DEBUGP (("Certificates loaded: %d\n", ncerts));
|
||||
|
||||
/* Use the private key from the cert file unless otherwise specified. */
|
||||
if (opt.cert_file && !opt.private_key)
|
||||
{
|
||||
opt.private_key = opt.cert_file;
|
||||
opt.private_key = xstrdup (opt.cert_file);
|
||||
opt.private_key_type = opt.cert_type;
|
||||
}
|
||||
/* Use the cert from the private key file unless otherwise specified. */
|
||||
if (!opt.cert_file && opt.private_key)
|
||||
{
|
||||
opt.cert_file = opt.private_key;
|
||||
opt.cert_file = xstrdup (opt.private_key);
|
||||
opt.cert_type = opt.private_key_type;
|
||||
}
|
||||
|
||||
@@ -141,23 +203,19 @@ ssl_init (void)
|
||||
{
|
||||
int type;
|
||||
if (opt.private_key_type != opt.cert_type)
|
||||
{
|
||||
/* GnuTLS can't handle this */
|
||||
logprintf (LOG_NOTQUIET, _("ERROR: GnuTLS requires the key and the \
|
||||
{
|
||||
/* GnuTLS can't handle this */
|
||||
logprintf (LOG_NOTQUIET, _("ERROR: GnuTLS requires the key and the \
|
||||
cert to be of the same type.\n"));
|
||||
}
|
||||
}
|
||||
|
||||
type = key_type_to_gnutls_type (opt.private_key_type);
|
||||
|
||||
gnutls_certificate_set_x509_key_file (credentials, opt.cert_file,
|
||||
opt.private_key,
|
||||
type);
|
||||
opt.private_key,
|
||||
type);
|
||||
}
|
||||
|
||||
if (opt.ca_cert)
|
||||
gnutls_certificate_set_x509_trust_file (credentials, opt.ca_cert,
|
||||
GNUTLS_X509_FMT_PEM);
|
||||
|
||||
ssl_initialized = true;
|
||||
|
||||
return true;
|
||||
@@ -166,6 +224,7 @@ cert to be of the same type.\n"));
|
||||
struct wgnutls_transport_context
|
||||
{
|
||||
gnutls_session_t session; /* GnuTLS session handle */
|
||||
gnutls_datum_t *session_data;
|
||||
int last_error; /* last error returned by read/write/... */
|
||||
|
||||
/* Since GnuTLS doesn't support the equivalent to recv(...,
|
||||
@@ -176,11 +235,6 @@ struct wgnutls_transport_context
|
||||
int peeklen;
|
||||
};
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(i, j) ((i) <= (j) ? (i) : (j))
|
||||
#endif
|
||||
|
||||
|
||||
static int
|
||||
wgnutls_read_timeout (int fd, char *buf, int bufsize, void *arg, double timeout)
|
||||
{
|
||||
@@ -228,6 +282,12 @@ wgnutls_read_timeout (int fd, char *buf, int bufsize, void *arg, double timeout)
|
||||
{
|
||||
ret = gnutls_record_recv (ctx->session, buf, bufsize);
|
||||
timed_out = timeout && ptimer_measure (timer) >= timeout;
|
||||
if (!timed_out && ret == GNUTLS_E_REHANDSHAKE)
|
||||
{
|
||||
DEBUGP (("GnuTLS: *** REHANDSHAKE while reading\n"));
|
||||
if ((ret = _do_handshake (ctx->session, fd, timeout)) == 0)
|
||||
ret = GNUTLS_E_AGAIN; /* restart reading */
|
||||
}
|
||||
}
|
||||
}
|
||||
while (ret == GNUTLS_E_INTERRUPTED || (ret == GNUTLS_E_AGAIN && !timed_out));
|
||||
@@ -278,7 +338,7 @@ wgnutls_read (int fd, char *buf, int bufsize, void *arg)
|
||||
}
|
||||
|
||||
static int
|
||||
wgnutls_write (int fd, char *buf, int bufsize, void *arg)
|
||||
wgnutls_write (int fd _GL_UNUSED, char *buf, int bufsize, void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct wgnutls_transport_context *ctx = arg;
|
||||
@@ -315,7 +375,7 @@ wgnutls_peek (int fd, char *buf, int bufsize, void *arg)
|
||||
return offset;
|
||||
}
|
||||
|
||||
if (bufsize > sizeof ctx->peekbuf)
|
||||
if (bufsize > (int) sizeof ctx->peekbuf)
|
||||
bufsize = sizeof ctx->peekbuf;
|
||||
|
||||
if (bufsize > offset)
|
||||
@@ -346,7 +406,7 @@ wgnutls_peek (int fd, char *buf, int bufsize, void *arg)
|
||||
}
|
||||
|
||||
static const char *
|
||||
wgnutls_errstr (int fd, void *arg)
|
||||
wgnutls_errstr (int fd _GL_UNUSED, void *arg)
|
||||
{
|
||||
struct wgnutls_transport_context *ctx = arg;
|
||||
return gnutls_strerror (ctx->last_error);
|
||||
@@ -357,6 +417,11 @@ wgnutls_close (int fd, void *arg)
|
||||
{
|
||||
struct wgnutls_transport_context *ctx = arg;
|
||||
/*gnutls_bye (ctx->session, GNUTLS_SHUT_RDWR);*/
|
||||
if (ctx->session_data)
|
||||
{
|
||||
gnutls_free (ctx->session_data->data);
|
||||
gnutls_free (ctx->session_data);
|
||||
}
|
||||
gnutls_deinit (ctx->session);
|
||||
xfree (ctx);
|
||||
close (fd);
|
||||
@@ -371,19 +436,124 @@ static struct transport_implementation wgnutls_transport =
|
||||
wgnutls_peek, wgnutls_errstr, wgnutls_close
|
||||
};
|
||||
|
||||
static int
|
||||
_do_handshake (gnutls_session_t session, int fd, double timeout)
|
||||
{
|
||||
#ifdef F_GETFL
|
||||
int flags = 0;
|
||||
#endif
|
||||
int err;
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
#ifdef F_GETFL
|
||||
flags = fcntl (fd, F_GETFL, 0);
|
||||
if (flags < 0)
|
||||
return flags;
|
||||
if (fcntl (fd, F_SETFL, flags | O_NONBLOCK))
|
||||
return -1;
|
||||
#else
|
||||
/* XXX: Assume it was blocking before. */
|
||||
const int one = 1;
|
||||
if (ioctl (fd, FIONBIO, &one) < 0)
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We don't stop the handshake process for non-fatal errors */
|
||||
do
|
||||
{
|
||||
err = gnutls_handshake (session);
|
||||
|
||||
if (timeout && err == GNUTLS_E_AGAIN)
|
||||
{
|
||||
if (gnutls_record_get_direction (session))
|
||||
{
|
||||
/* wait for writeability */
|
||||
err = select_fd (fd, timeout, WAIT_FOR_WRITE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* wait for readability */
|
||||
err = select_fd (fd, timeout, WAIT_FOR_READ);
|
||||
}
|
||||
|
||||
if (err <= 0)
|
||||
{
|
||||
if (err == 0)
|
||||
{
|
||||
errno = ETIMEDOUT;
|
||||
err = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
err = GNUTLS_E_AGAIN;
|
||||
}
|
||||
else if (err < 0)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, "GnuTLS: %s\n", gnutls_strerror (err));
|
||||
if (err == GNUTLS_E_WARNING_ALERT_RECEIVED ||
|
||||
err == GNUTLS_E_FATAL_ALERT_RECEIVED)
|
||||
{
|
||||
gnutls_alert_description_t alert = gnutls_alert_get (session);
|
||||
const char *str = gnutls_alert_get_name (alert);
|
||||
logprintf (LOG_NOTQUIET, "GnuTLS: received alert [%d]: %s\n",
|
||||
alert, str ? str : "(unknown)");
|
||||
}
|
||||
}
|
||||
}
|
||||
while (err && gnutls_error_is_fatal (err) == 0);
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
#ifdef F_GETFL
|
||||
if (fcntl (fd, F_SETFL, flags) < 0)
|
||||
return -1;
|
||||
#else
|
||||
const int zero = 0;
|
||||
if (ioctl (fd, FIONBIO, &zero) < 0)
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static const char *
|
||||
_sni_hostname(const char *hostname)
|
||||
{
|
||||
size_t len = strlen(hostname);
|
||||
|
||||
char *sni_hostname = xmemdup(hostname, len + 1);
|
||||
|
||||
/* Remove trailing dot(s) to fix #47408.
|
||||
* Regarding RFC 6066 (SNI): The hostname is represented as a byte
|
||||
* string using ASCII encoding without a trailing dot. */
|
||||
while (len && sni_hostname[--len] == '.')
|
||||
sni_hostname[len] = 0;
|
||||
|
||||
return sni_hostname;
|
||||
}
|
||||
|
||||
bool
|
||||
ssl_connect_wget (int fd, const char *hostname)
|
||||
ssl_connect_wget (int fd, const char *hostname, int *continue_session)
|
||||
{
|
||||
struct wgnutls_transport_context *ctx;
|
||||
gnutls_session_t session;
|
||||
int err;
|
||||
|
||||
gnutls_init (&session, GNUTLS_CLIENT);
|
||||
|
||||
/* We set the server name but only if it's not an IP address. */
|
||||
if (! is_valid_ip_address (hostname))
|
||||
{
|
||||
gnutls_server_name_set (session, GNUTLS_NAME_DNS, hostname,
|
||||
strlen (hostname));
|
||||
/* GnuTLS 3.4.x (x<=10) disrespects the length parameter, we have to construct a new string */
|
||||
/* see https://gitlab.com/gnutls/gnutls/issues/78 */
|
||||
const char *sni_hostname = _sni_hostname(hostname);
|
||||
|
||||
gnutls_server_name_set (session, GNUTLS_NAME_DNS, sni_hostname, strlen(sni_hostname));
|
||||
xfree(sni_hostname);
|
||||
}
|
||||
|
||||
gnutls_set_default_priority (session);
|
||||
@@ -391,22 +561,46 @@ ssl_connect_wget (int fd, const char *hostname)
|
||||
#ifndef FD_TO_SOCKET
|
||||
# define FD_TO_SOCKET(X) (X)
|
||||
#endif
|
||||
#ifdef HAVE_INTPTR_T
|
||||
gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) (intptr_t) FD_TO_SOCKET (fd));
|
||||
#else
|
||||
gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) FD_TO_SOCKET (fd));
|
||||
#endif
|
||||
|
||||
err = 0;
|
||||
#if HAVE_GNUTLS_PRIORITY_SET_DIRECT
|
||||
switch (opt.secure_protocol)
|
||||
{
|
||||
case secure_protocol_auto:
|
||||
err = gnutls_priority_set_direct (session, "NORMAL:%COMPAT:-VERS-SSL3.0", NULL);
|
||||
break;
|
||||
|
||||
case secure_protocol_sslv2:
|
||||
case secure_protocol_sslv3:
|
||||
err = gnutls_priority_set_direct (session, "NORMAL:-VERS-TLS-ALL", NULL);
|
||||
err = gnutls_priority_set_direct (session, "NORMAL:-VERS-TLS-ALL:+VERS-SSL3.0", NULL);
|
||||
break;
|
||||
|
||||
case secure_protocol_tlsv1:
|
||||
err = gnutls_priority_set_direct (session, "NORMAL:-VERS-SSL3.0", NULL);
|
||||
break;
|
||||
|
||||
case secure_protocol_tlsv1_1:
|
||||
err = gnutls_priority_set_direct (session, "NORMAL:-VERS-SSL3.0:-VERS-TLS1.0", NULL);
|
||||
break;
|
||||
|
||||
case secure_protocol_tlsv1_2:
|
||||
err = gnutls_priority_set_direct (session, "NORMAL:-VERS-SSL3.0:-VERS-TLS1.0:-VERS-TLS1.1", NULL);
|
||||
break;
|
||||
|
||||
case secure_protocol_pfs:
|
||||
err = gnutls_priority_set_direct (session, "PFS:-VERS-SSL3.0", NULL);
|
||||
if (err != GNUTLS_E_SUCCESS)
|
||||
/* fallback if PFS is not available */
|
||||
err = gnutls_priority_set_direct (session, "NORMAL:-RSA:-VERS-SSL3.0", NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
logprintf (LOG_NOTQUIET, _("GnuTLS: unimplemented 'secure-protocol' option value %d\n"), opt.secure_protocol);
|
||||
logprintf (LOG_NOTQUIET, _("Please report this issue to bug-wget@gnu.org\n"));
|
||||
abort ();
|
||||
}
|
||||
#else
|
||||
@@ -415,6 +609,7 @@ ssl_connect_wget (int fd, const char *hostname)
|
||||
{
|
||||
case secure_protocol_auto:
|
||||
break;
|
||||
|
||||
case secure_protocol_sslv2:
|
||||
case secure_protocol_sslv3:
|
||||
allowed_protocols[0] = GNUTLS_SSL3;
|
||||
@@ -428,7 +623,20 @@ ssl_connect_wget (int fd, const char *hostname)
|
||||
err = gnutls_protocol_set_priority (session, allowed_protocols);
|
||||
break;
|
||||
|
||||
case secure_protocol_tlsv1_1:
|
||||
allowed_protocols[0] = GNUTLS_TLS1_1;
|
||||
allowed_protocols[1] = GNUTLS_TLS1_2;
|
||||
err = gnutls_protocol_set_priority (session, allowed_protocols);
|
||||
break;
|
||||
|
||||
case secure_protocol_tlsv1_2:
|
||||
allowed_protocols[0] = GNUTLS_TLS1_2;
|
||||
err = gnutls_protocol_set_priority (session, allowed_protocols);
|
||||
break;
|
||||
|
||||
default:
|
||||
logprintf (LOG_NOTQUIET, _("GnuTLS: unimplemented 'secure-protocol' option value %d\n"), opt.secure_protocol);
|
||||
logprintf (LOG_NOTQUIET, _("Please report this issue to bug-wget@gnu.org\n"));
|
||||
abort ();
|
||||
}
|
||||
#endif
|
||||
@@ -440,20 +648,112 @@ ssl_connect_wget (int fd, const char *hostname)
|
||||
return false;
|
||||
}
|
||||
|
||||
err = gnutls_handshake (session);
|
||||
if (continue_session)
|
||||
{
|
||||
ctx = (struct wgnutls_transport_context *) fd_transport_context (*continue_session);
|
||||
if (!gnutls_session_is_resumed (session))
|
||||
{
|
||||
if (!ctx || !ctx->session_data || gnutls_session_set_data (session, ctx->session_data->data, ctx->session_data->size))
|
||||
{
|
||||
if (ctx && ctx->session_data)
|
||||
{
|
||||
/* server does not want to continue the session */
|
||||
if (ctx->session_data->data)
|
||||
gnutls_free (ctx->session_data->data);
|
||||
gnutls_free (ctx->session_data);
|
||||
}
|
||||
gnutls_deinit (session);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logputs (LOG_ALWAYS, "SSL session has already been resumed. Continuing.\n");
|
||||
continue_session = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
err = _do_handshake (session, fd, opt.connect_timeout);
|
||||
|
||||
if (err < 0)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, "GnuTLS: %s\n", gnutls_strerror (err));
|
||||
gnutls_deinit (session);
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx = xnew0 (struct wgnutls_transport_context);
|
||||
ctx->session_data = xnew0 (gnutls_datum_t);
|
||||
ctx->session = session;
|
||||
if (gnutls_session_get_data2 (session, ctx->session_data))
|
||||
{
|
||||
xfree (ctx->session_data);
|
||||
logprintf (LOG_NOTQUIET, "WARNING: Could not save SSL session data for socket %d\n", fd);
|
||||
}
|
||||
fd_register_transport (fd, &wgnutls_transport, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
pkp_pin_peer_pubkey (gnutls_x509_crt_t cert, const char *pinnedpubkey)
|
||||
{
|
||||
/* Scratch */
|
||||
size_t len1 = 0, len2 = 0;
|
||||
char *buff1 = NULL;
|
||||
|
||||
gnutls_pubkey_t key = NULL;
|
||||
|
||||
/* Result is returned to caller */
|
||||
int ret = 0;
|
||||
bool result = false;
|
||||
|
||||
/* if a path wasn't specified, don't pin */
|
||||
if (NULL == pinnedpubkey)
|
||||
return true;
|
||||
|
||||
if (NULL == cert)
|
||||
return result;
|
||||
|
||||
/* Begin Gyrations to get the public key */
|
||||
gnutls_pubkey_init (&key);
|
||||
|
||||
ret = gnutls_pubkey_import_x509 (key, cert, 0);
|
||||
if (ret < 0)
|
||||
goto cleanup; /* failed */
|
||||
|
||||
ret = gnutls_pubkey_export (key, GNUTLS_X509_FMT_DER, NULL, &len1);
|
||||
if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER || len1 == 0)
|
||||
goto cleanup; /* failed */
|
||||
|
||||
buff1 = xmalloc (len1);
|
||||
|
||||
len2 = len1;
|
||||
|
||||
ret = gnutls_pubkey_export (key, GNUTLS_X509_FMT_DER, buff1, &len2);
|
||||
if (ret < 0 || len1 != len2)
|
||||
goto cleanup; /* failed */
|
||||
|
||||
/* End Gyrations */
|
||||
|
||||
/* The one good exit point */
|
||||
result = wg_pin_peer_pubkey (pinnedpubkey, buff1, len1);
|
||||
|
||||
cleanup:
|
||||
if (NULL != key)
|
||||
gnutls_pubkey_deinit (key);
|
||||
|
||||
xfree (buff1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define _CHECK_CERT(flag,msg) \
|
||||
if (status & (flag))\
|
||||
{\
|
||||
logprintf (LOG_NOTQUIET, (msg),\
|
||||
severity, quote (host));\
|
||||
success = false;\
|
||||
}
|
||||
|
||||
bool
|
||||
ssl_check_certificate (int fd, const char *host)
|
||||
{
|
||||
@@ -466,6 +766,11 @@ ssl_check_certificate (int fd, const char *host)
|
||||
him about problems with the server's certificate. */
|
||||
const char *severity = opt.check_cert ? _("ERROR") : _("WARNING");
|
||||
bool success = true;
|
||||
bool pinsuccess = opt.pinnedpubkey == NULL;
|
||||
|
||||
/* The user explicitly said to not check for the certificate. */
|
||||
if (opt.check_cert == CHECK_CERT_QUIET && pinsuccess)
|
||||
return success;
|
||||
|
||||
err = gnutls_certificate_verify_peers2 (ctx->session, &status);
|
||||
if (err < 0)
|
||||
@@ -476,24 +781,13 @@ ssl_check_certificate (int fd, const char *host)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (status & GNUTLS_CERT_INVALID)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("%s: The certificate of %s is not trusted.\n"),
|
||||
severity, quote (host));
|
||||
success = false;
|
||||
}
|
||||
if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("%s: The certificate of %s hasn't got a known issuer.\n"),
|
||||
severity, quote (host));
|
||||
success = false;
|
||||
}
|
||||
if (status & GNUTLS_CERT_REVOKED)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("%s: The certificate of %s has been revoked.\n"),
|
||||
severity, quote (host));
|
||||
success = false;
|
||||
}
|
||||
_CHECK_CERT (GNUTLS_CERT_INVALID, _("%s: The certificate of %s is not trusted.\n"));
|
||||
_CHECK_CERT (GNUTLS_CERT_SIGNER_NOT_FOUND, _("%s: The certificate of %s hasn't got a known issuer.\n"));
|
||||
_CHECK_CERT (GNUTLS_CERT_REVOKED, _("%s: The certificate of %s has been revoked.\n"));
|
||||
_CHECK_CERT (GNUTLS_CERT_SIGNER_NOT_CA, _("%s: The certificate signer of %s was not a CA.\n"));
|
||||
_CHECK_CERT (GNUTLS_CERT_INSECURE_ALGORITHM, _("%s: The certificate of %s was signed using an insecure algorithm.\n"));
|
||||
_CHECK_CERT (GNUTLS_CERT_NOT_ACTIVATED, _("%s: The certificate of %s is not yet activated.\n"));
|
||||
_CHECK_CERT (GNUTLS_CERT_EXPIRED, _("%s: The certificate of %s has expired.\n"));
|
||||
|
||||
if (gnutls_certificate_type_get (ctx->session) == GNUTLS_CRT_X509)
|
||||
{
|
||||
@@ -501,6 +795,7 @@ ssl_check_certificate (int fd, const char *host)
|
||||
gnutls_x509_crt_t cert;
|
||||
const gnutls_datum_t *cert_list;
|
||||
unsigned int cert_list_size;
|
||||
const char *sni_hostname;
|
||||
|
||||
if ((err = gnutls_x509_crt_init (&cert)) < 0)
|
||||
{
|
||||
@@ -515,7 +810,7 @@ ssl_check_certificate (int fd, const char *host)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("No certificate found\n"));
|
||||
success = false;
|
||||
goto out;
|
||||
goto crt_deinit;
|
||||
}
|
||||
err = gnutls_x509_crt_import (cert, cert_list, GNUTLS_X509_FMT_DER);
|
||||
if (err < 0)
|
||||
@@ -523,7 +818,7 @@ ssl_check_certificate (int fd, const char *host)
|
||||
logprintf (LOG_NOTQUIET, _("Error parsing certificate: %s\n"),
|
||||
gnutls_strerror (err));
|
||||
success = false;
|
||||
goto out;
|
||||
goto crt_deinit;
|
||||
}
|
||||
if (now < gnutls_x509_crt_get_activation_time (cert))
|
||||
{
|
||||
@@ -535,16 +830,33 @@ ssl_check_certificate (int fd, const char *host)
|
||||
logprintf (LOG_NOTQUIET, _("The certificate has expired\n"));
|
||||
success = false;
|
||||
}
|
||||
if (!gnutls_x509_crt_check_hostname (cert, host))
|
||||
sni_hostname = _sni_hostname(host);
|
||||
if (!gnutls_x509_crt_check_hostname (cert, sni_hostname))
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("The certificate's owner does not match hostname %s\n"),
|
||||
quote (host));
|
||||
quote (sni_hostname));
|
||||
success = false;
|
||||
}
|
||||
xfree(sni_hostname);
|
||||
|
||||
pinsuccess = pkp_pin_peer_pubkey (cert, opt.pinnedpubkey);
|
||||
if (!pinsuccess)
|
||||
{
|
||||
logprintf (LOG_ALWAYS, _("The public key does not match pinned public key!\n"));
|
||||
success = false;
|
||||
}
|
||||
|
||||
crt_deinit:
|
||||
gnutls_x509_crt_deinit (cert);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("Certificate must be X.509\n"));
|
||||
success = false;
|
||||
}
|
||||
|
||||
out:
|
||||
return opt.check_cert ? success : true;
|
||||
/* never return true if pinsuccess fails */
|
||||
return !pinsuccess ? false : (opt.check_cert == CHECK_CERT_ON ? success : true);
|
||||
}
|
||||
|
||||
30
src/hash.c
30
src/hash.c
@@ -1,6 +1,6 @@
|
||||
/* Hash tables.
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
|
||||
2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
2009, 2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -46,20 +46,17 @@ as that of the covered work. */
|
||||
# include "utils.h"
|
||||
#else
|
||||
/* Make do without them. */
|
||||
# define xnew(x) xmalloc (sizeof (x))
|
||||
# define xnew_array(type, x) xmalloc (sizeof (type) * (x))
|
||||
# define xmalloc malloc
|
||||
# define xfree free
|
||||
# define xnew(type) (xmalloc (sizeof (type)))
|
||||
# define xnew0(type) (xcalloc (1, sizeof (type)))
|
||||
# define xnew_array(type, len) (xmalloc ((len) * sizeof (type)))
|
||||
# define xfree(p) do { free ((void *) (p)); p = NULL; } while (0)
|
||||
|
||||
# ifndef countof
|
||||
# define countof(x) (sizeof (x) / sizeof ((x)[0]))
|
||||
# endif
|
||||
# include <ctype.h>
|
||||
# define c_tolower(x) tolower ((unsigned char) (x))
|
||||
# ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# else
|
||||
typedef unsigned long uintptr_t;
|
||||
# endif
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "hash.h"
|
||||
@@ -589,7 +586,7 @@ hash_table_count (const struct hash_table *ht)
|
||||
{
|
||||
return ht->count;
|
||||
}
|
||||
|
||||
|
||||
/* Functions from this point onward are meant for convenience and
|
||||
don't strictly belong to this file. However, this is as good a
|
||||
place for them as any. */
|
||||
@@ -744,7 +741,7 @@ cmp_pointer (const void *ptr1, const void *ptr2)
|
||||
{
|
||||
return ptr1 == ptr2;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -767,6 +764,15 @@ main (void)
|
||||
{
|
||||
struct hash_table *ht = make_string_hash_table (0);
|
||||
char line[80];
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
/* Set the current locale. */
|
||||
setlocale (LC_ALL, "");
|
||||
/* Set the text message domain. */
|
||||
bindtextdomain ("wget", LOCALEDIR);
|
||||
textdomain ("wget");
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
while ((fgets (line, sizeof (line), stdin)))
|
||||
{
|
||||
int len = strlen (line);
|
||||
|
||||
10
src/hash.h
10
src/hash.h
@@ -1,5 +1,5 @@
|
||||
/* Hash table declarations.
|
||||
Copyright (C) 2000, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Copyright (C) 2000, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
@@ -34,7 +34,7 @@ as that of the covered work. */
|
||||
struct hash_table;
|
||||
|
||||
struct hash_table *hash_table_new (int, unsigned long (*) (const void *),
|
||||
int (*) (const void *, const void *));
|
||||
int (*) (const void *, const void *));
|
||||
void hash_table_destroy (struct hash_table *);
|
||||
|
||||
void *hash_table_get (const struct hash_table *, const void *);
|
||||
@@ -47,11 +47,11 @@ int hash_table_remove (struct hash_table *, const void *);
|
||||
void hash_table_clear (struct hash_table *);
|
||||
|
||||
void hash_table_for_each (struct hash_table *,
|
||||
int (*) (void *, void *, void *), void *);
|
||||
int (*) (void *, void *, void *), void *);
|
||||
|
||||
typedef struct {
|
||||
void *key, *value; /* public members */
|
||||
void *pos, *end; /* private members */
|
||||
void *key, *value; /* public members */
|
||||
void *pos, *end; /* private members */
|
||||
} hash_table_iterator;
|
||||
void hash_table_iterate (struct hash_table *, hash_table_iterator *);
|
||||
int hash_table_iter_next (hash_table_iterator *);
|
||||
|
||||
297
src/host.c
297
src/host.c
@@ -1,7 +1,7 @@
|
||||
/* Host name resolution and matching.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -57,10 +57,15 @@ as that of the covered work. */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef ENABLE_IRI
|
||||
#include <idn-free.h>
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include "host.h"
|
||||
#include "url.h"
|
||||
#include "hash.h"
|
||||
#include "ptimer.h"
|
||||
|
||||
#ifndef NO_ADDRESS
|
||||
# define NO_ADDRESS NO_DATA
|
||||
@@ -151,6 +156,13 @@ address_list_set_faulty (struct address_list *al, int index)
|
||||
"faulty" attempt is always preceded with all-faulty addresses,
|
||||
and this is how Wget uses it. */
|
||||
assert (index == al->faulty);
|
||||
if (index != al->faulty)
|
||||
{
|
||||
logprintf (LOG_ALWAYS, "index: %d\nal->faulty: %d\n", index, al->faulty);
|
||||
logprintf (LOG_ALWAYS, _("Error in handling the address list.\n"));
|
||||
logprintf (LOG_ALWAYS, _("Please report this issue to bug-wget@gnu.org\n"));
|
||||
abort();
|
||||
}
|
||||
|
||||
++al->faulty;
|
||||
if (al->faulty >= al->count)
|
||||
@@ -309,7 +321,7 @@ address_list_release (struct address_list *al)
|
||||
address_list_delete (al);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Versions of gethostbyname and getaddrinfo that support timeout. */
|
||||
|
||||
#ifndef ENABLE_IPV6
|
||||
@@ -408,7 +420,7 @@ getaddrinfo_with_timeout (const char *node, const char *service,
|
||||
}
|
||||
|
||||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
|
||||
/* Return a textual representation of ADDR, i.e. the dotted quad for
|
||||
IPv4 addresses, and the colon-separated list of hex words (with all
|
||||
zeros omitted, etc.) for IPv6 addresses. */
|
||||
@@ -570,7 +582,7 @@ is_valid_ipv6_address (const char *str, const char *end)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Simple host cache, used by lookup_host to speed up resolving. The
|
||||
cache doesn't handle TTL because Wget is a fairly short-lived
|
||||
application. Refreshing is attempted when connect fails, though --
|
||||
@@ -592,7 +604,7 @@ cache_query (const char *host)
|
||||
al = hash_table_get (host_name_addresses_map, host);
|
||||
if (al)
|
||||
{
|
||||
DEBUGP (("Found %s in host_name_addresses_map (%p)\n", host, al));
|
||||
DEBUGP (("Found %s in host_name_addresses_map (%p)\n", host, (void *) al));
|
||||
++al->refcount;
|
||||
return al;
|
||||
}
|
||||
@@ -637,7 +649,113 @@ cache_remove (const char *host)
|
||||
hash_table_remove (host_name_addresses_map, host);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_LIBCARES
|
||||
#include <sys/select.h>
|
||||
#include <ares.h>
|
||||
extern ares_channel ares;
|
||||
|
||||
static struct address_list *
|
||||
merge_address_lists (struct address_list *al1, struct address_list *al2)
|
||||
{
|
||||
int count = al1->count + al2->count;
|
||||
|
||||
/* merge al2 into al1 */
|
||||
al1->addresses = xrealloc (al1->addresses, sizeof (ip_address) * count);
|
||||
memcpy (al1->addresses + al1->count, al2->addresses, sizeof (ip_address) * al2->count);
|
||||
al1->count = count;
|
||||
|
||||
address_list_delete (al2);
|
||||
|
||||
return al1;
|
||||
}
|
||||
|
||||
static struct address_list *
|
||||
address_list_from_hostent (struct hostent *host)
|
||||
{
|
||||
int count, i;
|
||||
struct address_list *al = xnew0 (struct address_list);
|
||||
|
||||
for (count = 0; host->h_addr_list[count]; count++)
|
||||
;
|
||||
|
||||
assert (count > 0);
|
||||
|
||||
al->addresses = xnew_array (ip_address, count);
|
||||
al->count = count;
|
||||
al->refcount = 1;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
ip_address *ip = &al->addresses[i];
|
||||
ip->family = host->h_addrtype;
|
||||
memcpy (IP_INADDR_DATA (ip), host->h_addr_list[i], ip->family == AF_INET ? 4 : 16);
|
||||
}
|
||||
|
||||
return al;
|
||||
}
|
||||
|
||||
/* Since GnuLib's select() (i.e. rpl_select()) cannot handle socket-numbers
|
||||
* returned from C-ares, we must use the original select() from Winsock.
|
||||
*/
|
||||
#ifdef WINDOWS
|
||||
#undef select
|
||||
#endif
|
||||
|
||||
static void
|
||||
wait_ares (ares_channel channel)
|
||||
{
|
||||
struct ptimer *timer = NULL;
|
||||
|
||||
if (opt.dns_timeout)
|
||||
timer = ptimer_new ();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
struct timeval *tvp, tv;
|
||||
fd_set read_fds, write_fds;
|
||||
int nfds, rc;
|
||||
|
||||
FD_ZERO (&read_fds);
|
||||
FD_ZERO (&write_fds);
|
||||
nfds = ares_fds (channel, &read_fds, &write_fds);
|
||||
if (nfds == 0)
|
||||
break;
|
||||
|
||||
if (timer)
|
||||
{
|
||||
double max = opt.dns_timeout - ptimer_measure (timer);
|
||||
|
||||
tv.tv_sec = (long) max;
|
||||
tv.tv_usec = 1000000 * (max - (long) max);
|
||||
tvp = ares_timeout (channel, &tv, &tv);
|
||||
}
|
||||
else
|
||||
tvp = ares_timeout (channel, NULL, &tv);
|
||||
|
||||
rc = select (nfds, &read_fds, &write_fds, NULL, tvp);
|
||||
if (rc == 0 && timer && ptimer_measure (timer) >= opt.dns_timeout)
|
||||
ares_cancel (channel);
|
||||
else
|
||||
ares_process (channel, &read_fds, &write_fds);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
callback (void *arg, int status, int timeouts _GL_UNUSED, struct hostent *host)
|
||||
{
|
||||
struct address_list **al = (struct address_list **) arg;
|
||||
|
||||
if (!host || status != ARES_SUCCESS)
|
||||
{
|
||||
*al = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
*al = address_list_from_hostent (host);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Look up HOST in DNS and return a list of IP addresses.
|
||||
|
||||
This function caches its result so that, if the same host is passed
|
||||
@@ -734,91 +852,122 @@ lookup_host (const char *host, int flags)
|
||||
str = xmalloc (len);
|
||||
snprintf (str, len, "%s (%s)", name, host);
|
||||
str[len-1] = '\0';
|
||||
xfree (name);
|
||||
idn_free (name);
|
||||
}
|
||||
|
||||
logprintf (LOG_VERBOSE, _("Resolving %s... "),
|
||||
quotearg_style (escape_quoting_style, str ? str : host));
|
||||
|
||||
if (str)
|
||||
xfree (str);
|
||||
xfree (str);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
{
|
||||
int err;
|
||||
struct addrinfo hints, *res;
|
||||
#ifdef HAVE_LIBCARES
|
||||
if (ares)
|
||||
{
|
||||
struct address_list *al4;
|
||||
struct address_list *al6;
|
||||
|
||||
xzero (hints);
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
if (opt.ipv4_only)
|
||||
hints.ai_family = AF_INET;
|
||||
else if (opt.ipv6_only)
|
||||
hints.ai_family = AF_INET6;
|
||||
else
|
||||
/* We tried using AI_ADDRCONFIG, but removed it because: it
|
||||
misinterprets IPv6 loopbacks, it is broken on AIX 5.1, and
|
||||
it's unneeded since we sort the addresses anyway. */
|
||||
if (opt.ipv4_only || !opt.ipv6_only)
|
||||
ares_gethostbyname (ares, host, AF_INET, callback, &al4);
|
||||
if (opt.ipv6_only || !opt.ipv4_only)
|
||||
ares_gethostbyname (ares, host, AF_INET6, callback, &al6);
|
||||
|
||||
wait_ares (ares);
|
||||
|
||||
if (al4 && al6)
|
||||
al = merge_address_lists (al4, al6);
|
||||
else if (al4)
|
||||
al = al4;
|
||||
else
|
||||
al = al6;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
int err;
|
||||
struct addrinfo hints, *res;
|
||||
|
||||
xzero (hints);
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
if (opt.ipv4_only)
|
||||
hints.ai_family = AF_INET;
|
||||
else if (opt.ipv6_only)
|
||||
hints.ai_family = AF_INET6;
|
||||
else
|
||||
/* We tried using AI_ADDRCONFIG, but removed it because: it
|
||||
misinterprets IPv6 loopbacks, it is broken on AIX 5.1, and
|
||||
it's unneeded since we sort the addresses anyway. */
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
|
||||
if (flags & LH_BIND)
|
||||
hints.ai_flags |= AI_PASSIVE;
|
||||
if (flags & LH_BIND)
|
||||
hints.ai_flags |= AI_PASSIVE;
|
||||
|
||||
#ifdef AI_NUMERICHOST
|
||||
if (numeric_address)
|
||||
{
|
||||
/* Where available, the AI_NUMERICHOST hint can prevent costly
|
||||
access to DNS servers. */
|
||||
hints.ai_flags |= AI_NUMERICHOST;
|
||||
timeout = 0; /* no timeout needed when "resolving"
|
||||
if (numeric_address)
|
||||
{
|
||||
/* Where available, the AI_NUMERICHOST hint can prevent costly
|
||||
access to DNS servers. */
|
||||
hints.ai_flags |= AI_NUMERICHOST;
|
||||
timeout = 0; /* no timeout needed when "resolving"
|
||||
numeric hosts -- avoid setting up
|
||||
signal handlers and such. */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
err = getaddrinfo_with_timeout (host, NULL, &hints, &res, timeout);
|
||||
if (err != 0 || res == NULL)
|
||||
{
|
||||
if (!silent)
|
||||
logprintf (LOG_VERBOSE, _("failed: %s.\n"),
|
||||
err != EAI_SYSTEM ? gai_strerror (err) : strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
al = address_list_from_addrinfo (res);
|
||||
freeaddrinfo (res);
|
||||
if (!al)
|
||||
{
|
||||
logprintf (LOG_VERBOSE,
|
||||
_("failed: No IPv4/IPv6 addresses for host.\n"));
|
||||
return NULL;
|
||||
}
|
||||
err = getaddrinfo_with_timeout (host, NULL, &hints, &res, timeout);
|
||||
|
||||
/* Reorder addresses so that IPv4 ones (or IPv6 ones, as per
|
||||
--prefer-family) come first. Sorting is stable so the order of
|
||||
the addresses with the same family is undisturbed. */
|
||||
if (al->count > 1 && opt.prefer_family != prefer_none)
|
||||
stable_sort (al->addresses, al->count, sizeof (ip_address),
|
||||
opt.prefer_family == prefer_ipv4
|
||||
? cmp_prefer_ipv4 : cmp_prefer_ipv6);
|
||||
}
|
||||
if (err != 0 || res == NULL)
|
||||
{
|
||||
if (!silent)
|
||||
logprintf (LOG_VERBOSE, _ ("failed: %s.\n"),
|
||||
err != EAI_SYSTEM ? gai_strerror (err) : strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
al = address_list_from_addrinfo (res);
|
||||
freeaddrinfo (res);
|
||||
}
|
||||
|
||||
if (!al)
|
||||
{
|
||||
logprintf (LOG_VERBOSE,
|
||||
_ ("failed: No IPv4/IPv6 addresses for host.\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Reorder addresses so that IPv4 ones (or IPv6 ones, as per
|
||||
--prefer-family) come first. Sorting is stable so the order of
|
||||
the addresses with the same family is undisturbed. */
|
||||
if (al->count > 1 && opt.prefer_family != prefer_none)
|
||||
stable_sort (al->addresses, al->count, sizeof (ip_address),
|
||||
opt.prefer_family == prefer_ipv4
|
||||
? cmp_prefer_ipv4 : cmp_prefer_ipv6);
|
||||
#else /* not ENABLE_IPV6 */
|
||||
{
|
||||
struct hostent *hptr = gethostbyname_with_timeout (host, timeout);
|
||||
if (!hptr)
|
||||
{
|
||||
if (!silent)
|
||||
{
|
||||
if (errno != ETIMEDOUT)
|
||||
logprintf (LOG_VERBOSE, _("failed: %s.\n"),
|
||||
host_errstr (h_errno));
|
||||
else
|
||||
logputs (LOG_VERBOSE, _("failed: timed out.\n"));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/* Do older systems have h_addr_list? */
|
||||
al = address_list_from_ipv4_addresses (hptr->h_addr_list);
|
||||
}
|
||||
#ifdef HAVE_LIBCARES
|
||||
if (ares)
|
||||
{
|
||||
ares_gethostbyname (ares, host, AF_INET, callback, &al);
|
||||
wait_ares (ares);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
struct hostent *hptr = gethostbyname_with_timeout (host, timeout);
|
||||
if (!hptr)
|
||||
{
|
||||
if (!silent)
|
||||
{
|
||||
if (errno != ETIMEDOUT)
|
||||
logprintf (LOG_VERBOSE, _ ("failed: %s.\n"),
|
||||
host_errstr (h_errno));
|
||||
else
|
||||
logputs (LOG_VERBOSE, _ ("failed: timed out.\n"));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/* Do older systems have h_addr_list? */
|
||||
al = address_list_from_ipv4_addresses (hptr->h_addr_list);
|
||||
}
|
||||
#endif /* not ENABLE_IPV6 */
|
||||
|
||||
/* Print the addresses determined by DNS lookup, but no more than
|
||||
@@ -848,7 +997,7 @@ lookup_host (const char *host, int flags)
|
||||
|
||||
return al;
|
||||
}
|
||||
|
||||
|
||||
/* Determine whether a URL is acceptable to be followed, according to
|
||||
a list of domains to accept. */
|
||||
bool
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Declarations for host.c
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -58,9 +58,9 @@ typedef struct {
|
||||
|
||||
/* The actual data, in the form of struct in_addr or in6_addr: */
|
||||
union {
|
||||
struct in_addr d4; /* IPv4 address */
|
||||
struct in_addr d4; /* IPv4 address */
|
||||
#ifdef ENABLE_IPV6
|
||||
struct in6_addr d6; /* IPv6 address */
|
||||
struct in6_addr d6; /* IPv6 address */
|
||||
#endif
|
||||
} data;
|
||||
|
||||
|
||||
819
src/hsts.c
Normal file
819
src/hsts.c
Normal file
@@ -0,0 +1,819 @@
|
||||
/* HTTP Strict Transport Security (HSTS) support.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
GNU Wget 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.
|
||||
|
||||
GNU Wget 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 Wget. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this program, or any covered work, by linking or
|
||||
combining it with the OpenSSL project's OpenSSL library (or a
|
||||
modified version of that library), containing parts covered by the
|
||||
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
|
||||
grants you additional permission to convey the resulting work.
|
||||
Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work. */
|
||||
#include "wget.h"
|
||||
|
||||
#ifdef HAVE_HSTS
|
||||
#include "hsts.h"
|
||||
#include "host.h" /* for is_valid_ip_address() */
|
||||
#include "init.h" /* for home_dir() */
|
||||
#include "utils.h"
|
||||
#include "hash.h"
|
||||
#include "c-ctype.h"
|
||||
#ifdef TESTING
|
||||
#include "test.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
struct hsts_store {
|
||||
struct hash_table *table;
|
||||
time_t last_mtime;
|
||||
bool changed;
|
||||
};
|
||||
|
||||
struct hsts_kh {
|
||||
char *host;
|
||||
int explicit_port;
|
||||
};
|
||||
|
||||
struct hsts_kh_info {
|
||||
time_t created;
|
||||
time_t max_age;
|
||||
bool include_subdomains;
|
||||
};
|
||||
|
||||
enum hsts_kh_match {
|
||||
NO_MATCH,
|
||||
SUPERDOMAIN_MATCH,
|
||||
CONGRUENT_MATCH
|
||||
};
|
||||
|
||||
#define hsts_is_host_name_valid(host) (!is_valid_ip_address (host))
|
||||
#define hsts_is_scheme_valid(scheme) (scheme == SCHEME_HTTPS)
|
||||
#define hsts_is_host_eligible(scheme, host) \
|
||||
(hsts_is_scheme_valid (scheme) && hsts_is_host_name_valid (host))
|
||||
|
||||
#define DEFAULT_HTTP_PORT 80
|
||||
#define DEFAULT_SSL_PORT 443
|
||||
#define CHECK_EXPLICIT_PORT(p1, p2) (p1 == 0 || p1 == p2)
|
||||
#define MAKE_EXPLICIT_PORT(s, p) (s == SCHEME_HTTPS ? (p == DEFAULT_SSL_PORT ? 0 : p) \
|
||||
: (p == DEFAULT_HTTP_PORT ? 0 : p))
|
||||
|
||||
/* Hashing and comparison functions for the hash table */
|
||||
|
||||
static unsigned long
|
||||
hsts_hash_func (const void *key)
|
||||
{
|
||||
struct hsts_kh *k = (struct hsts_kh *) key;
|
||||
const char *h = NULL;
|
||||
unsigned int hash = k->explicit_port;
|
||||
|
||||
for (h = k->host; *h; h++)
|
||||
hash = hash * 31 + *h;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
static int
|
||||
hsts_cmp_func (const void *h1, const void *h2)
|
||||
{
|
||||
struct hsts_kh *kh1 = (struct hsts_kh *) h1,
|
||||
*kh2 = (struct hsts_kh *) h2;
|
||||
|
||||
return (!strcmp (kh1->host, kh2->host)) && (kh1->explicit_port == kh2->explicit_port);
|
||||
}
|
||||
|
||||
/* Private functions. Feel free to make some of these public when needed. */
|
||||
|
||||
static struct hsts_kh_info *
|
||||
hsts_find_entry (hsts_store_t store,
|
||||
const char *host, int explicit_port,
|
||||
enum hsts_kh_match *match_type,
|
||||
struct hsts_kh *kh)
|
||||
{
|
||||
struct hsts_kh *k = NULL;
|
||||
struct hsts_kh_info *khi = NULL;
|
||||
enum hsts_kh_match match = NO_MATCH;
|
||||
char *pos = NULL;
|
||||
char *org_ptr = NULL;
|
||||
|
||||
k = (struct hsts_kh *) xnew (struct hsts_kh);
|
||||
k->host = xstrdup_lower (host);
|
||||
k->explicit_port = explicit_port;
|
||||
|
||||
/* save pointer so that we don't get into trouble later when freeing */
|
||||
org_ptr = k->host;
|
||||
|
||||
khi = (struct hsts_kh_info *) hash_table_get (store->table, k);
|
||||
if (khi)
|
||||
{
|
||||
match = CONGRUENT_MATCH;
|
||||
goto end;
|
||||
}
|
||||
|
||||
while (match == NO_MATCH &&
|
||||
(pos = strchr (k->host, '.')) && pos - k->host > 0 &&
|
||||
strchr (pos + 1, '.'))
|
||||
{
|
||||
k->host += (pos - k->host + 1);
|
||||
khi = (struct hsts_kh_info *) hash_table_get (store->table, k);
|
||||
if (khi)
|
||||
match = SUPERDOMAIN_MATCH;
|
||||
}
|
||||
|
||||
end:
|
||||
/* restore pointer or we'll get a SEGV */
|
||||
k->host = org_ptr;
|
||||
|
||||
/* copy parameters to previous frame */
|
||||
if (match_type)
|
||||
*match_type = match;
|
||||
if (kh)
|
||||
memcpy (kh, k, sizeof (struct hsts_kh));
|
||||
else
|
||||
xfree (k->host);
|
||||
|
||||
xfree (k);
|
||||
return khi;
|
||||
}
|
||||
|
||||
static bool
|
||||
hsts_new_entry_internal (hsts_store_t store,
|
||||
const char *host, int port,
|
||||
time_t created, time_t max_age,
|
||||
bool include_subdomains,
|
||||
bool check_validity,
|
||||
bool check_expired,
|
||||
bool check_duplicates)
|
||||
{
|
||||
struct hsts_kh *kh = xnew (struct hsts_kh);
|
||||
struct hsts_kh_info *khi = xnew0 (struct hsts_kh_info);
|
||||
bool success = false;
|
||||
|
||||
kh->host = xstrdup_lower (host);
|
||||
kh->explicit_port = MAKE_EXPLICIT_PORT (SCHEME_HTTPS, port);
|
||||
|
||||
khi->created = created;
|
||||
khi->max_age = max_age;
|
||||
khi->include_subdomains = include_subdomains;
|
||||
|
||||
/* Check validity */
|
||||
if (check_validity && !hsts_is_host_name_valid (host))
|
||||
goto bail;
|
||||
|
||||
if (check_expired && ((khi->created + khi->max_age) < khi->created))
|
||||
goto bail;
|
||||
|
||||
if (check_duplicates && hash_table_contains (store->table, kh))
|
||||
goto bail;
|
||||
|
||||
/* Now store the new entry */
|
||||
hash_table_put (store->table, kh, khi);
|
||||
success = true;
|
||||
|
||||
bail:
|
||||
if (!success)
|
||||
{
|
||||
/* abort! */
|
||||
xfree (kh->host);
|
||||
xfree (kh);
|
||||
xfree (khi);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/*
|
||||
Creates a new entry, but does not check whether that entry already exists.
|
||||
This function assumes that check has already been done by the caller.
|
||||
*/
|
||||
static bool
|
||||
hsts_add_entry (hsts_store_t store,
|
||||
const char *host, int port,
|
||||
time_t max_age, bool include_subdomains)
|
||||
{
|
||||
time_t t = time (NULL);
|
||||
|
||||
/* It might happen time() returned -1 */
|
||||
return (t < 0 ?
|
||||
false :
|
||||
hsts_new_entry_internal (store, host, port, t, max_age, include_subdomains, false, true, false));
|
||||
}
|
||||
|
||||
/* Creates a new entry, unless an identical one already exists. */
|
||||
static bool
|
||||
hsts_new_entry (hsts_store_t store,
|
||||
const char *host, int port,
|
||||
time_t created, time_t max_age,
|
||||
bool include_subdomains)
|
||||
{
|
||||
return hsts_new_entry_internal (store, host, port, created, max_age, include_subdomains, true, true, true);
|
||||
}
|
||||
|
||||
static void
|
||||
hsts_remove_entry (hsts_store_t store, struct hsts_kh *kh)
|
||||
{
|
||||
hash_table_remove (store->table, kh);
|
||||
}
|
||||
|
||||
static bool
|
||||
hsts_store_merge (hsts_store_t store,
|
||||
const char *host, int port,
|
||||
time_t created, time_t max_age,
|
||||
bool include_subdomains)
|
||||
{
|
||||
enum hsts_kh_match match_type = NO_MATCH;
|
||||
struct hsts_kh_info *khi = NULL;
|
||||
bool success = false;
|
||||
|
||||
port = MAKE_EXPLICIT_PORT (SCHEME_HTTPS, port);
|
||||
khi = hsts_find_entry (store, host, port, &match_type, NULL);
|
||||
if (khi && match_type == CONGRUENT_MATCH && created > khi->created)
|
||||
{
|
||||
/* update the entry with the new info */
|
||||
khi->created = created;
|
||||
khi->max_age = max_age;
|
||||
khi->include_subdomains = include_subdomains;
|
||||
|
||||
success = true;
|
||||
}
|
||||
else if (!khi)
|
||||
success = hsts_new_entry (store, host, port, created, max_age, include_subdomains);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool
|
||||
hsts_read_database (hsts_store_t store, FILE *fp, bool merge_with_existing_entries)
|
||||
{
|
||||
char *line = NULL, *p;
|
||||
size_t len = 0;
|
||||
int items_read;
|
||||
bool result = false;
|
||||
bool (*func)(hsts_store_t, const char *, int, time_t, time_t, bool);
|
||||
|
||||
char host[256];
|
||||
int port;
|
||||
time_t created, max_age;
|
||||
int include_subdomains;
|
||||
|
||||
func = (merge_with_existing_entries ? hsts_store_merge : hsts_new_entry);
|
||||
|
||||
while (getline (&line, &len, fp) > 0)
|
||||
{
|
||||
for (p = line; c_isspace (*p); p++)
|
||||
;
|
||||
|
||||
if (*p == '#')
|
||||
continue;
|
||||
|
||||
items_read = sscanf (p, "%255s %d %d %lu %lu",
|
||||
host,
|
||||
&port,
|
||||
&include_subdomains,
|
||||
(unsigned long *) &created,
|
||||
(unsigned long *) &max_age);
|
||||
|
||||
if (items_read == 5)
|
||||
func (store, host, port, created, max_age, !!include_subdomains);
|
||||
}
|
||||
|
||||
xfree (line);
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
hsts_store_dump (hsts_store_t store, FILE *fp)
|
||||
{
|
||||
hash_table_iterator it;
|
||||
|
||||
/* Print preliminary comments. We don't care if any of these fail. */
|
||||
fputs ("# HSTS 1.0 Known Hosts database for GNU Wget.\n", fp);
|
||||
fputs ("# Edit at your own risk.\n", fp);
|
||||
fputs ("# <hostname>\t<port>\t<incl. subdomains>\t<created>\t<max-age>\n", fp);
|
||||
|
||||
/* Now cycle through the HSTS store in memory and dump the entries */
|
||||
for (hash_table_iterate (store->table, &it); hash_table_iter_next (&it);)
|
||||
{
|
||||
struct hsts_kh *kh = (struct hsts_kh *) it.key;
|
||||
struct hsts_kh_info *khi = (struct hsts_kh_info *) it.value;
|
||||
|
||||
if (fprintf (fp, "%s\t%d\t%d\t%lu\t%lu\n",
|
||||
kh->host, kh->explicit_port, khi->include_subdomains,
|
||||
khi->created, khi->max_age) < 0)
|
||||
{
|
||||
logprintf (LOG_ALWAYS, "Could not write the HSTS database correctly.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test:
|
||||
* - The file is a regular file (ie. not a symlink), and
|
||||
* - The file is not world-writable.
|
||||
*/
|
||||
static bool
|
||||
hsts_file_access_valid (const char *filename)
|
||||
{
|
||||
struct_stat st;
|
||||
|
||||
if (stat (filename, &st) == -1)
|
||||
return false;
|
||||
|
||||
return !(st.st_mode & S_IWOTH) && S_ISREG (st.st_mode);
|
||||
}
|
||||
|
||||
/* HSTS API */
|
||||
|
||||
/*
|
||||
Changes the given URLs according to the HSTS policy.
|
||||
|
||||
If there's no host in the store that either congruently
|
||||
or not, matches the given URL, no changes are made.
|
||||
Returns true if the URL was changed, or false
|
||||
if it was left intact.
|
||||
*/
|
||||
bool
|
||||
hsts_match (hsts_store_t store, struct url *u)
|
||||
{
|
||||
bool url_changed = false;
|
||||
struct hsts_kh_info *entry = NULL;
|
||||
struct hsts_kh *kh = xnew(struct hsts_kh);
|
||||
enum hsts_kh_match match = NO_MATCH;
|
||||
int port = MAKE_EXPLICIT_PORT (u->scheme, u->port);
|
||||
|
||||
/* avoid doing any computation if we're already in HTTPS */
|
||||
if (!hsts_is_scheme_valid (u->scheme))
|
||||
{
|
||||
entry = hsts_find_entry (store, u->host, port, &match, kh);
|
||||
if (entry)
|
||||
{
|
||||
if ((entry->created + entry->max_age) >= time(NULL))
|
||||
{
|
||||
if ((match == CONGRUENT_MATCH) ||
|
||||
(match == SUPERDOMAIN_MATCH && entry->include_subdomains))
|
||||
{
|
||||
/* we found a matching Known HSTS Host
|
||||
rewrite the URL */
|
||||
u->scheme = SCHEME_HTTPS;
|
||||
if (u->port == 80)
|
||||
u->port = 443;
|
||||
url_changed = true;
|
||||
store->changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hsts_remove_entry (store, kh);
|
||||
store->changed = true;
|
||||
}
|
||||
}
|
||||
xfree (kh->host);
|
||||
}
|
||||
|
||||
xfree (kh);
|
||||
|
||||
return url_changed;
|
||||
}
|
||||
|
||||
/*
|
||||
Add a new HSTS Known Host to the HSTS store.
|
||||
|
||||
If the host already exists, its information is updated,
|
||||
or it'll be removed from the store if max_age is zero.
|
||||
|
||||
Bear in mind that the store is kept in memory, and will not
|
||||
be written to disk until hsts_store_save is called.
|
||||
This function regrows the in-memory HSTS store if necessary.
|
||||
|
||||
Currently, for a host to be taken into consideration,
|
||||
two conditions have to be met:
|
||||
- Connection must be through a secure channel (HTTPS).
|
||||
- The host must not be an IPv4 or IPv6 address.
|
||||
|
||||
The RFC 6797 states that hosts that match IPv4 or IPv6 format
|
||||
should be discarded at URI rewrite time. But we short-circuit
|
||||
that check here, since there's no point in storing a host that
|
||||
will never be matched.
|
||||
|
||||
Returns true if a new entry was actually created, or false
|
||||
if an existing entry was updated/deleted. */
|
||||
bool
|
||||
hsts_store_entry (hsts_store_t store,
|
||||
enum url_scheme scheme, const char *host, int port,
|
||||
time_t max_age, bool include_subdomains)
|
||||
{
|
||||
bool result = false;
|
||||
enum hsts_kh_match match = NO_MATCH;
|
||||
struct hsts_kh *kh = xnew(struct hsts_kh);
|
||||
struct hsts_kh_info *entry = NULL;
|
||||
time_t t = 0;
|
||||
|
||||
if (hsts_is_host_eligible (scheme, host))
|
||||
{
|
||||
port = MAKE_EXPLICIT_PORT (scheme, port);
|
||||
entry = hsts_find_entry (store, host, port, &match, kh);
|
||||
if (entry && match == CONGRUENT_MATCH)
|
||||
{
|
||||
if (max_age == 0)
|
||||
{
|
||||
hsts_remove_entry (store, kh);
|
||||
store->changed = true;
|
||||
}
|
||||
else if (max_age > 0)
|
||||
{
|
||||
if (entry->max_age != max_age ||
|
||||
entry->include_subdomains != include_subdomains)
|
||||
{
|
||||
/* RFC 6797 states that 'max_age' is a TTL relative to the reception of the STS header
|
||||
so we have to update the 'created' field too */
|
||||
t = time (NULL);
|
||||
if (t != -1)
|
||||
entry->created = t;
|
||||
entry->max_age = max_age;
|
||||
entry->include_subdomains = include_subdomains;
|
||||
|
||||
store->changed = true;
|
||||
}
|
||||
}
|
||||
/* we ignore negative max_ages */
|
||||
}
|
||||
else if (entry == NULL || match == SUPERDOMAIN_MATCH)
|
||||
{
|
||||
/* Either we didn't find a matching host,
|
||||
or we got a superdomain match.
|
||||
In either case, we create a new entry.
|
||||
|
||||
We have to perform an explicit check because it might
|
||||
happen we got a non-existent entry with max_age == 0.
|
||||
*/
|
||||
result = hsts_add_entry (store, host, port, max_age, include_subdomains);
|
||||
if (result)
|
||||
store->changed = true;
|
||||
}
|
||||
/* we ignore new entries with max_age == 0 */
|
||||
xfree (kh->host);
|
||||
}
|
||||
|
||||
xfree (kh);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
hsts_store_t
|
||||
hsts_store_open (const char *filename)
|
||||
{
|
||||
hsts_store_t store = NULL;
|
||||
|
||||
store = xnew0 (struct hsts_store);
|
||||
store->table = hash_table_new (0, hsts_hash_func, hsts_cmp_func);
|
||||
store->last_mtime = 0;
|
||||
store->changed = false;
|
||||
|
||||
if (file_exists_p (filename))
|
||||
{
|
||||
if (hsts_file_access_valid (filename))
|
||||
{
|
||||
struct_stat st;
|
||||
FILE *fp = fopen (filename, "r");
|
||||
|
||||
if (!fp || !hsts_read_database (store, fp, false))
|
||||
{
|
||||
/* abort! */
|
||||
hsts_store_close (store);
|
||||
xfree (store);
|
||||
fclose (fp);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (fstat (fileno (fp), &st) == 0)
|
||||
store->last_mtime = st.st_mtime;
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If we're not reading the HSTS database,
|
||||
* then by all means act as if HSTS was disabled.
|
||||
*/
|
||||
hsts_store_close (store);
|
||||
xfree (store);
|
||||
|
||||
logprintf (LOG_NOTQUIET, "Will not apply HSTS. "
|
||||
"The HSTS database must be a regular and non-world-writable file.\n");
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return store;
|
||||
}
|
||||
|
||||
void
|
||||
hsts_store_save (hsts_store_t store, const char *filename)
|
||||
{
|
||||
struct_stat st;
|
||||
FILE *fp = NULL;
|
||||
int fd = 0;
|
||||
|
||||
if (filename && hash_table_count (store->table) > 0)
|
||||
{
|
||||
fp = fopen (filename, "a+");
|
||||
if (fp)
|
||||
{
|
||||
/* Lock the file to avoid potential race conditions */
|
||||
fd = fileno (fp);
|
||||
flock (fd, LOCK_EX);
|
||||
|
||||
/* If the file has changed, merge the changes with our in-memory data
|
||||
before dumping them to the file.
|
||||
Otherwise we could potentially overwrite the data stored by other Wget processes.
|
||||
*/
|
||||
if (store->last_mtime && stat (filename, &st) == 0 && st.st_mtime > store->last_mtime)
|
||||
hsts_read_database (store, fp, true);
|
||||
|
||||
/* We've merged the latest changes so we can now truncate the file
|
||||
and dump everything. */
|
||||
fseek (fp, 0, SEEK_SET);
|
||||
ftruncate (fd, 0);
|
||||
|
||||
/* now dump to the file */
|
||||
hsts_store_dump (store, fp);
|
||||
|
||||
/* fclose is expected to unlock the file for us */
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
hsts_store_has_changed (hsts_store_t store)
|
||||
{
|
||||
return (store ? store->changed : false);
|
||||
}
|
||||
|
||||
void
|
||||
hsts_store_close (hsts_store_t store)
|
||||
{
|
||||
hash_table_iterator it;
|
||||
|
||||
/* free all the host fields */
|
||||
for (hash_table_iterate (store->table, &it); hash_table_iter_next (&it);)
|
||||
{
|
||||
xfree (((struct hsts_kh *) it.key)->host);
|
||||
xfree (it.key);
|
||||
xfree (it.value);
|
||||
}
|
||||
|
||||
hash_table_destroy (store->table);
|
||||
}
|
||||
|
||||
#ifdef TESTING
|
||||
/* I know I'm really evil because I'm writing macros
|
||||
that change control flow. But we're testing, who will tell? :D
|
||||
*/
|
||||
#define TEST_URL_RW(s, u, p) do { \
|
||||
if (test_url_rewrite (s, u, p, true)) \
|
||||
return test_url_rewrite (s, u, p, true); \
|
||||
} while (0)
|
||||
|
||||
#define TEST_URL_NORW(s, u, p) do { \
|
||||
if (test_url_rewrite (s, u, p, false)) \
|
||||
return test_url_rewrite (s, u, p, false); \
|
||||
} while (0)
|
||||
|
||||
static char *
|
||||
get_hsts_store_filename (void)
|
||||
{
|
||||
char *home = NULL, *filename = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
home = home_dir ();
|
||||
if (home)
|
||||
{
|
||||
filename = aprintf ("%s/.wget-hsts-test", home);
|
||||
fp = fopen (filename, "w");
|
||||
if (fp)
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
xfree (home);
|
||||
return filename;
|
||||
}
|
||||
|
||||
static hsts_store_t
|
||||
open_hsts_test_store (void)
|
||||
{
|
||||
char *filename = NULL;
|
||||
hsts_store_t table = NULL;
|
||||
|
||||
filename = get_hsts_store_filename ();
|
||||
table = hsts_store_open (filename);
|
||||
xfree (filename);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
static void
|
||||
close_hsts_test_store (hsts_store_t store)
|
||||
{
|
||||
char *filename = NULL;
|
||||
|
||||
filename = get_hsts_store_filename ();
|
||||
unlink (filename);
|
||||
xfree (filename);
|
||||
xfree (store);
|
||||
}
|
||||
|
||||
static const char*
|
||||
test_url_rewrite (hsts_store_t s, const char *url, int port, bool rewrite)
|
||||
{
|
||||
bool result;
|
||||
struct url u;
|
||||
|
||||
u.host = xstrdup (url);
|
||||
u.port = port;
|
||||
u.scheme = SCHEME_HTTP;
|
||||
|
||||
result = hsts_match (s, &u);
|
||||
|
||||
if (rewrite)
|
||||
{
|
||||
if (port == 80)
|
||||
mu_assert("URL: port should've been rewritten to 443", u.port == 443);
|
||||
else
|
||||
mu_assert("URL: port should've been left intact", u.port == port);
|
||||
mu_assert("URL: scheme should've been rewritten to HTTPS", u.scheme == SCHEME_HTTPS);
|
||||
mu_assert("result should've been true", result == true);
|
||||
}
|
||||
else
|
||||
{
|
||||
mu_assert("URL: port should've been left intact", u.port == port);
|
||||
mu_assert("URL: scheme should've been left intact", u.scheme == SCHEME_HTTP);
|
||||
mu_assert("result should've been false", result == false);
|
||||
}
|
||||
|
||||
xfree (u.host);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
test_hsts_new_entry (void)
|
||||
{
|
||||
enum hsts_kh_match match = NO_MATCH;
|
||||
struct hsts_kh_info *khi;
|
||||
hsts_store_t s;
|
||||
bool created;
|
||||
|
||||
s = open_hsts_test_store ();
|
||||
mu_assert("Could not open the HSTS store. This could be due to lack of memory.", s != NULL);
|
||||
|
||||
created = hsts_store_entry (s, SCHEME_HTTP, "www.foo.com", 80, 1234, true);
|
||||
mu_assert("No entry should have been created.", created == false);
|
||||
|
||||
created = hsts_store_entry (s, SCHEME_HTTPS, "www.foo.com", 443, 1234, true);
|
||||
mu_assert("A new entry should have been created", created == true);
|
||||
|
||||
khi = hsts_find_entry (s, "www.foo.com", MAKE_EXPLICIT_PORT (SCHEME_HTTPS, 443), &match, NULL);
|
||||
mu_assert("Should've been a congruent match", match == CONGRUENT_MATCH);
|
||||
mu_assert("No valid HSTS info was returned", khi != NULL);
|
||||
mu_assert("Variable 'max_age' should be 1234", khi->max_age == 1234);
|
||||
mu_assert("Variable 'include_subdomains' should be asserted", khi->include_subdomains == true);
|
||||
|
||||
khi = hsts_find_entry (s, "b.www.foo.com", MAKE_EXPLICIT_PORT (SCHEME_HTTPS, 443), &match, NULL);
|
||||
mu_assert("Should've been a superdomain match", match == SUPERDOMAIN_MATCH);
|
||||
mu_assert("No valid HSTS info was returned", khi != NULL);
|
||||
mu_assert("Variable 'max_age' should be 1234", khi->max_age == 1234);
|
||||
mu_assert("Variable 'include_subdomains' should be asserted", khi->include_subdomains == true);
|
||||
|
||||
khi = hsts_find_entry (s, "ww.foo.com", MAKE_EXPLICIT_PORT (SCHEME_HTTPS, 443), &match, NULL);
|
||||
mu_assert("Should've been no match", match == NO_MATCH);
|
||||
|
||||
khi = hsts_find_entry (s, "foo.com", MAKE_EXPLICIT_PORT (SCHEME_HTTPS, 443), &match, NULL);
|
||||
mu_assert("Should've been no match", match == NO_MATCH);
|
||||
|
||||
khi = hsts_find_entry (s, ".foo.com", MAKE_EXPLICIT_PORT (SCHEME_HTTPS, 443), &match, NULL);
|
||||
mu_assert("Should've been no match", match == NO_MATCH);
|
||||
|
||||
khi = hsts_find_entry (s, ".www.foo.com", MAKE_EXPLICIT_PORT (SCHEME_HTTPS, 443), &match, NULL);
|
||||
mu_assert("Should've been no match", match == NO_MATCH);
|
||||
|
||||
hsts_store_close (s);
|
||||
close_hsts_test_store (s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
test_hsts_url_rewrite_superdomain (void)
|
||||
{
|
||||
hsts_store_t s;
|
||||
bool created;
|
||||
|
||||
s = open_hsts_test_store ();
|
||||
mu_assert("Could not open the HSTS store", s != NULL);
|
||||
|
||||
created = hsts_store_entry (s, SCHEME_HTTPS, "www.foo.com", 443, 1234, true);
|
||||
mu_assert("A new entry should've been created", created == true);
|
||||
|
||||
TEST_URL_RW (s, "www.foo.com", 80);
|
||||
TEST_URL_RW (s, "bar.www.foo.com", 80);
|
||||
|
||||
hsts_store_close (s);
|
||||
close_hsts_test_store (s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
test_hsts_url_rewrite_congruent (void)
|
||||
{
|
||||
hsts_store_t s;
|
||||
bool created;
|
||||
|
||||
s = open_hsts_test_store ();
|
||||
mu_assert("Could not open the HSTS store", s != NULL);
|
||||
|
||||
created = hsts_store_entry (s, SCHEME_HTTPS, "foo.com", 443, 1234, false);
|
||||
mu_assert("A new entry should've been created", created == true);
|
||||
|
||||
TEST_URL_RW (s, "foo.com", 80);
|
||||
TEST_URL_NORW (s, "www.foo.com", 80);
|
||||
|
||||
hsts_store_close (s);
|
||||
close_hsts_test_store (s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
test_hsts_read_database (void)
|
||||
{
|
||||
hsts_store_t table;
|
||||
char *home = home_dir();
|
||||
char *file = NULL;
|
||||
FILE *fp = NULL;
|
||||
time_t created = time(NULL) - 10;
|
||||
|
||||
if (home)
|
||||
{
|
||||
file = aprintf ("%s/.wget-hsts-testing", home);
|
||||
fp = fopen (file, "w");
|
||||
if (fp)
|
||||
{
|
||||
fputs ("# dummy comment\n", fp);
|
||||
fprintf (fp, "foo.example.com\t0\t1\t%ld\t123\n",(long) created);
|
||||
fprintf (fp, "bar.example.com\t0\t0\t%ld\t456\n", (long) created);
|
||||
fprintf (fp, "test.example.com\t8080\t0\t%ld\t789\n", (long) created);
|
||||
fclose (fp);
|
||||
|
||||
table = hsts_store_open (file);
|
||||
|
||||
TEST_URL_RW (table, "foo.example.com", 80);
|
||||
TEST_URL_RW (table, "www.foo.example.com", 80);
|
||||
TEST_URL_RW (table, "bar.example.com", 80);
|
||||
|
||||
TEST_URL_NORW(table, "www.bar.example.com", 80);
|
||||
|
||||
TEST_URL_RW (table, "test.example.com", 8080);
|
||||
|
||||
hsts_store_close (table);
|
||||
close_hsts_test_store (table);
|
||||
unlink (file);
|
||||
}
|
||||
xfree (file);
|
||||
xfree (home);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif /* TESTING */
|
||||
#endif /* HAVE_HSTS */
|
||||
54
src/hsts.h
Normal file
54
src/hsts.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* Declarations for hsts.c
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
GNU Wget 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.
|
||||
|
||||
GNU Wget 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 Wget. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this program, or any covered work, by linking or
|
||||
combining it with the OpenSSL project's OpenSSL library (or a
|
||||
modified version of that library), containing parts covered by the
|
||||
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
|
||||
grants you additional permission to convey the resulting work.
|
||||
Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work. */
|
||||
#include "wget.h"
|
||||
|
||||
#ifdef HAVE_HSTS
|
||||
|
||||
#ifndef HSTS_H
|
||||
#define HSTS_H
|
||||
|
||||
#include "url.h"
|
||||
|
||||
typedef struct hsts_store *hsts_store_t;
|
||||
|
||||
hsts_store_t hsts_store_open (const char *);
|
||||
|
||||
void hsts_store_save (hsts_store_t, const char *);
|
||||
void hsts_store_close (hsts_store_t);
|
||||
bool hsts_store_has_changed (hsts_store_t);
|
||||
|
||||
bool hsts_store_entry (hsts_store_t,
|
||||
enum url_scheme, const char *, int,
|
||||
time_t, bool);
|
||||
bool hsts_match (hsts_store_t, struct url *);
|
||||
|
||||
#endif /* HSTS_H */
|
||||
#endif /* HAVE_HSTS */
|
||||
@@ -1,6 +1,6 @@
|
||||
/* HTML parser for Wget.
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
2007, 2008, 2009, 2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -253,7 +253,7 @@ struct pool {
|
||||
(sizevar) = ga_newsize; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Test whether n+1-sized entity name fits in P. We don't support
|
||||
IE-style non-terminated entities, e.g. "<foo" -> "<foo".
|
||||
However, "<foo" will work, as will "<!foo", "<", etc. In
|
||||
@@ -517,7 +517,7 @@ convert_and_copy (struct pool *pool, const char *beg, const char *end, int flags
|
||||
*p = c_tolower (*p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Originally we used to adhere to rfc 1866 here, and allowed only
|
||||
letters, digits, periods, and hyphens as names (of tags or
|
||||
attributes). However, this broke too many pages which used
|
||||
@@ -770,7 +770,7 @@ find_comment_end (const char *beg, const char *end)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Return true if the string containing of characters inside [b, e) is
|
||||
present in hash table HT. */
|
||||
|
||||
@@ -881,7 +881,7 @@ map_html_tags (const char *text, int size,
|
||||
if (*p == '!')
|
||||
{
|
||||
if (!(flags & MHT_STRICT_COMMENTS)
|
||||
&& p < end + 3 && p[1] == '-' && p[2] == '-')
|
||||
&& p + 3 < end && p[1] == '-' && p[2] == '-')
|
||||
{
|
||||
/* If strict comments are not enforced and if we know
|
||||
we're looking at a comment, simply look for the
|
||||
@@ -1167,7 +1167,7 @@ map_html_tags (const char *text, int size,
|
||||
#undef ADVANCE
|
||||
#undef SKIP_WS
|
||||
#undef SKIP_NON_WS
|
||||
|
||||
|
||||
#ifdef STANDALONE
|
||||
static void
|
||||
test_mapper (struct taginfo *taginfo, void *arg)
|
||||
@@ -1189,6 +1189,14 @@ int main ()
|
||||
int read_count;
|
||||
int tag_counter = 0;
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
/* Set the current locale. */
|
||||
setlocale (LC_ALL, "");
|
||||
/* Set the text message domain. */
|
||||
bindtextdomain ("wget", LOCALEDIR);
|
||||
textdomain ("wget");
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
while ((read_count = fread (x + length, 1, size - length, stdin)))
|
||||
{
|
||||
length += read_count;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Declarations for html-parse.c.
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
2007, 2008, 2009, 2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -32,8 +32,8 @@ as that of the covered work. */
|
||||
#define HTML_PARSE_H
|
||||
|
||||
struct attr_pair {
|
||||
char *name; /* attribute name */
|
||||
char *value; /* attribute value */
|
||||
char *name; /* attribute name */
|
||||
char *value; /* attribute value */
|
||||
|
||||
/* Needed for URL conversion; the places where the value begins and
|
||||
ends, including the quotes and everything. */
|
||||
@@ -45,19 +45,19 @@ struct attr_pair {
|
||||
};
|
||||
|
||||
struct taginfo {
|
||||
char *name; /* tag name */
|
||||
int end_tag_p; /* whether this is an end-tag */
|
||||
int nattrs; /* number of attributes */
|
||||
struct attr_pair *attrs; /* attributes */
|
||||
char *name; /* tag name */
|
||||
int end_tag_p; /* whether this is an end-tag */
|
||||
int nattrs; /* number of attributes */
|
||||
struct attr_pair *attrs; /* attributes */
|
||||
|
||||
const char *start_position; /* start position of tag */
|
||||
const char *end_position; /* end position of tag */
|
||||
const char *start_position; /* start position of tag */
|
||||
const char *end_position; /* end position of tag */
|
||||
|
||||
const char *contents_begin; /* delimiters of tag contents */
|
||||
const char *contents_end; /* only valid if end_tag_p */
|
||||
};
|
||||
|
||||
struct hash_table; /* forward declaration */
|
||||
struct hash_table; /* forward declaration */
|
||||
|
||||
/* Flags for map_html_tags: */
|
||||
#define MHT_STRICT_COMMENTS 1 /* use strict comment interpretation */
|
||||
@@ -65,7 +65,7 @@ struct hash_table; /* forward declaration */
|
||||
<a href=" foo "> as "foo" */
|
||||
|
||||
void map_html_tags (const char *, int,
|
||||
void (*) (struct taginfo *, void *), void *, int,
|
||||
const struct hash_table *, const struct hash_table *);
|
||||
void (*) (struct taginfo *, void *), void *, int,
|
||||
const struct hash_table *, const struct hash_table *);
|
||||
|
||||
#endif /* HTML_PARSE_H */
|
||||
|
||||
178
src/html-url.c
178
src/html-url.c
@@ -1,6 +1,7 @@
|
||||
/* Collect URLs from HTML source.
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||
2007, 2008, 2009, 2010, 2011, 2012, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -45,6 +46,7 @@ as that of the covered work. */
|
||||
#include "recur.h"
|
||||
#include "html-url.h"
|
||||
#include "css-url.h"
|
||||
#include "c-strcase.h"
|
||||
|
||||
typedef void (*tag_handler_t) (int, struct taginfo *, struct map_context *);
|
||||
|
||||
@@ -54,6 +56,7 @@ typedef void (*tag_handler_t) (int, struct taginfo *, struct map_context *);
|
||||
DECLARE_TAG_HANDLER (tag_find_urls);
|
||||
DECLARE_TAG_HANDLER (tag_handle_base);
|
||||
DECLARE_TAG_HANDLER (tag_handle_form);
|
||||
DECLARE_TAG_HANDLER (tag_handle_img);
|
||||
DECLARE_TAG_HANDLER (tag_handle_link);
|
||||
DECLARE_TAG_HANDLER (tag_handle_meta);
|
||||
|
||||
@@ -79,7 +82,10 @@ enum {
|
||||
TAG_SCRIPT,
|
||||
TAG_TABLE,
|
||||
TAG_TD,
|
||||
TAG_TH
|
||||
TAG_TH,
|
||||
TAG_VIDEO,
|
||||
TAG_AUDIO,
|
||||
TAG_SOURCE
|
||||
};
|
||||
|
||||
/* The list of known tags and functions used for handling them. Most
|
||||
@@ -100,7 +106,7 @@ static struct known_tag {
|
||||
{ TAG_FORM, "form", tag_handle_form },
|
||||
{ TAG_FRAME, "frame", tag_find_urls },
|
||||
{ TAG_IFRAME, "iframe", tag_find_urls },
|
||||
{ TAG_IMG, "img", tag_find_urls },
|
||||
{ TAG_IMG, "img", tag_handle_img },
|
||||
{ TAG_INPUT, "input", tag_find_urls },
|
||||
{ TAG_LAYER, "layer", tag_find_urls },
|
||||
{ TAG_LINK, "link", tag_handle_link },
|
||||
@@ -110,7 +116,10 @@ static struct known_tag {
|
||||
{ TAG_SCRIPT, "script", tag_find_urls },
|
||||
{ TAG_TABLE, "table", tag_find_urls },
|
||||
{ TAG_TD, "td", tag_find_urls },
|
||||
{ TAG_TH, "th", tag_find_urls }
|
||||
{ TAG_TH, "th", tag_find_urls },
|
||||
{ TAG_VIDEO, "video", tag_find_urls },
|
||||
{ TAG_AUDIO, "audio", tag_find_urls },
|
||||
{ TAG_SOURCE, "source", tag_find_urls }
|
||||
};
|
||||
|
||||
/* tag_url_attributes documents which attributes of which tags contain
|
||||
@@ -157,7 +166,12 @@ static struct {
|
||||
{ TAG_SCRIPT, "src", ATTR_INLINE },
|
||||
{ TAG_TABLE, "background", ATTR_INLINE },
|
||||
{ TAG_TD, "background", ATTR_INLINE },
|
||||
{ TAG_TH, "background", ATTR_INLINE }
|
||||
{ TAG_TH, "background", ATTR_INLINE },
|
||||
{ TAG_VIDEO, "src", ATTR_INLINE },
|
||||
{ TAG_VIDEO, "poster", ATTR_INLINE },
|
||||
{ TAG_AUDIO, "src", ATTR_INLINE },
|
||||
{ TAG_AUDIO, "poster", ATTR_INLINE },
|
||||
{ TAG_SOURCE, "src", ATTR_INLINE }
|
||||
};
|
||||
|
||||
/* The lists of interesting tags and attributes are built dynamically,
|
||||
@@ -170,7 +184,8 @@ static const char *additional_attributes[] = {
|
||||
"name", /* used by tag_handle_meta */
|
||||
"content", /* used by tag_handle_meta */
|
||||
"action", /* used by tag_handle_form */
|
||||
"style" /* used by check_style_attr */
|
||||
"style", /* used by check_style_attr */
|
||||
"srcset", /* used by tag_handle_img */
|
||||
};
|
||||
|
||||
static struct hash_table *interesting_tags;
|
||||
@@ -244,7 +259,7 @@ find_attr (struct taginfo *tag, const char *name, int *attrind)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < tag->nattrs; i++)
|
||||
if (!strcasecmp (tag->attrs[i].name, name))
|
||||
if (!c_strcasecmp (tag->attrs[i].name, name))
|
||||
{
|
||||
if (attrind)
|
||||
*attrind = i;
|
||||
@@ -273,6 +288,10 @@ append_url (const char *link_uri, int position, int size,
|
||||
const char *base = ctx->base ? ctx->base : ctx->parent_base;
|
||||
struct url *url;
|
||||
|
||||
struct iri *iri = iri_new ();
|
||||
set_uri_encoding (iri, opt.locale, true);
|
||||
iri->utf8_encode = true;
|
||||
|
||||
if (!base)
|
||||
{
|
||||
DEBUGP (("%s: no base, merge will use \"%s\".\n",
|
||||
@@ -287,14 +306,16 @@ append_url (const char *link_uri, int position, int size,
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("%s: Cannot resolve incomplete link %s.\n"),
|
||||
ctx->document_file, link_uri);
|
||||
iri_free (iri);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
url = url_parse (link_uri, NULL, NULL, false);
|
||||
url = url_parse (link_uri, NULL, iri, false);
|
||||
if (!url)
|
||||
{
|
||||
DEBUGP (("%s: link \"%s\" doesn't parse.\n",
|
||||
ctx->document_file, link_uri));
|
||||
iri_free (iri);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -312,17 +333,20 @@ append_url (const char *link_uri, int position, int size,
|
||||
quote_n (2, link_uri),
|
||||
quotearg_n_style (3, escape_quoting_style, complete_uri)));
|
||||
|
||||
url = url_parse (complete_uri, NULL, NULL, false);
|
||||
url = url_parse (complete_uri, NULL, iri, false);
|
||||
if (!url)
|
||||
{
|
||||
DEBUGP (("%s: merged link \"%s\" doesn't parse.\n",
|
||||
ctx->document_file, complete_uri));
|
||||
xfree (complete_uri);
|
||||
iri_free (iri);
|
||||
return NULL;
|
||||
}
|
||||
xfree (complete_uri);
|
||||
}
|
||||
|
||||
iri_free (iri);
|
||||
|
||||
DEBUGP (("appending %s to urlpos.\n", quote (url->url)));
|
||||
|
||||
newel = xnew0 (struct urlpos);
|
||||
@@ -361,7 +385,7 @@ append_url (const char *link_uri, int position, int size,
|
||||
|
||||
return newel;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
check_style_attr (struct taginfo *tag, struct map_context *ctx)
|
||||
{
|
||||
@@ -455,7 +479,7 @@ tag_find_urls (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
/* Handle the BASE tag, for <base href=...>. */
|
||||
|
||||
static void
|
||||
tag_handle_base (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
tag_handle_base (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *ctx)
|
||||
{
|
||||
struct urlpos *base_urlpos;
|
||||
int attrind;
|
||||
@@ -470,8 +494,7 @@ tag_handle_base (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
base_urlpos->ignore_when_downloading = 1;
|
||||
base_urlpos->link_base_p = 1;
|
||||
|
||||
if (ctx->base)
|
||||
xfree (ctx->base);
|
||||
xfree (ctx->base);
|
||||
if (ctx->parent_base)
|
||||
ctx->base = uri_merge (ctx->parent_base, newbase);
|
||||
else
|
||||
@@ -481,7 +504,7 @@ tag_handle_base (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
/* Mark the URL found in <form action=...> for conversion. */
|
||||
|
||||
static void
|
||||
tag_handle_form (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
tag_handle_form (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *ctx)
|
||||
{
|
||||
int attrind;
|
||||
char *action = find_attr (tag, "action", &attrind);
|
||||
@@ -499,7 +522,7 @@ tag_handle_form (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
links will be followed in -p mode depends on the REL attribute. */
|
||||
|
||||
static void
|
||||
tag_handle_link (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
tag_handle_link (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *ctx)
|
||||
{
|
||||
int attrind;
|
||||
char *href = find_attr (tag, "href", &attrind);
|
||||
@@ -519,12 +542,12 @@ tag_handle_link (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
char *rel = find_attr (tag, "rel", NULL);
|
||||
if (rel)
|
||||
{
|
||||
if (0 == strcasecmp (rel, "stylesheet"))
|
||||
if (0 == c_strcasecmp (rel, "stylesheet"))
|
||||
{
|
||||
up->link_inline_p = 1;
|
||||
up->link_expect_css = 1;
|
||||
}
|
||||
else if (0 == strcasecmp (rel, "shortcut icon"))
|
||||
else if (0 == c_strcasecmp (rel, "shortcut icon"))
|
||||
{
|
||||
up->link_inline_p = 1;
|
||||
}
|
||||
@@ -536,7 +559,7 @@ tag_handle_link (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
<link rel="alternate" type="application/rss+xml" href=".../?feed=rss2" />
|
||||
*/
|
||||
char *type = find_attr (tag, "type", NULL);
|
||||
if (!type || strcasecmp (type, "text/html") == 0)
|
||||
if (!type || c_strcasecmp (type, "text/html") == 0)
|
||||
up->link_expect_html = 1;
|
||||
}
|
||||
}
|
||||
@@ -548,12 +571,12 @@ tag_handle_link (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
refresh feature and because of robot exclusion. */
|
||||
|
||||
static void
|
||||
tag_handle_meta (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
tag_handle_meta (int tagid _GL_UNUSED, struct taginfo *tag, struct map_context *ctx)
|
||||
{
|
||||
char *name = find_attr (tag, "name", NULL);
|
||||
char *http_equiv = find_attr (tag, "http-equiv", NULL);
|
||||
|
||||
if (http_equiv && 0 == strcasecmp (http_equiv, "refresh"))
|
||||
if (http_equiv && 0 == c_strcasecmp (http_equiv, "refresh"))
|
||||
{
|
||||
/* Some pages use a META tag to specify that the page be
|
||||
refreshed by a new page after a given number of seconds. The
|
||||
@@ -598,7 +621,7 @@ tag_handle_meta (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
entry->link_expect_html = 1;
|
||||
}
|
||||
}
|
||||
else if (http_equiv && 0 == strcasecmp (http_equiv, "content-type"))
|
||||
else if (http_equiv && 0 == c_strcasecmp (http_equiv, "content-type"))
|
||||
{
|
||||
/* Handle stuff like:
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=CHARSET"> */
|
||||
@@ -612,17 +635,17 @@ tag_handle_meta (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
if (!mcharset)
|
||||
return;
|
||||
|
||||
xfree_null (meta_charset);
|
||||
xfree (meta_charset);
|
||||
meta_charset = mcharset;
|
||||
}
|
||||
else if (name && 0 == strcasecmp (name, "robots"))
|
||||
else if (name && 0 == c_strcasecmp (name, "robots"))
|
||||
{
|
||||
/* Handle stuff like:
|
||||
<meta name="robots" content="index,nofollow"> */
|
||||
char *content = find_attr (tag, "content", NULL);
|
||||
if (!content)
|
||||
return;
|
||||
if (!strcasecmp (content, "none"))
|
||||
if (!c_strcasecmp (content, "none"))
|
||||
ctx->nofollow = true;
|
||||
else
|
||||
{
|
||||
@@ -634,7 +657,7 @@ tag_handle_meta (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
/* Find the next occurrence of ',' or whitespace,
|
||||
* or the end of the string. */
|
||||
end = content + strcspn (content, ", \f\n\r\t\v");
|
||||
if (!strncasecmp (content, "nofollow", end - content))
|
||||
if (!c_strncasecmp (content, "nofollow", end - content))
|
||||
ctx->nofollow = true;
|
||||
/* Skip past the next comma, if any. */
|
||||
if (*end == ',')
|
||||
@@ -653,6 +676,88 @@ tag_handle_meta (int tagid, struct taginfo *tag, struct map_context *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the IMG tag. This requires special handling for the srcset attr,
|
||||
while the traditional src/lowsrc/href attributes can be handled generically.
|
||||
*/
|
||||
|
||||
static void
|
||||
tag_handle_img (int tagid, struct taginfo *tag, struct map_context *ctx) {
|
||||
int attrind;
|
||||
char *srcset;
|
||||
|
||||
/* Use the generic approach for the attributes without special syntax. */
|
||||
tag_find_urls(tagid, tag, ctx);
|
||||
|
||||
srcset = find_attr (tag, "srcset", &attrind);
|
||||
if (srcset)
|
||||
{
|
||||
/* These are relative to the input text. */
|
||||
int base_ind = ATTR_POS (tag,attrind,ctx);
|
||||
int size = strlen (srcset);
|
||||
|
||||
/* These are relative to srcset. */
|
||||
int offset, url_start, url_end;
|
||||
|
||||
/* Make sure to line up base_ind with srcset[0], not outside quotes. */
|
||||
if (ctx->text[base_ind] == '"' || ctx->text[base_ind] == '\'')
|
||||
++base_ind;
|
||||
|
||||
offset = 0;
|
||||
while (offset < size)
|
||||
{
|
||||
bool has_descriptor = true;
|
||||
|
||||
/* Skip over initial whitespace and commas. Note there is no \v
|
||||
in HTML5 whitespace. */
|
||||
url_start = offset + strspn (srcset + offset, " \f\n\r\t,");
|
||||
|
||||
if (url_start == size)
|
||||
return;
|
||||
|
||||
/* URL is any non-whitespace chars (including commas) - but with
|
||||
trailing commas removed. */
|
||||
url_end = url_start + strcspn (srcset + url_start, " \f\n\r\t");
|
||||
while ((url_end - 1) > url_start && srcset[url_end - 1] == ',')
|
||||
{
|
||||
has_descriptor = false;
|
||||
--url_end;
|
||||
}
|
||||
|
||||
if (url_end > url_start)
|
||||
{
|
||||
char *url_text = strdupdelim (srcset + url_start,
|
||||
srcset + url_end);
|
||||
struct urlpos *up = append_url (url_text, base_ind + url_start,
|
||||
url_end - url_start, ctx);
|
||||
up->link_inline_p = 1;
|
||||
up->link_noquote_html_p = 1;
|
||||
xfree (url_text);
|
||||
}
|
||||
|
||||
/* If the URL wasn't terminated by a , there may also be a descriptor
|
||||
which we just skip. */
|
||||
if (has_descriptor)
|
||||
{
|
||||
/* This is comma-terminated, except there may be one level of
|
||||
parentheses escaping that. */
|
||||
bool in_paren = false;
|
||||
for (offset = url_end; offset < size; ++offset)
|
||||
{
|
||||
char c = srcset[offset];
|
||||
if (c == '(')
|
||||
in_paren = true;
|
||||
else if (c == ')' && in_paren)
|
||||
in_paren = false;
|
||||
else if (c == ',' && !in_paren)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
offset = url_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Dispatch the tag handler appropriate for the tag we're mapping
|
||||
over. See known_tags[] for definition of tag handlers. */
|
||||
|
||||
@@ -675,7 +780,7 @@ collect_tags_mapper (struct taginfo *tag, void *arg)
|
||||
|
||||
check_style_attr (tag, ctx);
|
||||
|
||||
if (tag->end_tag_p && (0 == strcasecmp (tag->name, "style"))
|
||||
if (tag->end_tag_p && (0 == c_strcasecmp (tag->name, "style"))
|
||||
&& tag->contents_begin && tag->contents_end
|
||||
&& tag->contents_begin <= tag->contents_end)
|
||||
{
|
||||
@@ -684,7 +789,7 @@ collect_tags_mapper (struct taginfo *tag, void *arg)
|
||||
tag->contents_end - tag->contents_begin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Analyze HTML tags FILE and construct a list of URLs referenced from
|
||||
it. It merges relative links in FILE with URL. It is aware of
|
||||
<base href=...> and does the right thing. */
|
||||
@@ -731,15 +836,18 @@ get_urls_html (const char *file, const char *url, bool *meta_disallow_follow,
|
||||
map_html_tags (fm->content, fm->length, collect_tags_mapper, &ctx, flags,
|
||||
NULL, interesting_attributes);
|
||||
|
||||
/* If meta charset isn't null, override content encoding */
|
||||
if (iri && meta_charset)
|
||||
#ifdef ENABLE_IRI
|
||||
/* Meta charset is only valid if there was no HTTP header Content-Type charset. */
|
||||
/* This is true for HTTP 1.0 and 1.1. */
|
||||
if (iri && !iri->content_encoding && meta_charset)
|
||||
set_content_encoding (iri, meta_charset);
|
||||
#endif
|
||||
|
||||
DEBUGP (("no-follow in %s: %d\n", file, ctx.nofollow));
|
||||
if (meta_disallow_follow)
|
||||
*meta_disallow_follow = ctx.nofollow;
|
||||
|
||||
xfree_null (ctx.base);
|
||||
xfree (ctx.base);
|
||||
wget_read_file_free (fm);
|
||||
return ctx.head;
|
||||
}
|
||||
@@ -770,6 +878,7 @@ get_urls_file (const char *file)
|
||||
{
|
||||
int up_error_code;
|
||||
char *url_text;
|
||||
char *new_url;
|
||||
struct urlpos *entry;
|
||||
struct url *url;
|
||||
|
||||
@@ -804,6 +913,13 @@ get_urls_file (const char *file)
|
||||
url_text = merged;
|
||||
}
|
||||
|
||||
new_url = rewrite_shorthand_url (url_text);
|
||||
if (new_url)
|
||||
{
|
||||
xfree (url_text);
|
||||
url_text = new_url;
|
||||
}
|
||||
|
||||
url = url_parse (url_text, &up_error_code, NULL, false);
|
||||
if (!url)
|
||||
{
|
||||
@@ -830,7 +946,7 @@ get_urls_file (const char *file)
|
||||
return head;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
cleanup_html_url (void)
|
||||
{
|
||||
/* Destroy the hash tables. The hash table keys and values are not
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Declarations for html-url.c.
|
||||
Copyright (C) 1995, 1996, 1997, 2009, 2010, 2011 Free Software
|
||||
Copyright (C) 1995, 1996, 1997, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
@@ -32,20 +32,21 @@ as that of the covered work. */
|
||||
#define HTML_URL_H
|
||||
|
||||
struct map_context {
|
||||
char *text; /* HTML text. */
|
||||
char *base; /* Base URI of the document, possibly
|
||||
changed through <base href=...>. */
|
||||
const char *parent_base; /* Base of the current document. */
|
||||
const char *document_file; /* File name of this document. */
|
||||
bool nofollow; /* whether NOFOLLOW was specified in a
|
||||
char *text; /* HTML text. */
|
||||
char *base; /* Base URI of the document, possibly
|
||||
changed through <base href=...>. */
|
||||
const char *parent_base; /* Base of the current document. */
|
||||
const char *document_file; /* File name of this document. */
|
||||
bool nofollow; /* whether NOFOLLOW was specified in a
|
||||
<meta name=robots> tag. */
|
||||
|
||||
struct urlpos *head; /* List of URLs that is being built. */
|
||||
struct urlpos *head; /* List of URLs that is being built. */
|
||||
};
|
||||
|
||||
struct urlpos *get_urls_file (const char *);
|
||||
struct urlpos *get_urls_html (const char *, const char *, bool *, struct iri *);
|
||||
struct urlpos *append_url (const char *, int, int, struct map_context *);
|
||||
void free_urlpos (struct urlpos *);
|
||||
void cleanup_html_url (void);
|
||||
|
||||
#endif /* HTML_URL_H */
|
||||
|
||||
296
src/http-ntlm.c
296
src/http-ntlm.c
@@ -1,6 +1,6 @@
|
||||
/* NTLM code.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free
|
||||
Software Foundation, Inc.
|
||||
Contributed by Daniel Stenberg.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
@@ -42,68 +42,45 @@ as that of the covered work. */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/des.h>
|
||||
#include <openssl/md4.h>
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "http-ntlm.h"
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x00907001L
|
||||
#define DES_key_schedule des_key_schedule
|
||||
#define DES_cblock des_cblock
|
||||
#define DES_set_odd_parity des_set_odd_parity
|
||||
#define DES_set_key des_set_key
|
||||
#define DES_ecb_encrypt des_ecb_encrypt
|
||||
#ifdef HAVE_NETTLE
|
||||
# include <nettle/md4.h>
|
||||
# include <nettle/des.h>
|
||||
#else
|
||||
# include <openssl/des.h>
|
||||
# include <openssl/md4.h>
|
||||
# include <openssl/opensslv.h>
|
||||
|
||||
# if OPENSSL_VERSION_NUMBER < 0x00907001L
|
||||
# define DES_key_schedule des_key_schedule
|
||||
# define DES_cblock des_cblock
|
||||
# define DES_set_odd_parity des_set_odd_parity
|
||||
# define DES_set_key des_set_key
|
||||
# define DES_ecb_encrypt des_ecb_encrypt
|
||||
|
||||
/* This is how things were done in the old days */
|
||||
#define DESKEY(x) x
|
||||
#define DESKEYARG(x) x
|
||||
#else
|
||||
# define DESKEY(x) x
|
||||
# define DESKEYARG(x) x
|
||||
# else
|
||||
/* Modern version */
|
||||
#define DESKEYARG(x) *x
|
||||
#define DESKEY(x) &x
|
||||
# define DESKEYARG(x) *x
|
||||
# define DESKEY(x) &x
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Define this to make the type-3 message include the NT response message */
|
||||
#define USE_NTRESPONSES 1
|
||||
|
||||
|
||||
|
||||
/* Flag bits definitions available at on
|
||||
http://davenport.sourceforge.net/ntlm.html */
|
||||
|
||||
#define NTLMFLAG_NEGOTIATE_UNICODE (1<<0)
|
||||
#define NTLMFLAG_NEGOTIATE_OEM (1<<1)
|
||||
#define NTLMFLAG_REQUEST_TARGET (1<<2)
|
||||
/* unknown (1<<3) */
|
||||
#define NTLMFLAG_NEGOTIATE_SIGN (1<<4)
|
||||
#define NTLMFLAG_NEGOTIATE_SEAL (1<<5)
|
||||
#define NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE (1<<6)
|
||||
#define NTLMFLAG_NEGOTIATE_LM_KEY (1<<7)
|
||||
#define NTLMFLAG_NEGOTIATE_NETWARE (1<<8)
|
||||
#define NTLMFLAG_NEGOTIATE_NTLM_KEY (1<<9)
|
||||
/* unknown (1<<10) */
|
||||
/* unknown (1<<11) */
|
||||
#define NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED (1<<12)
|
||||
#define NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED (1<<13)
|
||||
#define NTLMFLAG_NEGOTIATE_LOCAL_CALL (1<<14)
|
||||
#define NTLMFLAG_NEGOTIATE_ALWAYS_SIGN (1<<15)
|
||||
#define NTLMFLAG_TARGET_TYPE_DOMAIN (1<<16)
|
||||
#define NTLMFLAG_TARGET_TYPE_SERVER (1<<17)
|
||||
#define NTLMFLAG_TARGET_TYPE_SHARE (1<<18)
|
||||
#define NTLMFLAG_NEGOTIATE_NTLM2_KEY (1<<19)
|
||||
#define NTLMFLAG_REQUEST_INIT_RESPONSE (1<<20)
|
||||
#define NTLMFLAG_REQUEST_ACCEPT_RESPONSE (1<<21)
|
||||
#define NTLMFLAG_REQUEST_NONNT_SESSION_KEY (1<<22)
|
||||
#define NTLMFLAG_NEGOTIATE_TARGET_INFO (1<<23)
|
||||
/* unknown (1<24) */
|
||||
/* unknown (1<25) */
|
||||
/* unknown (1<26) */
|
||||
/* unknown (1<27) */
|
||||
/* unknown (1<28) */
|
||||
#define NTLMFLAG_NEGOTIATE_128 (1<<29)
|
||||
#define NTLMFLAG_NEGOTIATE_KEY_EXCHANGE (1<<30)
|
||||
#define NTLMFLAG_NEGOTIATE_56 (1<<31)
|
||||
|
||||
|
||||
/*
|
||||
(*) = A "security buffer" is a triplet consisting of two shorts and one
|
||||
long:
|
||||
@@ -140,7 +117,7 @@ ntlm_input (struct ntlmdata *ntlm, const char *header)
|
||||
(40) Target Information (optional) security buffer(*)
|
||||
32 (48) start of data block
|
||||
*/
|
||||
int size;
|
||||
ssize_t size;
|
||||
char *buffer = (char *) alloca (strlen (header));
|
||||
|
||||
DEBUGP (("Received a type-2 NTLM message.\n"));
|
||||
@@ -176,6 +153,25 @@ ntlm_input (struct ntlmdata *ntlm, const char *header)
|
||||
* Turns a 56 bit key into the 64 bit, odd parity key and sets the key. The
|
||||
* key schedule ks is also set.
|
||||
*/
|
||||
#ifdef HAVE_NETTLE
|
||||
static void
|
||||
setup_des_key(unsigned char *key_56,
|
||||
struct des_ctx *des)
|
||||
{
|
||||
unsigned char key[8];
|
||||
|
||||
key[0] = key_56[0];
|
||||
key[1] = ((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1);
|
||||
key[2] = ((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2);
|
||||
key[3] = ((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3);
|
||||
key[4] = ((key_56[3] << 4) & 0xFF) | (key_56[4] >> 4);
|
||||
key[5] = ((key_56[4] << 3) & 0xFF) | (key_56[5] >> 5);
|
||||
key[6] = ((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6);
|
||||
key[7] = (key_56[6] << 1) & 0xFF;
|
||||
|
||||
nettle_des_set_key(des, key);
|
||||
}
|
||||
#else
|
||||
static void
|
||||
setup_des_key(unsigned char *key_56,
|
||||
DES_key_schedule DESKEYARG(ks))
|
||||
@@ -194,6 +190,7 @@ setup_des_key(unsigned char *key_56,
|
||||
DES_set_odd_parity(&key);
|
||||
DES_set_key(&key, ks);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* takes a 21 byte array and treats it as 3 56-bit DES keys. The
|
||||
@@ -203,6 +200,18 @@ setup_des_key(unsigned char *key_56,
|
||||
static void
|
||||
calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results)
|
||||
{
|
||||
#ifdef HAVE_NETTLE
|
||||
struct des_ctx des;
|
||||
|
||||
setup_des_key(keys, &des);
|
||||
nettle_des_encrypt(&des, 8, results, plaintext);
|
||||
|
||||
setup_des_key(keys + 7, &des);
|
||||
nettle_des_encrypt(&des, 8, results + 8, plaintext);
|
||||
|
||||
setup_des_key(keys + 14, &des);
|
||||
nettle_des_encrypt(&des, 8, results + 16, plaintext);
|
||||
#else
|
||||
DES_key_schedule ks;
|
||||
|
||||
setup_des_key(keys, DESKEY(ks));
|
||||
@@ -216,6 +225,7 @@ calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results)
|
||||
setup_des_key(keys+14, DESKEY(ks));
|
||||
DES_ecb_encrypt((DES_cblock*) plaintext, (DES_cblock*) (results+16),
|
||||
DESKEY(ks), DES_ENCRYPT);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -238,8 +248,7 @@ mkhash(const char *password,
|
||||
static const unsigned char magic[] = {
|
||||
0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25
|
||||
};
|
||||
int i;
|
||||
int len = strlen(password);
|
||||
size_t i, len = strlen(password);
|
||||
|
||||
/* make it fit at least 14 bytes */
|
||||
pw = (unsigned char *) alloca (len < 7 ? 14 : len * 2);
|
||||
@@ -248,13 +257,22 @@ mkhash(const char *password,
|
||||
len = 14;
|
||||
|
||||
for (i=0; i<len; i++)
|
||||
pw[i] = c_toupper (password[i]);
|
||||
pw[i] = (unsigned char) c_toupper (password[i]);
|
||||
|
||||
for (; i<14; i++)
|
||||
pw[i] = 0;
|
||||
|
||||
{
|
||||
/* create LanManager hashed password */
|
||||
#ifdef HAVE_NETTLE
|
||||
struct des_ctx des;
|
||||
|
||||
setup_des_key(pw, &des);
|
||||
nettle_des_encrypt(&des, 8, lmbuffer, magic);
|
||||
|
||||
setup_des_key(pw + 7, &des);
|
||||
nettle_des_encrypt(&des, 8, lmbuffer + 8, magic);
|
||||
#else
|
||||
DES_key_schedule ks;
|
||||
|
||||
setup_des_key(pw, DESKEY(ks));
|
||||
@@ -264,6 +282,7 @@ mkhash(const char *password,
|
||||
setup_des_key(pw+7, DESKEY(ks));
|
||||
DES_ecb_encrypt((DES_cblock *)magic, (DES_cblock *)(lmbuffer+8),
|
||||
DESKEY(ks), DES_ENCRYPT);
|
||||
#endif
|
||||
|
||||
memset(lmbuffer+16, 0, 5);
|
||||
}
|
||||
@@ -272,19 +291,29 @@ mkhash(const char *password,
|
||||
|
||||
#ifdef USE_NTRESPONSES
|
||||
{
|
||||
/* create NT hashed password */
|
||||
#ifdef HAVE_NETTLE
|
||||
struct md4_ctx MD4;
|
||||
#else
|
||||
MD4_CTX MD4;
|
||||
#endif
|
||||
|
||||
len = strlen(password);
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
pw[2*i] = password[i];
|
||||
pw[2*i] = (unsigned char) password[i];
|
||||
pw[2*i+1] = 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_NETTLE
|
||||
nettle_md4_init(&MD4);
|
||||
nettle_md4_update(&MD4, (unsigned) (2 * len), pw);
|
||||
nettle_md4_digest(&MD4, MD4_DIGEST_SIZE, ntbuffer);
|
||||
#else
|
||||
/* create NT hashed password */
|
||||
MD4_Init(&MD4);
|
||||
MD4_Update(&MD4, pw, 2*len);
|
||||
MD4_Final(ntbuffer, &MD4);
|
||||
#endif
|
||||
|
||||
memset(ntbuffer+16, 0, 5);
|
||||
}
|
||||
@@ -293,7 +322,7 @@ mkhash(const char *password,
|
||||
#endif
|
||||
}
|
||||
|
||||
#define SHORTPAIR(x) ((x) & 0xff), ((x) >> 8)
|
||||
#define SHORTPAIR(x) (char) ((x) & 0xff), (char) ((x) >> 8)
|
||||
#define LONGQUARTET(x) ((x) & 0xff), (((x) >> 8)&0xff), \
|
||||
(((x) >>16)&0xff), ((x)>>24)
|
||||
|
||||
@@ -302,19 +331,19 @@ char *
|
||||
ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
|
||||
bool *ready)
|
||||
{
|
||||
const char *domain=""; /* empty */
|
||||
const char *host=""; /* empty */
|
||||
int domlen=strlen(domain);
|
||||
int hostlen = strlen(host);
|
||||
int hostoff; /* host name offset */
|
||||
int domoff; /* domain name offset */
|
||||
int size;
|
||||
const char *domain = ""; /* empty */
|
||||
const char *host = ""; /* empty */
|
||||
size_t domlen = strlen(domain);
|
||||
size_t hostlen = strlen(host);
|
||||
size_t hostoff; /* host name offset */
|
||||
size_t domoff; /* domain name offset */
|
||||
size_t size;
|
||||
char *base64;
|
||||
char ntlmbuf[256]; /* enough, unless the host/domain is very long */
|
||||
|
||||
/* point to the address of the pointer that holds the string to sent to the
|
||||
server, which is for a plain host or for a HTTP proxy */
|
||||
char *output;
|
||||
char *output = NULL;
|
||||
|
||||
*ready = false;
|
||||
|
||||
@@ -327,7 +356,8 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
|
||||
|
||||
switch(ntlm->state) {
|
||||
case NTLMSTATE_TYPE1:
|
||||
default: /* for the weird cases we (re)start here */
|
||||
case NTLMSTATE_NONE:
|
||||
case NTLMSTATE_LAST:
|
||||
hostoff = 32;
|
||||
domoff = hostoff + hostlen;
|
||||
|
||||
@@ -405,15 +435,15 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
|
||||
*/
|
||||
|
||||
{
|
||||
int lmrespoff;
|
||||
int ntrespoff;
|
||||
int useroff;
|
||||
size_t lmrespoff;
|
||||
size_t ntrespoff;
|
||||
size_t useroff;
|
||||
unsigned char lmresp[0x18]; /* fixed-size */
|
||||
#ifdef USE_NTRESPONSES
|
||||
unsigned char ntresp[0x18]; /* fixed-size */
|
||||
#endif
|
||||
const char *usr;
|
||||
int userlen;
|
||||
size_t userlen;
|
||||
|
||||
DEBUGP (("Creating a type-3 NTLM message.\n"));
|
||||
|
||||
@@ -423,7 +453,7 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
|
||||
|
||||
if (usr) {
|
||||
domain = user;
|
||||
domlen = usr - domain;
|
||||
domlen = (size_t) (usr - domain);
|
||||
usr++;
|
||||
}
|
||||
else
|
||||
@@ -444,82 +474,82 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
|
||||
|
||||
/* Create the big type-3 message binary blob */
|
||||
|
||||
size = snprintf (ntlmbuf, sizeof(ntlmbuf),
|
||||
"NTLMSSP%c"
|
||||
"\x03%c%c%c" /* type-3, 32 bits */
|
||||
snprintf (ntlmbuf, sizeof (ntlmbuf),
|
||||
"NTLMSSP%c"
|
||||
"\x03%c%c%c" /* type-3, 32 bits */
|
||||
|
||||
"%c%c%c%c" /* LanManager length + allocated space */
|
||||
"%c%c" /* LanManager offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
"%c%c%c%c" /* LanManager length + allocated space */
|
||||
"%c%c" /* LanManager offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
|
||||
"%c%c" /* NT-response length */
|
||||
"%c%c" /* NT-response allocated space */
|
||||
"%c%c" /* NT-response offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
"%c%c" /* NT-response length */
|
||||
"%c%c" /* NT-response allocated space */
|
||||
"%c%c" /* NT-response offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
|
||||
"%c%c" /* domain length */
|
||||
"%c%c" /* domain allocated space */
|
||||
"%c%c" /* domain name offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
"%c%c" /* domain length */
|
||||
"%c%c" /* domain allocated space */
|
||||
"%c%c" /* domain name offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
|
||||
"%c%c" /* user length */
|
||||
"%c%c" /* user allocated space */
|
||||
"%c%c" /* user offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
"%c%c" /* user length */
|
||||
"%c%c" /* user allocated space */
|
||||
"%c%c" /* user offset */
|
||||
"%c%c" /* 2 zeroes */
|
||||
|
||||
"%c%c" /* host length */
|
||||
"%c%c" /* host allocated space */
|
||||
"%c%c" /* host offset */
|
||||
"%c%c%c%c%c%c" /* 6 zeroes */
|
||||
"%c%c" /* host length */
|
||||
"%c%c" /* host allocated space */
|
||||
"%c%c" /* host offset */
|
||||
"%c%c%c%c%c%c" /* 6 zeroes */
|
||||
|
||||
"\xff\xff" /* message length */
|
||||
"%c%c" /* 2 zeroes */
|
||||
"\xff\xff" /* message length */
|
||||
"%c%c" /* 2 zeroes */
|
||||
|
||||
"\x01\x82" /* flags */
|
||||
"%c%c" /* 2 zeroes */
|
||||
"\x01\x82" /* flags */
|
||||
"%c%c" /* 2 zeroes */
|
||||
|
||||
/* domain string */
|
||||
/* user string */
|
||||
/* host string */
|
||||
/* LanManager response */
|
||||
/* NT response */
|
||||
,
|
||||
0, /* zero termination */
|
||||
0,0,0, /* type-3 long, the 24 upper bits */
|
||||
/* domain string */
|
||||
/* user string */
|
||||
/* host string */
|
||||
/* LanManager response */
|
||||
/* NT response */
|
||||
,
|
||||
0, /* zero termination */
|
||||
0, 0, 0, /* type-3 long, the 24 upper bits */
|
||||
|
||||
SHORTPAIR(0x18), /* LanManager response length, twice */
|
||||
SHORTPAIR(0x18),
|
||||
SHORTPAIR(lmrespoff),
|
||||
0x0, 0x0,
|
||||
SHORTPAIR (0x18), /* LanManager response length, twice */
|
||||
SHORTPAIR (0x18),
|
||||
SHORTPAIR (lmrespoff),
|
||||
0x0, 0x0,
|
||||
|
||||
#ifdef USE_NTRESPONSES
|
||||
SHORTPAIR(0x18), /* NT-response length, twice */
|
||||
SHORTPAIR(0x18),
|
||||
SHORTPAIR (0x18), /* NT-response length, twice */
|
||||
SHORTPAIR (0x18),
|
||||
#else
|
||||
0x0, 0x0,
|
||||
0x0, 0x0,
|
||||
0x0, 0x0,
|
||||
0x0, 0x0,
|
||||
#endif
|
||||
SHORTPAIR(ntrespoff),
|
||||
0x0, 0x0,
|
||||
SHORTPAIR (ntrespoff),
|
||||
0x0, 0x0,
|
||||
|
||||
SHORTPAIR(domlen),
|
||||
SHORTPAIR(domlen),
|
||||
SHORTPAIR(domoff),
|
||||
0x0, 0x0,
|
||||
SHORTPAIR (domlen),
|
||||
SHORTPAIR (domlen),
|
||||
SHORTPAIR (domoff),
|
||||
0x0, 0x0,
|
||||
|
||||
SHORTPAIR(userlen),
|
||||
SHORTPAIR(userlen),
|
||||
SHORTPAIR(useroff),
|
||||
0x0, 0x0,
|
||||
SHORTPAIR (userlen),
|
||||
SHORTPAIR (userlen),
|
||||
SHORTPAIR (useroff),
|
||||
0x0, 0x0,
|
||||
|
||||
SHORTPAIR(hostlen),
|
||||
SHORTPAIR(hostlen),
|
||||
SHORTPAIR(hostoff),
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
SHORTPAIR (hostlen),
|
||||
SHORTPAIR (hostlen),
|
||||
SHORTPAIR (hostoff),
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
|
||||
0x0, 0x0,
|
||||
0x0, 0x0,
|
||||
|
||||
0x0, 0x0);
|
||||
0x0, 0x0);
|
||||
|
||||
/* size is now 64 */
|
||||
size=64;
|
||||
@@ -527,7 +557,7 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
|
||||
|
||||
/* Make sure that the user and domain strings fit in the target buffer
|
||||
before we copy them there. */
|
||||
if(((size_t) size + userlen + domlen) >= sizeof(ntlmbuf))
|
||||
if((size + userlen + domlen) >= sizeof(ntlmbuf))
|
||||
return NULL;
|
||||
|
||||
memcpy(&ntlmbuf[size], domain, domlen);
|
||||
@@ -537,20 +567,20 @@ ntlm_output (struct ntlmdata *ntlm, const char *user, const char *passwd,
|
||||
size += userlen;
|
||||
|
||||
/* we append the binary hashes to the end of the blob */
|
||||
if(size < ((int)sizeof(ntlmbuf) - 0x18)) {
|
||||
if(size < (sizeof(ntlmbuf) - 0x18)) {
|
||||
memcpy(&ntlmbuf[size], lmresp, 0x18);
|
||||
size += 0x18;
|
||||
}
|
||||
|
||||
#ifdef USE_NTRESPONSES
|
||||
if(size < ((int)sizeof(ntlmbuf) - 0x18)) {
|
||||
if(size < (sizeof(ntlmbuf) - 0x18)) {
|
||||
memcpy(&ntlmbuf[size], ntresp, 0x18);
|
||||
size += 0x18;
|
||||
}
|
||||
#endif
|
||||
|
||||
ntlmbuf[56] = size & 0xff;
|
||||
ntlmbuf[57] = size >> 8;
|
||||
ntlmbuf[56] = (char) (size & 0xff);
|
||||
ntlmbuf[57] = (char) (size >> 8);
|
||||
|
||||
/* convert the binary blob into base64 */
|
||||
base64 = (char *) alloca (BASE64_LENGTH (size) + 1);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef __HTTP_NTLM_H
|
||||
#define __HTTP_NTLM_H
|
||||
/* Declarations for http_ntlm.c
|
||||
Copyright (C) 1995, 1996, 1997, 2000, 2007, 2008, 2009, 2010, 2011
|
||||
Free Software Foundation, Inc.
|
||||
Copyright (C) 1995, 1996, 1997, 2000, 2007, 2008, 2009, 2010, 2011,
|
||||
2015 Free Software Foundation, Inc.
|
||||
Contributed by Daniel Stenberg.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
2738
src/http.c
2738
src/http.c
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/* Declarations for HTTP.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free
|
||||
Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -31,6 +31,8 @@ as that of the covered work. */
|
||||
#ifndef HTTP_H
|
||||
#define HTTP_H
|
||||
|
||||
#include "hsts.h"
|
||||
|
||||
struct url;
|
||||
|
||||
uerr_t http_loop (struct url *, struct url *, char **, char **, const char *,
|
||||
@@ -43,7 +45,7 @@ typedef struct {
|
||||
/* A token consists of characters in the [b, e) range. */
|
||||
const char *b, *e;
|
||||
} param_token;
|
||||
bool extract_param (const char **, param_token *, param_token *, char);
|
||||
bool extract_param (const char **, param_token *, param_token *, char, bool *);
|
||||
|
||||
|
||||
#endif /* HTTP_H */
|
||||
|
||||
496
src/init.c
496
src/init.c
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
/* Declarations for init.c.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
|
||||
259
src/iri.c
259
src/iri.c
@@ -1,5 +1,6 @@
|
||||
/* IRI related functions.
|
||||
Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 2008, 2009, 2010, 2011, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -35,41 +36,44 @@ as that of the covered work. */
|
||||
#include <iconv.h>
|
||||
#include <stringprep.h>
|
||||
#include <idna.h>
|
||||
#include <idn-free.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "url.h"
|
||||
#include "c-strcase.h"
|
||||
#include "c-strcasestr.h"
|
||||
#include "xstrndup.h"
|
||||
|
||||
/* RFC3987 section 3.1 mandates STD3 ASCII RULES */
|
||||
#define IDNA_FLAGS IDNA_USE_STD3_ASCII_RULES
|
||||
|
||||
/* Note: locale encoding is kept in options struct (opt.locale) */
|
||||
|
||||
static bool do_conversion (iconv_t cd, char *in, size_t inlen, char **out);
|
||||
|
||||
|
||||
/* Given a string containing "charset=XXX", return the encoding if found,
|
||||
or NULL otherwise */
|
||||
char *
|
||||
parse_charset (char *str)
|
||||
parse_charset (const char *str)
|
||||
{
|
||||
const char *end;
|
||||
char *charset;
|
||||
|
||||
if (!str || !*str)
|
||||
return NULL;
|
||||
|
||||
str = strcasestr (str, "charset=");
|
||||
str = c_strcasestr (str, "charset=");
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
str += 8;
|
||||
charset = str;
|
||||
end = str;
|
||||
|
||||
/* sXXXav: which chars should be banned ??? */
|
||||
while (*charset && !c_isspace (*charset))
|
||||
charset++;
|
||||
while (*end && !c_isspace (*end))
|
||||
end++;
|
||||
|
||||
/* sXXXav: could strdupdelim return NULL ? */
|
||||
charset = strdupdelim (str, charset);
|
||||
charset = strdupdelim (str, end);
|
||||
|
||||
/* Do a minimum check on the charset value */
|
||||
if (!check_encoding_name (charset))
|
||||
@@ -92,9 +96,9 @@ find_locale (void)
|
||||
|
||||
/* Basic check of an encoding name. */
|
||||
bool
|
||||
check_encoding_name (char *encoding)
|
||||
check_encoding_name (const char *encoding)
|
||||
{
|
||||
char *s = encoding;
|
||||
const char *s = encoding;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
@@ -110,60 +114,53 @@ check_encoding_name (char *encoding)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Try converting string str from locale to UTF-8. Return a new string
|
||||
on success, or str on error or if conversion isn't needed. */
|
||||
const char *
|
||||
locale_to_utf8 (const char *str)
|
||||
{
|
||||
iconv_t l2u;
|
||||
char *new;
|
||||
|
||||
/* That shouldn't happen, just in case */
|
||||
if (!opt.locale)
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("locale_to_utf8: locale is unset\n"));
|
||||
opt.locale = find_locale ();
|
||||
}
|
||||
|
||||
if (!opt.locale || !strcasecmp (opt.locale, "utf-8"))
|
||||
return str;
|
||||
|
||||
l2u = iconv_open ("UTF-8", opt.locale);
|
||||
if (l2u != (iconv_t)(-1))
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("Conversion from %s to %s isn't supported\n"),
|
||||
quote (opt.locale), quote ("UTF-8"));
|
||||
return str;
|
||||
}
|
||||
|
||||
if (do_conversion (l2u, (char *) str, strlen ((char *) str), &new))
|
||||
return (const char *) new;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/* Do the conversion according to the passed conversion descriptor cd. *out
|
||||
will contain the transcoded string on success. *out content is
|
||||
unspecified otherwise. */
|
||||
static bool
|
||||
do_conversion (iconv_t cd, char *in, size_t inlen, char **out)
|
||||
do_conversion (const char *tocode, const char *fromcode, char const *in_org, size_t inlen, char **out)
|
||||
{
|
||||
iconv_t cd;
|
||||
/* sXXXav : hummm hard to guess... */
|
||||
size_t len, done, outlen = inlen * 2;
|
||||
size_t len, done, outlen;
|
||||
int invalid = 0, tooshort = 0;
|
||||
char *s;
|
||||
char *s, *in, *in_save;
|
||||
|
||||
s = xmalloc (outlen + 1);
|
||||
*out = s;
|
||||
len = outlen;
|
||||
cd = iconv_open (tocode, fromcode);
|
||||
if (cd == (iconv_t)(-1))
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("Conversion from %s to %s isn't supported\n"),
|
||||
quote (fromcode), quote (tocode));
|
||||
*out = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* iconv() has to work on an unescaped string */
|
||||
in_save = in = xstrndup (in_org, inlen);
|
||||
url_unescape_except_reserved (in);
|
||||
inlen = strlen(in);
|
||||
|
||||
len = outlen = inlen * 2;
|
||||
*out = s = xmalloc (outlen + 1);
|
||||
done = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (iconv (cd, &in, &inlen, out, &outlen) != (size_t)(-1))
|
||||
if (iconv (cd, &in, &inlen, out, &outlen) != (size_t)(-1) &&
|
||||
iconv (cd, NULL, NULL, out, &outlen) != (size_t)(-1))
|
||||
{
|
||||
*out = s;
|
||||
*(s + len - outlen - done) = '\0';
|
||||
xfree(in_save);
|
||||
iconv_close(cd);
|
||||
IF_DEBUG
|
||||
{
|
||||
/* not not print out embedded passwords, in_org might be an URL */
|
||||
if (!strchr(in_org, '@') && !strchr(*out, '@'))
|
||||
debug_logprintf ("converted '%s' (%s) -> '%s' (%s)\n", in_org, fromcode, *out, tocode);
|
||||
else
|
||||
debug_logprintf ("%s: logging suppressed, strings may contain password\n", __func__);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -183,16 +180,10 @@ do_conversion (iconv_t cd, char *in, size_t inlen, char **out)
|
||||
}
|
||||
else if (errno == E2BIG) /* Output buffer full */
|
||||
{
|
||||
char *new;
|
||||
|
||||
tooshort++;
|
||||
done = len;
|
||||
outlen = done + inlen * 2;
|
||||
new = xmalloc (outlen + 1);
|
||||
memcpy (new, s, done);
|
||||
xfree (s);
|
||||
s = new;
|
||||
len = outlen;
|
||||
len = outlen = done + inlen * 2;
|
||||
s = xrealloc (s, outlen + 1);
|
||||
*out = s + done;
|
||||
}
|
||||
else /* Weird, we got an unspecified error */
|
||||
@@ -202,42 +193,129 @@ do_conversion (iconv_t cd, char *in, size_t inlen, char **out)
|
||||
}
|
||||
}
|
||||
|
||||
xfree(in_save);
|
||||
iconv_close(cd);
|
||||
IF_DEBUG
|
||||
{
|
||||
/* not not print out embedded passwords, in_org might be an URL */
|
||||
if (!strchr(in_org, '@') && !strchr(*out, '@'))
|
||||
debug_logprintf ("converted '%s' (%s) -> '%s' (%s)\n", in_org, fromcode, *out, tocode);
|
||||
else
|
||||
debug_logprintf ("%s: logging suppressed, strings may contain password\n", __func__);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Try converting string str from locale to UTF-8. Return a new string
|
||||
on success, or str on error or if conversion isn't needed. */
|
||||
const char *
|
||||
locale_to_utf8 (const char *str)
|
||||
{
|
||||
char *new;
|
||||
|
||||
/* That shouldn't happen, just in case */
|
||||
if (!opt.locale)
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("locale_to_utf8: locale is unset\n"));
|
||||
opt.locale = find_locale ();
|
||||
}
|
||||
|
||||
if (!opt.locale || !c_strcasecmp (opt.locale, "utf-8"))
|
||||
return str;
|
||||
|
||||
if (do_conversion ("UTF-8", opt.locale, (char *) str, strlen ((char *) str), &new))
|
||||
return (const char *) new;
|
||||
|
||||
xfree (new);
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Work around a libidn <= 1.30 vulnerability.
|
||||
*
|
||||
* The function checks for a valid UTF-8 character sequence before
|
||||
* passing it to idna_to_ascii_8z().
|
||||
*
|
||||
* [1] http://lists.gnu.org/archive/html/help-libidn/2015-05/msg00002.html
|
||||
* [2] https://lists.gnu.org/archive/html/bug-wget/2015-06/msg00002.html
|
||||
* [3] http://curl.haxx.se/mail/lib-2015-06/0143.html
|
||||
*/
|
||||
static bool
|
||||
_utf8_is_valid(const char *utf8)
|
||||
{
|
||||
const unsigned char *s = (const unsigned char *) utf8;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if ((*s & 0x80) == 0) /* 0xxxxxxx ASCII char */
|
||||
s++;
|
||||
else if ((*s & 0xE0) == 0xC0) /* 110xxxxx 10xxxxxx */
|
||||
{
|
||||
if ((s[1] & 0xC0) != 0x80)
|
||||
return false;
|
||||
s+=2;
|
||||
}
|
||||
else if ((*s & 0xF0) == 0xE0) /* 1110xxxx 10xxxxxx 10xxxxxx */
|
||||
{
|
||||
if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80)
|
||||
return false;
|
||||
s+=3;
|
||||
}
|
||||
else if ((*s & 0xF8) == 0xF0) /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
|
||||
{
|
||||
if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80 || (s[3] & 0xC0) != 0x80)
|
||||
return false;
|
||||
s+=4;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Try to "ASCII encode" UTF-8 host. Return the new domain on success or NULL
|
||||
on error. */
|
||||
char *
|
||||
idn_encode (struct iri *i, char *host)
|
||||
idn_encode (const struct iri *i, const char *host)
|
||||
{
|
||||
char *new;
|
||||
int ret;
|
||||
char *ascii_encoded;
|
||||
char *utf8_encoded = NULL;
|
||||
|
||||
/* Encode to UTF-8 if not done */
|
||||
if (!i->utf8_encode)
|
||||
{
|
||||
if (!remote_to_utf8 (i, (const char *) host, (const char **) &new))
|
||||
if (!remote_to_utf8 (i, host, &utf8_encoded))
|
||||
return NULL; /* Nothing to encode or an error occured */
|
||||
host = new;
|
||||
}
|
||||
|
||||
/* toASCII UTF-8 NULL terminated string */
|
||||
ret = idna_to_ascii_8z (host, &new, IDNA_FLAGS);
|
||||
if (!_utf8_is_valid(utf8_encoded ? utf8_encoded : host))
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("Invalid UTF-8 sequence: %s\n"),
|
||||
quote(utf8_encoded ? utf8_encoded : host));
|
||||
xfree (utf8_encoded);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Store in ascii_encoded the ASCII UTF-8 NULL terminated string */
|
||||
ret = idna_to_ascii_8z (utf8_encoded ? utf8_encoded : host, &ascii_encoded, IDNA_FLAGS);
|
||||
xfree (utf8_encoded);
|
||||
|
||||
if (ret != IDNA_SUCCESS)
|
||||
{
|
||||
/* sXXXav : free new when needed ! */
|
||||
logprintf (LOG_VERBOSE, _("idn_encode failed (%d): %s\n"), ret,
|
||||
quote (idna_strerror (ret)));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new;
|
||||
return ascii_encoded;
|
||||
}
|
||||
|
||||
/* Try to decode an "ASCII encoded" host. Return the new domain in the locale
|
||||
on success or NULL on error. */
|
||||
char *
|
||||
idn_decode (char *host)
|
||||
idn_decode (const char *host)
|
||||
{
|
||||
char *new;
|
||||
int ret;
|
||||
@@ -256,22 +334,21 @@ idn_decode (char *host)
|
||||
/* Try to transcode string str from remote encoding to UTF-8. On success, *new
|
||||
contains the transcoded string. *new content is unspecified otherwise. */
|
||||
bool
|
||||
remote_to_utf8 (struct iri *i, const char *str, const char **new)
|
||||
remote_to_utf8 (const struct iri *iri, const char *str, char **new)
|
||||
{
|
||||
iconv_t cd;
|
||||
bool ret = false;
|
||||
|
||||
if (!i->uri_encoding)
|
||||
if (!iri->uri_encoding)
|
||||
return false;
|
||||
|
||||
/* When `i->uri_encoding' == "UTF-8" there is nothing to convert. But we must
|
||||
test for non-ASCII symbols for correct hostname processing in `idn_encode'
|
||||
function. */
|
||||
if (!strcmp (i->uri_encoding, "UTF-8"))
|
||||
if (!c_strcasecmp (iri->uri_encoding, "UTF-8"))
|
||||
{
|
||||
int i, len = strlen (str);
|
||||
for (i = 0; i < len; i++)
|
||||
if ((unsigned char) str[i] >= (unsigned char) '\200')
|
||||
const unsigned char *p;
|
||||
for (p = (unsigned char *) str; *p; p++)
|
||||
if (*p > 127)
|
||||
{
|
||||
*new = strdup (str);
|
||||
return true;
|
||||
@@ -279,19 +356,13 @@ remote_to_utf8 (struct iri *i, const char *str, const char **new)
|
||||
return false;
|
||||
}
|
||||
|
||||
cd = iconv_open ("UTF-8", i->uri_encoding);
|
||||
if (cd == (iconv_t)(-1))
|
||||
return false;
|
||||
|
||||
if (do_conversion (cd, (char *) str, strlen ((char *) str), (char **) new))
|
||||
if (do_conversion ("UTF-8", iri->uri_encoding, str, strlen (str), new))
|
||||
ret = true;
|
||||
|
||||
iconv_close (cd);
|
||||
|
||||
/* Test if something was converted */
|
||||
if (!strcmp (str, *new))
|
||||
if (*new && !strcmp (str, *new))
|
||||
{
|
||||
xfree ((char *) *new);
|
||||
xfree (*new);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -325,23 +396,26 @@ struct iri *iri_dup (const struct iri *src)
|
||||
void
|
||||
iri_free (struct iri *i)
|
||||
{
|
||||
xfree_null (i->uri_encoding);
|
||||
xfree_null (i->content_encoding);
|
||||
xfree_null (i->orig_url);
|
||||
xfree (i);
|
||||
if (i)
|
||||
{
|
||||
xfree (i->uri_encoding);
|
||||
xfree (i->content_encoding);
|
||||
xfree (i->orig_url);
|
||||
xfree (i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set uri_encoding of struct iri i. If a remote encoding was specified, use
|
||||
it unless force is true. */
|
||||
void
|
||||
set_uri_encoding (struct iri *i, char *charset, bool force)
|
||||
set_uri_encoding (struct iri *i, const char *charset, bool force)
|
||||
{
|
||||
DEBUGP (("URI encoding = %s\n", charset ? quote (charset) : "None"));
|
||||
if (!force && opt.encoding_remote)
|
||||
return;
|
||||
if (i->uri_encoding)
|
||||
{
|
||||
if (charset && !strcasecmp (i->uri_encoding, charset))
|
||||
if (charset && !c_strcasecmp (i->uri_encoding, charset))
|
||||
return;
|
||||
xfree (i->uri_encoding);
|
||||
}
|
||||
@@ -351,18 +425,17 @@ set_uri_encoding (struct iri *i, char *charset, bool force)
|
||||
|
||||
/* Set content_encoding of struct iri i. */
|
||||
void
|
||||
set_content_encoding (struct iri *i, char *charset)
|
||||
set_content_encoding (struct iri *i, const char *charset)
|
||||
{
|
||||
DEBUGP (("URI content encoding = %s\n", charset ? quote (charset) : "None"));
|
||||
if (opt.encoding_remote)
|
||||
return;
|
||||
if (i->content_encoding)
|
||||
{
|
||||
if (charset && !strcasecmp (i->content_encoding, charset))
|
||||
if (charset && !c_strcasecmp (i->content_encoding, charset))
|
||||
return;
|
||||
xfree (i->content_encoding);
|
||||
}
|
||||
|
||||
i->content_encoding = charset ? xstrdup (charset) : NULL;
|
||||
}
|
||||
|
||||
|
||||
23
src/iri.h
23
src/iri.h
@@ -1,5 +1,6 @@
|
||||
/* Internationalization related declarations.
|
||||
Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 2008, 2009, 2010, 2011, 2015 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -39,29 +40,33 @@ struct iri {
|
||||
|
||||
#ifdef ENABLE_IRI
|
||||
|
||||
char *parse_charset (char *str);
|
||||
# include <idna.h>
|
||||
# include <idn-free.h>
|
||||
|
||||
char *parse_charset (const char *str);
|
||||
char *find_locale (void);
|
||||
bool check_encoding_name (char *encoding);
|
||||
bool check_encoding_name (const char *encoding);
|
||||
const char *locale_to_utf8 (const char *str);
|
||||
char *idn_encode (struct iri *i, char *host);
|
||||
char *idn_decode (char *host);
|
||||
bool remote_to_utf8 (struct iri *i, const char *str, const char **new);
|
||||
char *idn_encode (const struct iri *i, const char *host);
|
||||
char *idn_decode (const char *host);
|
||||
bool remote_to_utf8 (const struct iri *i, const char *str, char **new);
|
||||
struct iri *iri_new (void);
|
||||
struct iri *iri_dup (const struct iri *);
|
||||
void iri_free (struct iri *i);
|
||||
void set_uri_encoding (struct iri *i, char *charset, bool force);
|
||||
void set_content_encoding (struct iri *i, char *charset);
|
||||
void set_uri_encoding (struct iri *i, const char *charset, bool force);
|
||||
void set_content_encoding (struct iri *i, const char *charset);
|
||||
|
||||
#else /* ENABLE_IRI */
|
||||
|
||||
extern struct iri dummy_iri;
|
||||
|
||||
#define parse_charset(str) (str, NULL)
|
||||
#define parse_charset(str) NULL
|
||||
#define find_locale() NULL
|
||||
#define check_encoding_name(str) false
|
||||
#define locale_to_utf8(str) (str)
|
||||
#define idn_encode(a,b) NULL
|
||||
#define idn_decode(str) NULL
|
||||
#define idn_free(str) ((void)0)
|
||||
#define remote_to_utf8(a,b,c) false
|
||||
#define iri_new() (&dummy_iri)
|
||||
#define iri_dup(a) (&dummy_iri)
|
||||
|
||||
81
src/log.c
81
src/log.c
@@ -1,6 +1,6 @@
|
||||
/* Messages logging.
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
2007, 2008, 2009, 2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -39,6 +39,7 @@ as that of the covered work. */
|
||||
#include <errno.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "exits.h"
|
||||
#include "log.h"
|
||||
|
||||
/* 2005-10-25 SMS.
|
||||
@@ -72,7 +73,7 @@ as that of the covered work. */
|
||||
- Inhibiting output. When Wget receives SIGHUP, but redirecting
|
||||
the output fails, logging is inhibited. */
|
||||
|
||||
|
||||
|
||||
/* The file descriptor used for logging. This is NULL before log_init
|
||||
is called; logging functions log to stderr then. log_init sets it
|
||||
either to stderr or to a file pointer obtained from fopen(). If
|
||||
@@ -141,7 +142,7 @@ static int log_line_current = -1;
|
||||
static bool trailing_line;
|
||||
|
||||
static void check_redirect_output (void);
|
||||
|
||||
|
||||
#define ROT_ADVANCE(num) do { \
|
||||
if (++num >= SAVED_LOG_LINES) \
|
||||
num = 0; \
|
||||
@@ -155,11 +156,7 @@ static void
|
||||
free_log_line (int num)
|
||||
{
|
||||
struct log_ln *ln = log_lines + num;
|
||||
if (ln->malloced_line)
|
||||
{
|
||||
xfree (ln->malloced_line);
|
||||
ln->malloced_line = NULL;
|
||||
}
|
||||
xfree (ln->malloced_line);
|
||||
ln->content = NULL;
|
||||
}
|
||||
|
||||
@@ -264,7 +261,7 @@ saved_append (const char *s)
|
||||
s = end;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Check X against opt.verbose and opt.quiet. The semantics is as
|
||||
follows:
|
||||
|
||||
@@ -278,6 +275,10 @@ saved_append (const char *s)
|
||||
#define CHECK_VERBOSE(x) \
|
||||
switch (x) \
|
||||
{ \
|
||||
case LOG_PROGRESS: \
|
||||
if (!opt.show_progress) \
|
||||
return; \
|
||||
break; \
|
||||
case LOG_ALWAYS: \
|
||||
break; \
|
||||
case LOG_NOTQUIET: \
|
||||
@@ -309,6 +310,14 @@ get_log_fp (void)
|
||||
return stderr;
|
||||
}
|
||||
|
||||
static FILE *
|
||||
get_progress_fp (void)
|
||||
{
|
||||
if (opt.show_progress == true)
|
||||
return stderr;
|
||||
return get_log_fp();
|
||||
}
|
||||
|
||||
/* Returns the file descriptor for the secondary log file. This is
|
||||
WARCLOGFP, except if called before log_init, in which case it
|
||||
returns stderr. This is useful in case someone calls a logging
|
||||
@@ -333,7 +342,7 @@ log_set_warc_log_fp (FILE * fp)
|
||||
{
|
||||
warclogfp = fp;
|
||||
}
|
||||
|
||||
|
||||
/* Log a literal string S. The string is logged as-is, without a
|
||||
newline appended. */
|
||||
|
||||
@@ -342,11 +351,22 @@ logputs (enum log_options o, const char *s)
|
||||
{
|
||||
FILE *fp;
|
||||
FILE *warcfp;
|
||||
int errno_save = errno;
|
||||
|
||||
check_redirect_output ();
|
||||
if ((fp = get_log_fp ()) == NULL)
|
||||
if (o == LOG_PROGRESS)
|
||||
fp = get_progress_fp ();
|
||||
else
|
||||
fp = get_log_fp ();
|
||||
|
||||
errno = errno_save;
|
||||
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
||||
warcfp = get_warc_log_fp ();
|
||||
errno = errno_save;
|
||||
|
||||
CHECK_VERBOSE (o);
|
||||
|
||||
FPUTS (s, fp);
|
||||
@@ -358,6 +378,8 @@ logputs (enum log_options o, const char *s)
|
||||
logflush ();
|
||||
else
|
||||
needs_flushing = true;
|
||||
|
||||
errno = errno_save;
|
||||
}
|
||||
|
||||
struct logvprintf_state {
|
||||
@@ -380,7 +402,7 @@ struct logvprintf_state {
|
||||
(An alternative approach would be to use va_copy, but that's not
|
||||
portable.) */
|
||||
|
||||
static bool
|
||||
static bool GCC_FORMAT_ATTR (2, 0)
|
||||
log_vprintf_internal (struct logvprintf_state *state, const char *fmt,
|
||||
va_list args)
|
||||
{
|
||||
@@ -446,8 +468,7 @@ log_vprintf_internal (struct logvprintf_state *state, const char *fmt,
|
||||
FPUTS (write_ptr, fp);
|
||||
if (warcfp != NULL)
|
||||
FPUTS (write_ptr, warcfp);
|
||||
if (state->bigmsg)
|
||||
xfree (state->bigmsg);
|
||||
xfree (state->bigmsg);
|
||||
|
||||
flush:
|
||||
if (flush_log_p)
|
||||
@@ -529,13 +550,16 @@ logprintf (enum log_options o, const char *fmt, ...)
|
||||
va_list args;
|
||||
struct logvprintf_state lpstate;
|
||||
bool done;
|
||||
int errno_saved = errno;
|
||||
|
||||
check_redirect_output ();
|
||||
errno = errno_saved;
|
||||
if (inhibit_logging)
|
||||
return;
|
||||
CHECK_VERBOSE (o);
|
||||
|
||||
xzero (lpstate);
|
||||
errno = 0;
|
||||
do
|
||||
{
|
||||
va_start (args, fmt);
|
||||
@@ -543,9 +567,11 @@ logprintf (enum log_options o, const char *fmt, ...)
|
||||
va_end (args);
|
||||
|
||||
if (done && errno == EPIPE)
|
||||
exit (1);
|
||||
exit (WGET_EXIT_GENERIC_ERROR);
|
||||
}
|
||||
while (!done);
|
||||
|
||||
errno = errno_saved;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
@@ -575,7 +601,7 @@ debug_logprintf (const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_DEBUG */
|
||||
|
||||
|
||||
/* Open FILE and set up a logging stream. If FILE cannot be opened,
|
||||
exit with status of 1. */
|
||||
void
|
||||
@@ -583,11 +609,18 @@ log_init (const char *file, bool appendp)
|
||||
{
|
||||
if (file)
|
||||
{
|
||||
logfp = fopen (file, appendp ? "a" : "w");
|
||||
if (!logfp)
|
||||
if (HYPHENP (file))
|
||||
{
|
||||
fprintf (stderr, "%s: %s: %s\n", exec_name, file, strerror (errno));
|
||||
exit (1);
|
||||
logfp = stdout;
|
||||
}
|
||||
else
|
||||
{
|
||||
logfp = fopen (file, appendp ? "a" : "w");
|
||||
if (!logfp)
|
||||
{
|
||||
fprintf (stderr, "%s: %s: %s\n", exec_name, file, strerror (errno));
|
||||
exit (WGET_EXIT_GENERIC_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -670,7 +703,7 @@ log_dump_context (void)
|
||||
fflush (fp);
|
||||
fflush (warcfp);
|
||||
}
|
||||
|
||||
|
||||
/* String escape functions. */
|
||||
|
||||
/* Return the number of non-printable characters in SOURCE.
|
||||
@@ -842,9 +875,9 @@ log_cleanup (void)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < countof (ring); i++)
|
||||
xfree_null (ring[i].buffer);
|
||||
xfree (ring[i].buffer);
|
||||
}
|
||||
|
||||
|
||||
/* When SIGHUP or SIGUSR1 are received, the output is redirected
|
||||
elsewhere. Such redirection is only allowed once. */
|
||||
static enum { RR_NONE, RR_REQUESTED, RR_DONE } redirect_request = RR_NONE;
|
||||
@@ -871,7 +904,7 @@ redirect_output (void)
|
||||
can do but disable printing completely. */
|
||||
fprintf (stderr, _("\n%s received.\n"), redirect_request_signal_name);
|
||||
fprintf (stderr, _("%s: %s; disabling logging.\n"),
|
||||
logfile, strerror (errno));
|
||||
(logfile) ? logfile : DEFAULT_LOGFILE, strerror (errno));
|
||||
inhibit_logging = true;
|
||||
}
|
||||
save_context_p = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Declarations for log.c.
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
2007, 2008, 2009, 2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -36,7 +36,7 @@ as that of the covered work. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
enum log_options { LOG_VERBOSE, LOG_NOTQUIET, LOG_NONVERBOSE, LOG_ALWAYS };
|
||||
enum log_options { LOG_VERBOSE, LOG_NOTQUIET, LOG_NONVERBOSE, LOG_ALWAYS, LOG_PROGRESS };
|
||||
|
||||
void log_set_warc_log_fp (FILE *);
|
||||
|
||||
|
||||
1131
src/main.c
1131
src/main.c
File diff suppressed because it is too large
Load Diff
782
src/metalink.c
Normal file
782
src/metalink.c
Normal file
@@ -0,0 +1,782 @@
|
||||
/* Metalink module.
|
||||
Copyright (C) 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
GNU Wget 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.
|
||||
|
||||
GNU Wget 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 Wget. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this program, or any covered work, by linking or
|
||||
combining it with the OpenSSL project's OpenSSL library (or a
|
||||
modified version of that library), containing parts covered by the
|
||||
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
|
||||
grants you additional permission to convey the resulting work.
|
||||
Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work. */
|
||||
|
||||
#include "wget.h"
|
||||
#ifdef HAVE_METALINK
|
||||
|
||||
#include "metalink.h"
|
||||
#include "retr.h"
|
||||
#include "exits.h"
|
||||
#include "utils.h"
|
||||
#include "sha256.h"
|
||||
#include "xstrndup.h"
|
||||
#include <errno.h>
|
||||
#include <unistd.h> /* For unlink. */
|
||||
#include <metalink/metalink_parser.h>
|
||||
#ifdef HAVE_GPGME
|
||||
#include <gpgme.h>
|
||||
#include <fcntl.h> /* For open and close. */
|
||||
#endif
|
||||
|
||||
#ifdef TESTING
|
||||
#include "test.h"
|
||||
#endif
|
||||
|
||||
/* Loop through all files in metalink structure and retrieve them.
|
||||
Returns RETROK if all files were downloaded.
|
||||
Returns last retrieval error (from retrieve_url) if some files
|
||||
could not be downloaded. */
|
||||
uerr_t
|
||||
retrieve_from_metalink (const metalink_t* metalink)
|
||||
{
|
||||
metalink_file_t **mfile_ptr;
|
||||
uerr_t last_retr_err = RETROK; /* Store last encountered retrieve error. */
|
||||
|
||||
FILE *_output_stream = output_stream;
|
||||
bool _output_stream_regular = output_stream_regular;
|
||||
char *_output_document = opt.output_document;
|
||||
|
||||
DEBUGP (("Retrieving from Metalink\n"));
|
||||
|
||||
/* No files to download. */
|
||||
if (!metalink->files)
|
||||
return RETROK;
|
||||
|
||||
if (opt.output_document)
|
||||
{
|
||||
/* We cannot support output_document as we need to compute checksum
|
||||
of downloaded file, and to remove it if the checksum is bad. */
|
||||
logputs (LOG_NOTQUIET,
|
||||
_("-O not supported for metalink download. Ignoring.\n"));
|
||||
}
|
||||
|
||||
for (mfile_ptr = metalink->files; *mfile_ptr; mfile_ptr++)
|
||||
{
|
||||
metalink_file_t *mfile = *mfile_ptr;
|
||||
metalink_resource_t **mres_ptr;
|
||||
char *filename = NULL;
|
||||
bool hash_ok = false;
|
||||
|
||||
uerr_t retr_err = METALINK_MISSING_RESOURCE;
|
||||
|
||||
/* -1 -> file should be rejected
|
||||
0 -> could not verify
|
||||
1 -> verified successfully */
|
||||
char sig_status = 0;
|
||||
|
||||
output_stream = NULL;
|
||||
|
||||
DEBUGP (("Processing metalink file %s...\n", quote (mfile->name)));
|
||||
|
||||
/* Resources are sorted by priority. */
|
||||
for (mres_ptr = mfile->resources; *mres_ptr; mres_ptr++)
|
||||
{
|
||||
metalink_resource_t *mres = *mres_ptr;
|
||||
metalink_checksum_t **mchksum_ptr, *mchksum;
|
||||
struct iri *iri;
|
||||
struct url *url;
|
||||
int url_err;
|
||||
|
||||
if (!RES_TYPE_SUPPORTED (mres->type))
|
||||
{
|
||||
logprintf (LOG_VERBOSE,
|
||||
_("Resource type %s not supported, ignoring...\n"),
|
||||
quote (mres->type));
|
||||
continue;
|
||||
}
|
||||
|
||||
retr_err = METALINK_RETR_ERROR;
|
||||
|
||||
/* If output_stream is not NULL, then we have failed on
|
||||
previous resource and are retrying. Thus, remove the file. */
|
||||
if (output_stream)
|
||||
{
|
||||
fclose (output_stream);
|
||||
output_stream = NULL;
|
||||
if (unlink (filename))
|
||||
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
|
||||
xfree (filename);
|
||||
}
|
||||
|
||||
/* Parse our resource URL. */
|
||||
iri = iri_new ();
|
||||
set_uri_encoding (iri, opt.locale, true);
|
||||
url = url_parse (mres->url, &url_err, iri, false);
|
||||
|
||||
if (!url)
|
||||
{
|
||||
char *error = url_error (mres->url, url_err);
|
||||
logprintf (LOG_NOTQUIET, "%s: %s.\n", mres->url, error);
|
||||
xfree (error);
|
||||
inform_exit_status (URLERROR);
|
||||
iri_free (iri);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Avoid recursive Metalink from HTTP headers. */
|
||||
bool _metalink_http = opt.metalink_over_http;
|
||||
|
||||
/* Assure proper local file name regardless of the URL
|
||||
of particular Metalink resource.
|
||||
To do that we create the local file here and put
|
||||
it as output_stream. We restore the original configuration
|
||||
after we are finished with the file. */
|
||||
output_stream = unique_create (mfile->name, true, &filename);
|
||||
output_stream_regular = true;
|
||||
|
||||
/* Store the real file name for displaying in messages. */
|
||||
opt.output_document = filename;
|
||||
|
||||
opt.metalink_over_http = false;
|
||||
DEBUGP (("Storing to %s\n", filename));
|
||||
retr_err = retrieve_url (url, mres->url, NULL, NULL,
|
||||
NULL, NULL, opt.recursive, iri, false);
|
||||
opt.metalink_over_http = _metalink_http;
|
||||
}
|
||||
url_free (url);
|
||||
iri_free (iri);
|
||||
|
||||
if (retr_err == RETROK)
|
||||
{
|
||||
FILE *local_file;
|
||||
|
||||
/* Check the digest. */
|
||||
local_file = fopen (filename, "rb");
|
||||
if (!local_file)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("Could not open downloaded file.\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (mchksum_ptr = mfile->checksums; *mchksum_ptr; mchksum_ptr++)
|
||||
{
|
||||
char sha256[SHA256_DIGEST_SIZE];
|
||||
char sha256_txt[2 * SHA256_DIGEST_SIZE + 1];
|
||||
|
||||
mchksum = *mchksum_ptr;
|
||||
|
||||
/* I have seen both variants... */
|
||||
if (strcasecmp (mchksum->type, "sha256")
|
||||
&& strcasecmp (mchksum->type, "sha-256"))
|
||||
{
|
||||
DEBUGP (("Ignoring unsupported checksum type %s.\n",
|
||||
quote (mchksum->type)));
|
||||
continue;
|
||||
}
|
||||
|
||||
logprintf (LOG_VERBOSE, _("Computing checksum for %s\n"),
|
||||
quote (mfile->name));
|
||||
|
||||
sha256_stream (local_file, sha256);
|
||||
wg_hex_to_string (sha256_txt, sha256, SHA256_DIGEST_SIZE);
|
||||
DEBUGP (("Declared hash: %s\n", mchksum->hash));
|
||||
DEBUGP (("Computed hash: %s\n", sha256_txt));
|
||||
if (!strcmp (sha256_txt, mchksum->hash))
|
||||
{
|
||||
logputs (LOG_VERBOSE,
|
||||
_("Checksum matches.\n"));
|
||||
hash_ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("Checksum mismatch for file %s.\n"),
|
||||
quote (mfile->name));
|
||||
hash_ok = false;
|
||||
}
|
||||
|
||||
/* Stop as soon as we checked the supported checksum. */
|
||||
break;
|
||||
} /* Iterate over available checksums. */
|
||||
fclose (local_file);
|
||||
local_file = NULL;
|
||||
|
||||
if (!hash_ok)
|
||||
continue;
|
||||
|
||||
sig_status = 0; /* Not verified. */
|
||||
|
||||
#ifdef HAVE_GPGME
|
||||
/* Check the crypto signature.
|
||||
|
||||
Note that the signtures from Metalink in XML will not be
|
||||
parsed when using libmetalink version older than 0.1.3.
|
||||
Metalink-over-HTTP is not affected by this problem. */
|
||||
if (mfile->signature)
|
||||
{
|
||||
metalink_signature_t *msig = mfile->signature;
|
||||
gpgme_error_t gpgerr;
|
||||
gpgme_ctx_t gpgctx;
|
||||
gpgme_data_t gpgsigdata, gpgdata;
|
||||
gpgme_verify_result_t gpgres;
|
||||
gpgme_signature_t gpgsig;
|
||||
gpgme_protocol_t gpgprot = GPGME_PROTOCOL_UNKNOWN;
|
||||
int fd = -1;
|
||||
|
||||
/* Initialize the library - as name suggests. */
|
||||
gpgme_check_version (NULL);
|
||||
|
||||
/* Open data file. */
|
||||
fd = open (filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
logputs (LOG_NOTQUIET,
|
||||
_("Could not open downloaded file for signature "
|
||||
"verification.\n"));
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
/* Assign file descriptor to GPG data structure. */
|
||||
gpgerr = gpgme_data_new_from_fd (&gpgdata, fd);
|
||||
if (gpgerr != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
"GPGME data_new_from_fd: %s\n",
|
||||
gpgme_strerror (gpgerr));
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
/* Prepare new GPGME context. */
|
||||
gpgerr = gpgme_new (&gpgctx);
|
||||
if (gpgerr != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
"GPGME new: %s\n",
|
||||
gpgme_strerror (gpgerr));
|
||||
gpgme_data_release (gpgdata);
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
DEBUGP (("Verifying signature %s:\n%s\n",
|
||||
quote (msig->mediatype),
|
||||
msig->signature));
|
||||
|
||||
/* Check signature type. */
|
||||
if (!strcmp (msig->mediatype, "application/pgp-signature"))
|
||||
gpgprot = GPGME_PROTOCOL_OpenPGP;
|
||||
else /* Unsupported signature type. */
|
||||
{
|
||||
gpgme_release (gpgctx);
|
||||
gpgme_data_release (gpgdata);
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
gpgerr = gpgme_set_protocol (gpgctx, gpgprot);
|
||||
if (gpgerr != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
"GPGME set_protocol: %s\n",
|
||||
gpgme_strerror (gpgerr));
|
||||
gpgme_release (gpgctx);
|
||||
gpgme_data_release (gpgdata);
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
/* Load the signature. */
|
||||
gpgerr = gpgme_data_new_from_mem (&gpgsigdata,
|
||||
msig->signature,
|
||||
strlen (msig->signature),
|
||||
0);
|
||||
if (gpgerr != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("GPGME data_new_from_mem: %s\n"),
|
||||
gpgme_strerror (gpgerr));
|
||||
gpgme_release (gpgctx);
|
||||
gpgme_data_release (gpgdata);
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
/* Verify the signature. */
|
||||
gpgerr = gpgme_op_verify (gpgctx, gpgsigdata, gpgdata, NULL);
|
||||
if (gpgerr != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("GPGME op_verify: %s\n"),
|
||||
gpgme_strerror (gpgerr));
|
||||
gpgme_data_release (gpgsigdata);
|
||||
gpgme_release (gpgctx);
|
||||
gpgme_data_release (gpgdata);
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
/* Check the results. */
|
||||
gpgres = gpgme_op_verify_result (gpgctx);
|
||||
if (!gpgres)
|
||||
{
|
||||
logputs (LOG_NOTQUIET,
|
||||
_("GPGME op_verify_result: NULL\n"));
|
||||
gpgme_data_release (gpgsigdata);
|
||||
gpgme_release (gpgctx);
|
||||
gpgme_data_release (gpgdata);
|
||||
goto gpg_skip_verification;
|
||||
}
|
||||
|
||||
/* The list is null-terminated. */
|
||||
for (gpgsig = gpgres->signatures; gpgsig; gpgsig = gpgsig->next)
|
||||
{
|
||||
DEBUGP (("Checking signature %s\n", gpgsig->fpr));
|
||||
|
||||
if (gpgsig->summary
|
||||
& (GPGME_SIGSUM_VALID | GPGME_SIGSUM_GREEN))
|
||||
{
|
||||
logputs (LOG_VERBOSE,
|
||||
_("Signature validation suceeded.\n"));
|
||||
sig_status = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (gpgsig->summary & GPGME_SIGSUM_RED)
|
||||
{
|
||||
logputs (LOG_NOTQUIET,
|
||||
_("Invalid signature. Rejecting resource.\n"));
|
||||
sig_status = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (gpgsig->summary == 0
|
||||
&& (gpgsig->status & 0xFFFF) == GPG_ERR_NO_ERROR)
|
||||
{
|
||||
logputs (LOG_VERBOSE,
|
||||
_("Data matches signature, but signature "
|
||||
"is not trusted.\n"));
|
||||
}
|
||||
|
||||
if ((gpgsig->status & 0xFFFF) != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET,
|
||||
"GPGME: %s\n",
|
||||
gpgme_strerror (gpgsig->status & 0xFFFF));
|
||||
}
|
||||
}
|
||||
gpgme_data_release (gpgsigdata);
|
||||
gpgme_release (gpgctx);
|
||||
gpgme_data_release (gpgdata);
|
||||
gpg_skip_verification:
|
||||
if (fd != -1)
|
||||
close (fd);
|
||||
} /* endif (mfile->signature) */
|
||||
#endif
|
||||
/* Stop if file was downloaded with success. */
|
||||
if (sig_status >= 0)
|
||||
break;
|
||||
} /* endif RETR_OK. */
|
||||
} /* Iterate over resources. */
|
||||
|
||||
if (retr_err != RETROK)
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("Failed to download %s. Skipping resource.\n"),
|
||||
quote (mfile->name));
|
||||
}
|
||||
else if (!hash_ok)
|
||||
{
|
||||
retr_err = METALINK_CHKSUM_ERROR;
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("File %s retrieved but checksum does not match. "
|
||||
"\n"), quote (mfile->name));
|
||||
}
|
||||
#ifdef HAVE_GPGME
|
||||
/* Signature will be only validated if hash check was successful. */
|
||||
else if (sig_status < 0)
|
||||
{
|
||||
retr_err = METALINK_SIG_ERROR;
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("File %s retrieved but signature does not match. "
|
||||
"\n"), quote (mfile->name));
|
||||
}
|
||||
#endif
|
||||
last_retr_err = retr_err == RETROK ? last_retr_err : retr_err;
|
||||
|
||||
/* Remove the file if error encountered or if option specified.
|
||||
Note: the file has been downloaded using *_loop. Therefore, it
|
||||
is not necessary to keep the file for continuated download. */
|
||||
if ((retr_err != RETROK || opt.delete_after)
|
||||
&& filename != NULL && file_exists_p (filename))
|
||||
{
|
||||
logprintf (LOG_VERBOSE, _("Removing %s.\n"), quote (filename));
|
||||
if (unlink (filename))
|
||||
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
|
||||
}
|
||||
if (output_stream)
|
||||
{
|
||||
fclose (output_stream);
|
||||
output_stream = NULL;
|
||||
}
|
||||
xfree (filename);
|
||||
} /* Iterate over files. */
|
||||
|
||||
/* Restore original values. */
|
||||
opt.output_document = _output_document;
|
||||
output_stream_regular = _output_stream_regular;
|
||||
output_stream = _output_stream;
|
||||
|
||||
return last_retr_err;
|
||||
}
|
||||
|
||||
int metalink_res_cmp (const void* v1, const void* v2)
|
||||
{
|
||||
const metalink_resource_t *res1 = *(metalink_resource_t **) v1,
|
||||
*res2 = *(metalink_resource_t **) v2;
|
||||
if (res1->preference != res2->preference)
|
||||
return res2->preference - res1->preference;
|
||||
if (res1->priority != res2->priority)
|
||||
return res1->priority - res2->priority;
|
||||
if (opt.preferred_location)
|
||||
{
|
||||
int cmp = 0;
|
||||
if (res1->location &&
|
||||
!strcasecmp (opt.preferred_location, res1->location))
|
||||
cmp -= 1;
|
||||
if (res2->location &&
|
||||
!strcasecmp (opt.preferred_location, res2->location))
|
||||
cmp += 1;
|
||||
return cmp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Find value of given key. This is intended for Link header, but will
|
||||
work with any header that uses ';' as field separator and '=' as key-value
|
||||
separator.
|
||||
|
||||
Link = "Link" ":" #link-value
|
||||
link-value = "<" URI-Reference ">" *( ";" link-param )
|
||||
link-param = ( ( "rel" "=" relation-types )
|
||||
| ( "anchor" "=" <"> URI-Reference <"> )
|
||||
| ( "rev" "=" relation-types )
|
||||
| ( "hreflang" "=" Language-Tag )
|
||||
| ( "media" "=" ( MediaDesc | ( <"> MediaDesc <"> ) ) )
|
||||
| ( "title" "=" quoted-string )
|
||||
| ( "title*" "=" ext-value )
|
||||
| ( "type" "=" ( media-type | quoted-mt ) )
|
||||
| ( link-extension ) )
|
||||
link-extension = ( parmname [ "=" ( ptoken | quoted-string ) ] )
|
||||
| ( ext-name-star "=" ext-value )
|
||||
ext-name-star = parmname "*" ; reserved for RFC2231-profiled
|
||||
; extensions. Whitespace NOT
|
||||
; allowed in between.
|
||||
ptoken = 1*ptokenchar
|
||||
ptokenchar = "!" | "#" | "$" | "%" | "&" | "'" | "("
|
||||
| ")" | "*" | "+" | "-" | "." | "/" | DIGIT
|
||||
| ":" | "<" | "=" | ">" | "?" | "@" | ALPHA
|
||||
| "[" | "]" | "^" | "_" | "`" | "{" | "|"
|
||||
| "}" | "~"
|
||||
media-type = type-name "/" subtype-name
|
||||
quoted-mt = <"> media-type <">
|
||||
relation-types = relation-type
|
||||
| <"> relation-type *( 1*SP relation-type ) <">
|
||||
relation-type = reg-rel-type | ext-rel-type
|
||||
reg-rel-type = LOALPHA *( LOALPHA | DIGIT | "." | "-" )
|
||||
ext-rel-type = URI
|
||||
|
||||
See more: rfc5988
|
||||
*/
|
||||
bool
|
||||
find_key_value (const char *start, const char *end, const char *key, char **value)
|
||||
{
|
||||
const char *eq;
|
||||
size_t key_len = strlen (key);
|
||||
const char *val_beg, *val_end;
|
||||
const char *key_beg;
|
||||
|
||||
key_beg = start;
|
||||
|
||||
while (key_beg + key_len + 1 < end)
|
||||
{
|
||||
/* Skip whitespaces. */
|
||||
while (key_beg + key_len + 1 < end && c_isspace (*key_beg))
|
||||
key_beg++;
|
||||
if (strncmp (key_beg, key, key_len))
|
||||
{
|
||||
/* Find next token. */
|
||||
while (key_beg + key_len + 1 < end && *key_beg != ';')
|
||||
key_beg++;
|
||||
key_beg++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Find equals sign. */
|
||||
eq = key_beg + key_len;
|
||||
while (eq < end && c_isspace (*eq))
|
||||
eq++;
|
||||
if (eq == end)
|
||||
return false;
|
||||
if (*eq != '=')
|
||||
{
|
||||
key_beg++;
|
||||
continue;
|
||||
}
|
||||
|
||||
val_beg = eq + 1;
|
||||
while (val_beg < end && c_isspace (*val_beg))
|
||||
val_beg++;
|
||||
if (val_beg == end)
|
||||
return false;
|
||||
val_end = val_beg + 1;
|
||||
while (val_end < end && *val_end != ';' && !c_isspace (*val_end))
|
||||
val_end++;
|
||||
*value = xstrndup (val_beg, val_end - val_beg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*value = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This is to check if given token exists in HTTP header. Tokens are
|
||||
separated by ';'. */
|
||||
bool
|
||||
has_key (const char *start, const char *end, const char *key)
|
||||
{
|
||||
const char *pos; /* Here would the token start. */
|
||||
size_t key_len = strlen (key);
|
||||
|
||||
pos = start;
|
||||
while (pos + key_len <= end)
|
||||
{
|
||||
/* Skip whitespaces at beginning. */
|
||||
while (pos + key_len <= end && c_isspace (*pos))
|
||||
pos++;
|
||||
|
||||
/* Does the prefix of pos match our key? */
|
||||
if (strncmp (key, pos, key_len))
|
||||
{
|
||||
/* This was not a match.
|
||||
Skip all characters until beginning of next token. */
|
||||
while (pos + key_len <= end && *pos != ';')
|
||||
pos++;
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* key is prefix of pos. Is it the exact token or just a prefix? */
|
||||
pos += key_len;
|
||||
while (pos < end && c_isspace (*pos))
|
||||
pos++;
|
||||
if (pos == end || *pos == ';')
|
||||
return true;
|
||||
|
||||
/* This was not a match (just a prefix).
|
||||
Skip all characters until beginning of next token. */
|
||||
while (pos + key_len <= end && *pos != ';')
|
||||
pos++;
|
||||
pos++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Find all key=value pairs delimited with ';' or ','. This is intended for
|
||||
Digest header parsing.
|
||||
The usage is:
|
||||
|
||||
const char *pos;
|
||||
for (pos = header_beg; pos = find_key_values (pos, header_end, &key, &val); pos++)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
*/
|
||||
const char *
|
||||
find_key_values (const char *start, const char *end, char **key, char **value)
|
||||
{
|
||||
const char *key_start, *key_end;
|
||||
const char *eq;
|
||||
const char *val_start, *val_end;
|
||||
|
||||
eq = start;
|
||||
while (eq < end && *eq != '=')
|
||||
{
|
||||
/* Skip tokens without =value part. */
|
||||
if (*eq == ';' || *eq == ',')
|
||||
start = eq + 1;
|
||||
eq++;
|
||||
}
|
||||
|
||||
if (eq >= end)
|
||||
return NULL;
|
||||
|
||||
key_start = start;
|
||||
while (key_start < eq && c_isspace (*key_start))
|
||||
key_start++;
|
||||
|
||||
key_end = eq - 1;
|
||||
while (key_end > key_start && c_isspace (*key_end))
|
||||
key_end--;
|
||||
key_end++;
|
||||
|
||||
val_start = eq + 1;
|
||||
while (val_start < end && c_isspace (*val_start))
|
||||
val_start++;
|
||||
|
||||
val_end = val_start;
|
||||
|
||||
while (val_end < end && *val_end != ';' &&
|
||||
*val_end != ',' && !c_isspace (*val_end))
|
||||
val_end++;
|
||||
|
||||
*key = xstrndup (key_start, key_end - key_start);
|
||||
*value = xstrndup (val_start, val_end - val_start);
|
||||
|
||||
/* Skip trailing whitespaces. */
|
||||
while (val_end < end && c_isspace (*val_end))
|
||||
val_end++;
|
||||
|
||||
return val_end;
|
||||
}
|
||||
|
||||
#ifdef TESTING
|
||||
const char *
|
||||
test_find_key_values (void)
|
||||
{
|
||||
static const char *header_data = "key1=val1;key2=val2 ;key3=val3; key4=val4"\
|
||||
" ; key5=val5;key6 =val6;key7= val7; "\
|
||||
"key8 = val8 ; key9 = val9 "\
|
||||
" ,key10= val10,key11,key12=val12";
|
||||
static const struct
|
||||
{
|
||||
const char *key;
|
||||
const char *val;
|
||||
} test_array[] =
|
||||
{
|
||||
{ "key1", "val1" },
|
||||
{ "key2", "val2" },
|
||||
{ "key3", "val3" },
|
||||
{ "key4", "val4" },
|
||||
{ "key5", "val5" },
|
||||
{ "key6", "val6" },
|
||||
{ "key7", "val7" },
|
||||
{ "key8", "val8" },
|
||||
{ "key9", "val9" },
|
||||
{ "key10", "val10" },
|
||||
{ "key12", "val12" }
|
||||
};
|
||||
const char *pos;
|
||||
char *key, *value;
|
||||
size_t i = 0;
|
||||
|
||||
for (pos = header_data; (pos = find_key_values (pos,
|
||||
header_data + strlen (header_data),
|
||||
&key, &value)); pos++)
|
||||
{
|
||||
mu_assert ("test_find_key_values: wrong result",
|
||||
!strcmp (test_array[i].val, value) &&
|
||||
!strcmp (test_array[i].key, key));
|
||||
xfree (key);
|
||||
xfree (value);
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
test_find_key_value (void)
|
||||
{
|
||||
static const char *header_data = "key1=val1;key2=val2 ;key3=val3; key4=val4"\
|
||||
" ; key5=val5;key6 =val6;key7= val7; "\
|
||||
"key8 = val8 ; key9 = val9 ";
|
||||
static const struct
|
||||
{
|
||||
const char *key;
|
||||
const char *val;
|
||||
bool result;
|
||||
} test_array[] =
|
||||
{
|
||||
{ "key1", "val1", true },
|
||||
{ "key2", "val2", true },
|
||||
{ "key3", "val3", true },
|
||||
{ "key4", "val4", true },
|
||||
{ "key5", "val5", true },
|
||||
{ "key6", "val6", true },
|
||||
{ "key7", "val7", true },
|
||||
{ "key8", "val8", true },
|
||||
{ "key9", "val9", true },
|
||||
{ "key10", NULL, false },
|
||||
{ "ey1", NULL, false },
|
||||
{ "dey1", NULL, false }
|
||||
};
|
||||
size_t i;
|
||||
|
||||
for (i=0; i < countof (test_array); ++i)
|
||||
{
|
||||
bool result;
|
||||
char *value;
|
||||
|
||||
result = find_key_value (header_data,
|
||||
header_data + strlen(header_data),
|
||||
test_array[i].key, &value);
|
||||
|
||||
mu_assert ("test_find_key_value: wrong result",
|
||||
result == test_array[i].result &&
|
||||
((!test_array[i].result && !value) ||
|
||||
!strcmp (value, test_array[i].val)));
|
||||
|
||||
xfree (value);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
test_has_key (void)
|
||||
{
|
||||
static const char *header_data = "key1=val2;token1;xyz; token2;xyz;token3 ;"\
|
||||
"xyz; token4 ;xyz; token5 ";
|
||||
struct
|
||||
{
|
||||
const char *token;
|
||||
bool result;
|
||||
} test_array[] =
|
||||
{
|
||||
{ "key1=val2", true },
|
||||
{ "token1", true },
|
||||
{ "token2", true },
|
||||
{ "token3", true },
|
||||
{ "token4", true },
|
||||
{ "token5", true },
|
||||
{ "token6", false },
|
||||
{ "oken1", false },
|
||||
{ "poken1", false },
|
||||
{ "key1=val2", true }
|
||||
};
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < countof (test_array); ++i)
|
||||
mu_assert ("test_has_key: wrong result",
|
||||
has_key (header_data, header_data + strlen (header_data),
|
||||
test_array[i].token) == test_array[i].result);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_METALINK */
|
||||
60
src/metalink.h
Normal file
60
src/metalink.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* Declarations for metalink.c.
|
||||
Copyright (C) 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
GNU Wget 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.
|
||||
|
||||
GNU Wget 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 Wget. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this program, or any covered work, by linking or
|
||||
combining it with the OpenSSL project's OpenSSL library (or a
|
||||
modified version of that library), containing parts covered by the
|
||||
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
|
||||
grants you additional permission to convey the resulting work.
|
||||
Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work. */
|
||||
#if ! defined METALINK_H && defined HAVE_METALINK
|
||||
#define METALINK_H
|
||||
|
||||
#include <metalink/metalink_types.h>
|
||||
#include "wget.h"
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
# define RES_TYPE_SUPPORTED(x)\
|
||||
((!x) || !strcmp (x, "http") || !strcmp (x, "https") || !strcmp (x, "ftp") || !strcmp (x, "ftps"))
|
||||
#else
|
||||
# define RES_TYPE_SUPPORTED(x)\
|
||||
((!x) || !strcmp (x, "ftp") || !strcmp (x, "http"))
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PRI 999999
|
||||
#define VALID_PRI_RANGE(x) ((x) > 0 && (x) < 1000000)
|
||||
|
||||
uerr_t retrieve_from_metalink (const metalink_t *metalink);
|
||||
|
||||
int metalink_res_cmp (const void *res1, const void *res2);
|
||||
|
||||
bool find_key_value (const char *start,
|
||||
const char *end,
|
||||
const char *key,
|
||||
char **value);
|
||||
bool has_key (const char *start, const char *end, const char *key);
|
||||
const char *find_key_values (const char *start,
|
||||
const char *end,
|
||||
char **key,
|
||||
char **value);
|
||||
|
||||
#endif /* METALINK_H */
|
||||
@@ -1,7 +1,7 @@
|
||||
/* mswindows.c -- Windows-specific support
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -42,6 +42,7 @@ as that of the covered work. */
|
||||
|
||||
#include "utils.h"
|
||||
#include "url.h"
|
||||
#include "exits.h"
|
||||
|
||||
#ifndef ES_SYSTEM_REQUIRED
|
||||
#define ES_SYSTEM_REQUIRED 0x00000001
|
||||
@@ -61,7 +62,7 @@ void
|
||||
xsleep (double seconds)
|
||||
{
|
||||
#if defined(HAVE_USLEEP) && defined(HAVE_SLEEP)
|
||||
if (seconds > 1000)
|
||||
if (seconds >= 1)
|
||||
{
|
||||
/* Explained in utils.c. */
|
||||
sleep (seconds);
|
||||
@@ -84,11 +85,11 @@ windows_main (char **exec_name)
|
||||
if (p)
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ws_cleanup (void)
|
||||
{
|
||||
xfree ((char*)exec_name);
|
||||
xfree (exec_name);
|
||||
WSACleanup ();
|
||||
}
|
||||
|
||||
@@ -164,8 +165,8 @@ fake_fork_child (void)
|
||||
if (new_log_fp)
|
||||
{
|
||||
info->logfile_changed = true;
|
||||
strncpy (info->lfilename, opt.lfilename, sizeof (info->lfilename));
|
||||
info->lfilename[sizeof (info->lfilename) - 1] = '\0';
|
||||
snprintf (info->lfilename, sizeof (info->lfilename), "%s",
|
||||
opt.lfilename);
|
||||
fclose (new_log_fp);
|
||||
}
|
||||
}
|
||||
@@ -308,7 +309,7 @@ cleanup:
|
||||
|
||||
/* We're the parent. If all is well, terminate. */
|
||||
if (rv)
|
||||
exit (0);
|
||||
exit (WGET_EXIT_SUCCESS);
|
||||
|
||||
/* We failed, return. */
|
||||
}
|
||||
@@ -323,7 +324,7 @@ fork_to_background (void)
|
||||
rv = fake_fork_child ();
|
||||
if (rv < 0)
|
||||
{
|
||||
fprintf (stderr, "fake_fork_child() failed\n");
|
||||
fprintf (stderr, _("fake_fork_child() failed\n"));
|
||||
abort ();
|
||||
}
|
||||
else if (rv == 0)
|
||||
@@ -331,7 +332,7 @@ fork_to_background (void)
|
||||
/* We're the parent. */
|
||||
fake_fork ();
|
||||
/* If fake_fork() returns, it failed. */
|
||||
fprintf (stderr, "fake_fork() failed\n");
|
||||
fprintf (stderr, _("fake_fork() failed\n"));
|
||||
abort ();
|
||||
}
|
||||
/* If we get here, we're the child. */
|
||||
@@ -366,8 +367,8 @@ static int old_percentage = -1;
|
||||
void
|
||||
ws_changetitle (const char *url)
|
||||
{
|
||||
xfree_null (title_buf);
|
||||
xfree_null (curr_url);
|
||||
xfree (title_buf);
|
||||
xfree (curr_url);
|
||||
title_buf = xmalloc (strlen (url) + 20);
|
||||
curr_url = xstrdup (url);
|
||||
old_percentage = -1;
|
||||
@@ -461,7 +462,7 @@ ws_startup (void)
|
||||
{
|
||||
fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
|
||||
exec_name);
|
||||
exit (1);
|
||||
exit (WGET_EXIT_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
if (data.wVersion < requested)
|
||||
@@ -469,14 +470,14 @@ ws_startup (void)
|
||||
fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
|
||||
exec_name);
|
||||
WSACleanup ();
|
||||
exit (1);
|
||||
exit (WGET_EXIT_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
atexit (ws_cleanup);
|
||||
set_sleep_mode ();
|
||||
SetConsoleCtrlHandler (ws_handler, TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* run_with_timeout Windows implementation. */
|
||||
|
||||
/* Stack size 0 uses default thread stack-size (reserve+commit).
|
||||
@@ -620,35 +621,35 @@ inet_ntop (int af, const void *src, char *dst, socklen_t cnt)
|
||||
void
|
||||
set_windows_fd_as_blocking_socket (int fd)
|
||||
{
|
||||
/* 04/2011
|
||||
/* 04/2011
|
||||
gnulib select() converts blocking sockets to nonblocking in windows
|
||||
discussed here:
|
||||
http://old.nabble.com/blocking-socket-is-nonblocking-after-calling-gnulib-
|
||||
select%28%29-in-windows-td31432857.html
|
||||
|
||||
wget uses blocking sockets so we must convert them back to blocking.
|
||||
*/
|
||||
int ret = 0;
|
||||
int wsagle = 0;
|
||||
const int zero = 0;
|
||||
*/
|
||||
int ret = 0;
|
||||
int wsagle = 0;
|
||||
const int zero = 0;
|
||||
|
||||
do
|
||||
{
|
||||
if(wsagle == WSAEINPROGRESS)
|
||||
Sleep(1); /* use windows sleep */
|
||||
|
||||
WSASetLastError (0);
|
||||
ret = ioctl (fd, FIONBIO, &zero);
|
||||
wsagle = WSAGetLastError();
|
||||
}
|
||||
do
|
||||
{
|
||||
if(wsagle == WSAEINPROGRESS)
|
||||
Sleep(1); /* use windows sleep */
|
||||
|
||||
WSASetLastError (0);
|
||||
ret = ioctl (fd, FIONBIO, &zero);
|
||||
wsagle = WSAGetLastError ();
|
||||
}
|
||||
while (ret && (wsagle == WSAEINPROGRESS));
|
||||
|
||||
if(ret)
|
||||
if(ret)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl() failed. The socket could not be set as blocking.\n" );
|
||||
_("ioctl() failed. The socket could not be set as blocking.\n") );
|
||||
DEBUGP (("Winsock error: %d\n", WSAGetLastError ()));
|
||||
abort ();
|
||||
}
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Declarations for windows
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -57,13 +57,6 @@ as that of the covered work. */
|
||||
/* Declares getpid(). */
|
||||
#include <process.h>
|
||||
|
||||
#ifndef S_ISDIR
|
||||
# define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
|
||||
#endif
|
||||
#ifndef S_ISLNK
|
||||
# define S_ISLNK(a) 0
|
||||
#endif
|
||||
|
||||
/* We have strcasecmp and strncasecmp, just under different names. */
|
||||
#ifndef HAVE_STRCASECMP
|
||||
# define strcasecmp stricmp
|
||||
@@ -90,18 +83,6 @@ typedef __int64 wgint;
|
||||
# define strtoll_type __int64
|
||||
#endif
|
||||
|
||||
/* Windows has no symlink, therefore no lstat. Without symlinks lstat
|
||||
is equivalent to stat anyway. */
|
||||
#define lstat stat
|
||||
|
||||
/* Define LFS aliases for stat and fstat. */
|
||||
#ifdef stat_alias
|
||||
# define stat(f, b) stat_alias (f, b)
|
||||
#endif
|
||||
#ifdef fstat_alias
|
||||
# define fstat(f, b) fstat_alias (f, b)
|
||||
#endif
|
||||
|
||||
#define PATH_SEPARATOR '\\'
|
||||
|
||||
/* Additional declarations needed for IPv6: */
|
||||
|
||||
94
src/netrc.c
94
src/netrc.c
@@ -1,5 +1,5 @@
|
||||
/* Read and parse the .netrc file to get hosts, accounts, and passwords.
|
||||
Copyright (C) 1996, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Copyright (C) 1996, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
@@ -44,10 +44,16 @@ as that of the covered work. */
|
||||
|
||||
#define NETRC_FILE_NAME ".netrc"
|
||||
|
||||
acc_t *netrc_list;
|
||||
static acc_t *netrc_list;
|
||||
|
||||
static acc_t *parse_netrc (const char *);
|
||||
|
||||
void
|
||||
netrc_cleanup(void)
|
||||
{
|
||||
free_netrc (netrc_list);
|
||||
}
|
||||
|
||||
/* Return the correct user and password, given the host, user (as
|
||||
given in the URL), and password (as given in the URL). May return
|
||||
NULL.
|
||||
@@ -155,57 +161,13 @@ search_netrc (const char *host, const char **acc, const char **passwd,
|
||||
|
||||
#ifdef STANDALONE
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/* Normally, these functions would be defined by your package. */
|
||||
# define xmalloc malloc
|
||||
# define xfree free
|
||||
# define xfree(p) do { free ((void *) (p)); p = NULL; } while (0)
|
||||
# define xstrdup strdup
|
||||
|
||||
# define xrealloc realloc
|
||||
|
||||
/* Read a line from FP. The function reallocs the storage as needed
|
||||
to accomodate for any length of the line. Reallocs are done
|
||||
storage exponentially, doubling the storage after each overflow to
|
||||
minimize the number of calls to realloc() and fgets(). The newline
|
||||
character at the end of line is retained.
|
||||
|
||||
After end-of-file is encountered without anything being read, NULL
|
||||
is returned. NULL is also returned on error. To distinguish
|
||||
between these two cases, use the stdio function ferror(). */
|
||||
|
||||
char *
|
||||
read_whole_line (FILE *fp)
|
||||
{
|
||||
int length = 0;
|
||||
int bufsize = 81;
|
||||
char *line = xmalloc (bufsize);
|
||||
|
||||
while (fgets (line + length, bufsize - length, fp))
|
||||
{
|
||||
length += strlen (line + length);
|
||||
assert (length > 0);
|
||||
if (line[length - 1] == '\n')
|
||||
break;
|
||||
/* fgets() guarantees to read the whole line, or to use up the
|
||||
space we've given it. We can double the buffer
|
||||
unconditionally. */
|
||||
bufsize <<= 1;
|
||||
line = xrealloc (line, bufsize);
|
||||
}
|
||||
if (length == 0 || ferror (fp))
|
||||
{
|
||||
xfree (line);
|
||||
return NULL;
|
||||
}
|
||||
if (length + 1 < bufsize)
|
||||
/* Relieve the memory from our exponential greediness. We say
|
||||
`length + 1' because the terminating \0 is not included in
|
||||
LENGTH. We don't need to zero-terminate the string ourselves,
|
||||
though, because fgets() does that. */
|
||||
line = xrealloc (line, length + 1);
|
||||
return line;
|
||||
}
|
||||
#endif /* STANDALONE */
|
||||
|
||||
/* Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is
|
||||
@@ -221,9 +183,9 @@ maybe_add_to_list (acc_t **newentry, acc_t **list)
|
||||
if (a && ! a->acc)
|
||||
{
|
||||
/* Free any allocated space. */
|
||||
xfree_null (a->host);
|
||||
xfree_null (a->acc);
|
||||
xfree_null (a->passwd);
|
||||
xfree (a->host);
|
||||
xfree (a->acc);
|
||||
xfree (a->passwd);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -264,10 +226,11 @@ static acc_t *
|
||||
parse_netrc (const char *path)
|
||||
{
|
||||
FILE *fp;
|
||||
char *line, *p, *tok;
|
||||
char *line = NULL, *p, *tok;
|
||||
const char *premature_token;
|
||||
acc_t *current, *retval;
|
||||
int ln, qmark;
|
||||
size_t bufsize = 0;
|
||||
|
||||
/* The latest token we've seen in the file. */
|
||||
enum
|
||||
@@ -290,7 +253,7 @@ parse_netrc (const char *path)
|
||||
premature_token = NULL;
|
||||
|
||||
/* While there are lines in the file... */
|
||||
while ((line = read_whole_line (fp)) != NULL)
|
||||
while (getline (&line, &bufsize, fp) > 0)
|
||||
{
|
||||
ln ++;
|
||||
|
||||
@@ -423,10 +386,9 @@ parse_netrc (const char *path)
|
||||
exec_name, path, ln, tok);
|
||||
}
|
||||
}
|
||||
|
||||
xfree (line);
|
||||
}
|
||||
|
||||
xfree (line);
|
||||
fclose (fp);
|
||||
|
||||
/* Finalize the last machine entry we found. */
|
||||
@@ -462,9 +424,9 @@ free_netrc(acc_t *l)
|
||||
while (l)
|
||||
{
|
||||
t = l->next;
|
||||
xfree_null (l->acc);
|
||||
xfree_null (l->passwd);
|
||||
xfree_null (l->host);
|
||||
xfree (l->acc);
|
||||
xfree (l->passwd);
|
||||
xfree (l->host);
|
||||
xfree (l);
|
||||
l = t;
|
||||
}
|
||||
@@ -484,18 +446,26 @@ main (int argc, char **argv)
|
||||
if (argc < 2 || argc > 3)
|
||||
{
|
||||
fprintf (stderr, _("Usage: %s NETRC [HOSTNAME]\n"), argv[0]);
|
||||
exit (1);
|
||||
exit (WGET_EXIT_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
program_name = argv[0];
|
||||
file = argv[1];
|
||||
target = argv[2];
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
/* Set the current locale. */
|
||||
setlocale (LC_ALL, "");
|
||||
/* Set the text message domain. */
|
||||
bindtextdomain ("wget", LOCALEDIR);
|
||||
textdomain ("wget");
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
if (stat (file, &sb))
|
||||
{
|
||||
fprintf (stderr, _("%s: cannot stat %s: %s\n"), argv[0], file,
|
||||
strerror (errno));
|
||||
exit (1);
|
||||
exit (WGET_EXIT_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
head = parse_netrc (file);
|
||||
@@ -534,14 +504,14 @@ main (int argc, char **argv)
|
||||
|
||||
/* Exit if we found the target. */
|
||||
if (target)
|
||||
exit (0);
|
||||
exit (WGET_EXIT_SUCCESS);
|
||||
a = a->next;
|
||||
}
|
||||
|
||||
/* Exit with failure if we had a target, success otherwise. */
|
||||
if (target)
|
||||
exit (1);
|
||||
exit (WGET_EXIT_GENERIC_ERROR);
|
||||
|
||||
exit (0);
|
||||
exit (WGET_EXIT_SUCCESS);
|
||||
}
|
||||
#endif /* STANDALONE */
|
||||
|
||||
11
src/netrc.h
11
src/netrc.h
@@ -1,6 +1,6 @@
|
||||
/* Declarations for netrc.c
|
||||
Copyright (C) 1996, 1996, 1997, 2007, 2008, 2009, 2010, 2011 Free
|
||||
Software Foundation, Inc.
|
||||
Copyright (C) 1996, 1996, 1997, 2007, 2008, 2009, 2010, 2011, 2015
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -33,14 +33,15 @@ as that of the covered work. */
|
||||
|
||||
typedef struct _acc_t
|
||||
{
|
||||
char *host; /* NULL if this is the default machine
|
||||
entry. */
|
||||
char *host; /* NULL if this is the default machine
|
||||
entry. */
|
||||
char *acc;
|
||||
char *passwd; /* NULL if there is no password. */
|
||||
char *passwd; /* NULL if there is no password. */
|
||||
struct _acc_t *next;
|
||||
} acc_t;
|
||||
|
||||
void search_netrc (const char *, const char **, const char **, int);
|
||||
void free_netrc (acc_t *l);
|
||||
void netrc_cleanup(void);
|
||||
|
||||
#endif /* NETRC_H */
|
||||
|
||||
345
src/openssl.c
345
src/openssl.c
@@ -1,6 +1,6 @@
|
||||
/* SSL support via OpenSSL library.
|
||||
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
|
||||
2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||
2009, 2010, 2011, 2012, 2015 Free Software Foundation, Inc.
|
||||
Originally contributed by Christian Fraenkel.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
@@ -35,11 +35,17 @@ as that of the covered work. */
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bio.h>
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x00907000
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/engine.h>
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include "connect.h"
|
||||
@@ -86,9 +92,11 @@ init_prng (void)
|
||||
if (RAND_status ())
|
||||
return;
|
||||
|
||||
#ifdef HAVE_RAND_EGD
|
||||
/* Get random data from EGD if opt.egd_file was used. */
|
||||
if (opt.egd_file && *opt.egd_file)
|
||||
RAND_egd (opt.egd_file);
|
||||
#endif
|
||||
|
||||
if (RAND_status ())
|
||||
return;
|
||||
@@ -153,6 +161,9 @@ key_type_to_ssl_type (enum keyfile_type type)
|
||||
}
|
||||
}
|
||||
|
||||
/* SSL has been initialized */
|
||||
static int ssl_true_initialized = 0;
|
||||
|
||||
/* Create an SSL Context and set default paths etc. Called the first
|
||||
time an HTTP download is attempted.
|
||||
|
||||
@@ -162,6 +173,15 @@ bool
|
||||
ssl_init (void)
|
||||
{
|
||||
SSL_METHOD const *meth;
|
||||
long ssl_options = 0;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x00907000
|
||||
if (ssl_true_initialized == 0)
|
||||
{
|
||||
OPENSSL_config (NULL);
|
||||
ssl_true_initialized = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ssl_ctx)
|
||||
/* The SSL has already been initialized. */
|
||||
@@ -176,6 +196,12 @@ ssl_init (void)
|
||||
goto error;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x00907000
|
||||
OPENSSL_load_builtin_modules();
|
||||
ENGINE_load_builtin_engines();
|
||||
CONF_modules_load_file(NULL, NULL,
|
||||
CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE);
|
||||
#endif
|
||||
SSL_library_init ();
|
||||
SSL_load_error_strings ();
|
||||
SSLeay_add_all_algorithms ();
|
||||
@@ -183,21 +209,48 @@ ssl_init (void)
|
||||
|
||||
switch (opt.secure_protocol)
|
||||
{
|
||||
case secure_protocol_auto:
|
||||
meth = SSLv23_client_method ();
|
||||
break;
|
||||
#ifndef OPENSSL_NO_SSL2
|
||||
case secure_protocol_sslv2:
|
||||
meth = SSLv2_client_method ();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_SSL3
|
||||
case secure_protocol_sslv3:
|
||||
meth = SSLv3_client_method ();
|
||||
break;
|
||||
#endif
|
||||
|
||||
case secure_protocol_auto:
|
||||
case secure_protocol_pfs:
|
||||
meth = SSLv23_client_method ();
|
||||
ssl_options |= SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
|
||||
break;
|
||||
case secure_protocol_tlsv1:
|
||||
meth = TLSv1_client_method ();
|
||||
break;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10001000
|
||||
case secure_protocol_tlsv1_1:
|
||||
meth = TLSv1_1_client_method ();
|
||||
break;
|
||||
|
||||
case secure_protocol_tlsv1_2:
|
||||
meth = TLSv1_2_client_method ();
|
||||
break;
|
||||
#else
|
||||
case secure_protocol_tlsv1_1:
|
||||
logprintf (LOG_NOTQUIET, _("Your OpenSSL version is too old to support TLSv1.1\n"));
|
||||
goto error;
|
||||
|
||||
case secure_protocol_tlsv1_2:
|
||||
logprintf (LOG_NOTQUIET, _("Your OpenSSL version is too old to support TLSv1.2\n"));
|
||||
goto error;
|
||||
#endif
|
||||
|
||||
default:
|
||||
logprintf (LOG_NOTQUIET, _("OpenSSL: unimplemented 'secure-protocol' option value %d\n"), opt.secure_protocol);
|
||||
logprintf (LOG_NOTQUIET, _("Please report this issue to bug-wget@gnu.org\n"));
|
||||
abort ();
|
||||
}
|
||||
|
||||
@@ -207,9 +260,30 @@ ssl_init (void)
|
||||
if (!ssl_ctx)
|
||||
goto error;
|
||||
|
||||
if (ssl_options)
|
||||
SSL_CTX_set_options (ssl_ctx, ssl_options);
|
||||
|
||||
/* OpenSSL ciphers: https://www.openssl.org/docs/apps/ciphers.html
|
||||
* Since we want a good protection, we also use HIGH (that excludes MD4 ciphers and some more)
|
||||
*/
|
||||
if (opt.secure_protocol == secure_protocol_pfs)
|
||||
SSL_CTX_set_cipher_list (ssl_ctx, "HIGH:MEDIUM:!RC4:!SRP:!PSK:!RSA:!aNULL@STRENGTH");
|
||||
|
||||
SSL_CTX_set_default_verify_paths (ssl_ctx);
|
||||
SSL_CTX_load_verify_locations (ssl_ctx, opt.ca_cert, opt.ca_directory);
|
||||
|
||||
if (opt.crl_file)
|
||||
{
|
||||
X509_STORE *store = SSL_CTX_get_cert_store (ssl_ctx);
|
||||
X509_LOOKUP *lookup;
|
||||
|
||||
if (!(lookup = X509_STORE_add_lookup (store, X509_LOOKUP_file ()))
|
||||
|| (!X509_load_crl_file (lookup, opt.crl_file, X509_FILETYPE_PEM)))
|
||||
goto error;
|
||||
|
||||
X509_STORE_set_flags (store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
|
||||
}
|
||||
|
||||
/* SSL_VERIFY_NONE instructs OpenSSL not to abort SSL_connect if the
|
||||
certificate is invalid. We verify the certificate separately in
|
||||
ssl_check_certificate, which provides much better diagnostics
|
||||
@@ -219,10 +293,17 @@ ssl_init (void)
|
||||
/* Use the private key from the cert file unless otherwise specified. */
|
||||
if (opt.cert_file && !opt.private_key)
|
||||
{
|
||||
opt.private_key = opt.cert_file;
|
||||
opt.private_key = xstrdup (opt.cert_file);
|
||||
opt.private_key_type = opt.cert_type;
|
||||
}
|
||||
|
||||
/* Use cert from private key file unless otherwise specified. */
|
||||
if (opt.private_key && !opt.cert_file)
|
||||
{
|
||||
opt.cert_file = xstrdup (opt.private_key);
|
||||
opt.cert_type = opt.private_key_type;
|
||||
}
|
||||
|
||||
if (opt.cert_file)
|
||||
if (SSL_CTX_use_certificate_file (ssl_ctx, opt.cert_file,
|
||||
key_type_to_ssl_type (opt.cert_type))
|
||||
@@ -251,28 +332,55 @@ ssl_init (void)
|
||||
return false;
|
||||
}
|
||||
|
||||
struct openssl_transport_context {
|
||||
struct openssl_transport_context
|
||||
{
|
||||
SSL *conn; /* SSL connection handle */
|
||||
SSL_SESSION *sess; /* SSL session info */
|
||||
char *last_error; /* last error printed with openssl_errstr */
|
||||
};
|
||||
|
||||
struct openssl_read_args
|
||||
{
|
||||
int fd;
|
||||
struct openssl_transport_context *ctx;
|
||||
char *buf;
|
||||
int bufsize;
|
||||
int retval;
|
||||
};
|
||||
|
||||
static void openssl_read_callback(void *arg)
|
||||
{
|
||||
struct openssl_read_args *args = (struct openssl_read_args *) arg;
|
||||
struct openssl_transport_context *ctx = args->ctx;
|
||||
SSL *conn = ctx->conn;
|
||||
char *buf = args->buf;
|
||||
int bufsize = args->bufsize;
|
||||
int ret;
|
||||
|
||||
do
|
||||
ret = SSL_read (conn, buf, bufsize);
|
||||
while (ret == -1 && SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
|
||||
&& errno == EINTR);
|
||||
args->retval = ret;
|
||||
}
|
||||
|
||||
static int
|
||||
openssl_read (int fd, char *buf, int bufsize, void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct openssl_transport_context *ctx = arg;
|
||||
SSL *conn = ctx->conn;
|
||||
do
|
||||
ret = SSL_read (conn, buf, bufsize);
|
||||
while (ret == -1
|
||||
&& SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
|
||||
&& errno == EINTR);
|
||||
struct openssl_read_args args;
|
||||
args.fd = fd;
|
||||
args.buf = buf;
|
||||
args.bufsize = bufsize;
|
||||
args.ctx = (struct openssl_transport_context*) arg;
|
||||
|
||||
return ret;
|
||||
if (run_with_timeout(opt.read_timeout, openssl_read_callback, &args)) {
|
||||
return -1;
|
||||
}
|
||||
return args.retval;
|
||||
}
|
||||
|
||||
static int
|
||||
openssl_write (int fd, char *buf, int bufsize, void *arg)
|
||||
openssl_write (int fd _GL_UNUSED, char *buf, int bufsize, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
struct openssl_transport_context *ctx = arg;
|
||||
@@ -314,7 +422,7 @@ openssl_peek (int fd, char *buf, int bufsize, void *arg)
|
||||
}
|
||||
|
||||
static const char *
|
||||
openssl_errstr (int fd, void *arg)
|
||||
openssl_errstr (int fd _GL_UNUSED, void *arg)
|
||||
{
|
||||
struct openssl_transport_context *ctx = arg;
|
||||
unsigned long errcode;
|
||||
@@ -326,7 +434,7 @@ openssl_errstr (int fd, void *arg)
|
||||
return NULL;
|
||||
|
||||
/* Get rid of previous contents of ctx->last_error, if any. */
|
||||
xfree_null (ctx->last_error);
|
||||
xfree (ctx->last_error);
|
||||
|
||||
/* Iterate over OpenSSL's error stack and accumulate errors in the
|
||||
last_error buffer, separated by "; ". This is better than using
|
||||
@@ -370,7 +478,7 @@ openssl_close (int fd, void *arg)
|
||||
|
||||
SSL_shutdown (conn);
|
||||
SSL_free (conn);
|
||||
xfree_null (ctx->last_error);
|
||||
xfree (ctx->last_error);
|
||||
xfree (ctx);
|
||||
|
||||
close (fd);
|
||||
@@ -386,6 +494,35 @@ static struct transport_implementation openssl_transport = {
|
||||
openssl_peek, openssl_errstr, openssl_close
|
||||
};
|
||||
|
||||
struct scwt_context
|
||||
{
|
||||
SSL *ssl;
|
||||
int result;
|
||||
};
|
||||
|
||||
static void
|
||||
ssl_connect_with_timeout_callback(void *arg)
|
||||
{
|
||||
struct scwt_context *ctx = (struct scwt_context *)arg;
|
||||
ctx->result = SSL_connect(ctx->ssl);
|
||||
}
|
||||
|
||||
static const char *
|
||||
_sni_hostname(const char *hostname)
|
||||
{
|
||||
size_t len = strlen(hostname);
|
||||
|
||||
char *sni_hostname = xmemdup(hostname, len + 1);
|
||||
|
||||
/* Remove trailing dot(s) to fix #47408.
|
||||
* Regarding RFC 6066 (SNI): The hostname is represented as a byte
|
||||
* string using ASCII encoding without a trailing dot. */
|
||||
while (len && sni_hostname[--len] == '.')
|
||||
sni_hostname[len] = 0;
|
||||
|
||||
return sni_hostname;
|
||||
}
|
||||
|
||||
/* Perform the SSL handshake on file descriptor FD, which is assumed
|
||||
to be connected to an SSL server. The SSL handle provided by
|
||||
OpenSSL is registered with the file descriptor FD using
|
||||
@@ -395,9 +532,10 @@ static struct transport_implementation openssl_transport = {
|
||||
Returns true on success, false on failure. */
|
||||
|
||||
bool
|
||||
ssl_connect_wget (int fd, const char *hostname)
|
||||
ssl_connect_wget (int fd, const char *hostname, int *continue_session)
|
||||
{
|
||||
SSL *conn;
|
||||
struct scwt_context scwt_ctx;
|
||||
struct openssl_transport_context *ctx;
|
||||
|
||||
DEBUGP (("Initiating SSL handshake.\n"));
|
||||
@@ -407,29 +545,52 @@ ssl_connect_wget (int fd, const char *hostname)
|
||||
if (!conn)
|
||||
goto error;
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
|
||||
/* If the SSL library was build with support for ServerNameIndication
|
||||
/* If the SSL library was built with support for ServerNameIndication
|
||||
then use it whenever we have a hostname. If not, don't, ever. */
|
||||
if (! is_valid_ip_address (hostname))
|
||||
{
|
||||
if (! SSL_set_tlsext_host_name (conn, hostname))
|
||||
{
|
||||
DEBUGP (("Failed to set TLS server-name indication."));
|
||||
goto error;
|
||||
}
|
||||
const char *sni_hostname = _sni_hostname(hostname);
|
||||
|
||||
long rc = SSL_set_tlsext_host_name (conn, sni_hostname);
|
||||
xfree(sni_hostname);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
DEBUGP (("Failed to set TLS server-name indication."));
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (continue_session)
|
||||
{
|
||||
/* attempt to resume a previous SSL session */
|
||||
ctx = (struct openssl_transport_context *) fd_transport_context (*continue_session);
|
||||
if (!ctx || !ctx->sess || !SSL_set_session (conn, ctx->sess))
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifndef FD_TO_SOCKET
|
||||
# define FD_TO_SOCKET(X) (X)
|
||||
#endif
|
||||
if (!SSL_set_fd (conn, FD_TO_SOCKET (fd)))
|
||||
goto error;
|
||||
SSL_set_connect_state (conn);
|
||||
if (SSL_connect (conn) <= 0 || conn->state != SSL_ST_OK)
|
||||
|
||||
scwt_ctx.ssl = conn;
|
||||
if (run_with_timeout(opt.read_timeout, ssl_connect_with_timeout_callback,
|
||||
&scwt_ctx)) {
|
||||
DEBUGP (("SSL handshake timed out.\n"));
|
||||
goto timeout;
|
||||
}
|
||||
if (scwt_ctx.result <= 0 || SSL_state(conn) != SSL_ST_OK)
|
||||
goto error;
|
||||
|
||||
ctx = xnew0 (struct openssl_transport_context);
|
||||
ctx->conn = conn;
|
||||
ctx->sess = SSL_get0_session (conn);
|
||||
if (!ctx->sess)
|
||||
logprintf (LOG_NOTQUIET, "WARNING: Could not save SSL session data for socket %d\n", fd);
|
||||
|
||||
/* Register FD with Wget's transport layer, i.e. arrange that our
|
||||
functions are used for reading, writing, and polling. */
|
||||
@@ -441,6 +602,7 @@ ssl_connect_wget (int fd, const char *hostname)
|
||||
error:
|
||||
DEBUGP (("SSL handshake failed.\n"));
|
||||
print_errors ();
|
||||
timeout:
|
||||
if (conn)
|
||||
SSL_free (conn);
|
||||
return false;
|
||||
@@ -489,6 +651,86 @@ pattern_match (const char *pattern, const char *string)
|
||||
return *n == '\0';
|
||||
}
|
||||
|
||||
static char *_get_rfc2253_formatted (X509_NAME *name)
|
||||
{
|
||||
int len;
|
||||
char *out = NULL;
|
||||
BIO* b;
|
||||
|
||||
if ((b = BIO_new (BIO_s_mem ())))
|
||||
{
|
||||
if (X509_NAME_print_ex (b, name, 0, XN_FLAG_RFC2253) >= 0
|
||||
&& (len = BIO_number_written (b)) > 0)
|
||||
{
|
||||
out = xmalloc (len + 1);
|
||||
BIO_read (b, out, len);
|
||||
out[len] = 0;
|
||||
}
|
||||
BIO_free (b);
|
||||
}
|
||||
|
||||
return out ? out : xstrdup("");
|
||||
}
|
||||
|
||||
/*
|
||||
* Heavily modified from:
|
||||
* https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#OpenSSL
|
||||
*/
|
||||
static bool
|
||||
pkp_pin_peer_pubkey (X509* cert, const char *pinnedpubkey)
|
||||
{
|
||||
/* Scratch */
|
||||
int len1 = 0, len2 = 0;
|
||||
char *buff1 = NULL, *temp = NULL;
|
||||
|
||||
/* Result is returned to caller */
|
||||
bool result = false;
|
||||
|
||||
/* if a path wasn't specified, don't pin */
|
||||
if (!pinnedpubkey)
|
||||
return true;
|
||||
|
||||
if (!cert)
|
||||
return result;
|
||||
|
||||
/* Begin Gyrations to get the subjectPublicKeyInfo */
|
||||
/* Thanks to Viktor Dukhovni on the OpenSSL mailing list */
|
||||
|
||||
/* https://groups.google.com/group/mailing.openssl.users/browse_thread
|
||||
/thread/d61858dae102c6c7 */
|
||||
len1 = i2d_X509_PUBKEY (X509_get_X509_PUBKEY (cert), NULL);
|
||||
if (len1 < 1)
|
||||
goto cleanup; /* failed */
|
||||
|
||||
/* https://www.openssl.org/docs/crypto/buffer.html */
|
||||
buff1 = temp = OPENSSL_malloc (len1);
|
||||
if (!buff1)
|
||||
goto cleanup; /* failed */
|
||||
|
||||
/* https://www.openssl.org/docs/crypto/d2i_X509.html */
|
||||
len2 = i2d_X509_PUBKEY (X509_get_X509_PUBKEY (cert), (unsigned char **) &temp);
|
||||
|
||||
/*
|
||||
* These checks are verifying we got back the same values as when we
|
||||
* sized the buffer. It's pretty weak since they should always be the
|
||||
* same. But it gives us something to test.
|
||||
*/
|
||||
if ((len1 != len2) || !temp || ((temp - buff1) != len1))
|
||||
goto cleanup; /* failed */
|
||||
|
||||
/* End Gyrations */
|
||||
|
||||
/* The one good exit point */
|
||||
result = wg_pin_peer_pubkey (pinnedpubkey, buff1, len1);
|
||||
|
||||
cleanup:
|
||||
/* https://www.openssl.org/docs/crypto/buffer.html */
|
||||
if (NULL != buff1)
|
||||
OPENSSL_free (buff1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Verify the validity of the certificate presented by the server.
|
||||
Also check that the "common name" of the server, as presented by
|
||||
its certificate, corresponds to HOST. (HOST typically comes from
|
||||
@@ -512,6 +754,7 @@ ssl_check_certificate (int fd, const char *host)
|
||||
long vresult;
|
||||
bool success = true;
|
||||
bool alt_name_checked = false;
|
||||
bool pinsuccess = opt.pinnedpubkey == NULL;
|
||||
|
||||
/* If the user has specified --no-check-cert, we still want to warn
|
||||
him about problems with the server's certificate. */
|
||||
@@ -521,6 +764,10 @@ ssl_check_certificate (int fd, const char *host)
|
||||
SSL *conn = ctx->conn;
|
||||
assert (conn != NULL);
|
||||
|
||||
/* The user explicitly said to not check for the certificate. */
|
||||
if (opt.check_cert == CHECK_CERT_QUIET && pinsuccess)
|
||||
return success;
|
||||
|
||||
cert = SSL_get_peer_certificate (conn);
|
||||
if (!cert)
|
||||
{
|
||||
@@ -532,23 +779,25 @@ ssl_check_certificate (int fd, const char *host)
|
||||
|
||||
IF_DEBUG
|
||||
{
|
||||
char *subject = X509_NAME_oneline (X509_get_subject_name (cert), 0, 0);
|
||||
char *issuer = X509_NAME_oneline (X509_get_issuer_name (cert), 0, 0);
|
||||
char *subject = _get_rfc2253_formatted (X509_get_subject_name (cert));
|
||||
char *issuer = _get_rfc2253_formatted (X509_get_issuer_name (cert));
|
||||
DEBUGP (("certificate:\n subject: %s\n issuer: %s\n",
|
||||
quotearg_n_style (0, escape_quoting_style, subject),
|
||||
quotearg_n_style (1, escape_quoting_style, issuer)));
|
||||
OPENSSL_free (subject);
|
||||
OPENSSL_free (issuer);
|
||||
xfree (subject);
|
||||
xfree (issuer);
|
||||
}
|
||||
|
||||
vresult = SSL_get_verify_result (conn);
|
||||
if (vresult != X509_V_OK)
|
||||
{
|
||||
char *issuer = X509_NAME_oneline (X509_get_issuer_name (cert), 0, 0);
|
||||
char *issuer = _get_rfc2253_formatted (X509_get_issuer_name (cert));
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("%s: cannot verify %s's certificate, issued by %s:\n"),
|
||||
severity, quotearg_n_style (0, escape_quoting_style, host),
|
||||
quote_n (1, issuer));
|
||||
xfree(issuer);
|
||||
|
||||
/* Try to print more user-friendly (and translated) messages for
|
||||
the frequent verification errors. */
|
||||
switch (vresult)
|
||||
@@ -595,9 +844,12 @@ ssl_check_certificate (int fd, const char *host)
|
||||
{
|
||||
/* Test subject alternative names */
|
||||
|
||||
/* SNI hostname must not have a trailing dot */
|
||||
const char *sni_hostname = _sni_hostname(host);
|
||||
|
||||
/* Do we want to check for dNSNAmes or ipAddresses (see RFC 2818)?
|
||||
* Signal it by host_in_octet_string. */
|
||||
ASN1_OCTET_STRING *host_in_octet_string = a2i_IPADDRESS (host);
|
||||
ASN1_OCTET_STRING *host_in_octet_string = a2i_IPADDRESS (sni_hostname);
|
||||
|
||||
int numaltnames = sk_GENERAL_NAME_num (subjectAltNames);
|
||||
int i;
|
||||
@@ -632,9 +884,9 @@ ssl_check_certificate (int fd, const char *host)
|
||||
if (0 <= ASN1_STRING_to_UTF8 (&name_in_utf8, name->d.dNSName))
|
||||
{
|
||||
/* Compare and check for NULL attack in ASN1_STRING */
|
||||
if (pattern_match ((char *)name_in_utf8, host) &&
|
||||
if (pattern_match ((char *)name_in_utf8, sni_hostname) &&
|
||||
(strlen ((char *)name_in_utf8) ==
|
||||
ASN1_STRING_length (name->d.dNSName)))
|
||||
(size_t) ASN1_STRING_length (name->d.dNSName)))
|
||||
{
|
||||
OPENSSL_free (name_in_utf8);
|
||||
break;
|
||||
@@ -644,7 +896,7 @@ ssl_check_certificate (int fd, const char *host)
|
||||
}
|
||||
}
|
||||
}
|
||||
sk_GENERAL_NAME_free (subjectAltNames);
|
||||
sk_GENERAL_NAME_pop_free(subjectAltNames, GENERAL_NAME_free);
|
||||
if (host_in_octet_string)
|
||||
ASN1_OCTET_STRING_free(host_in_octet_string);
|
||||
|
||||
@@ -653,11 +905,13 @@ ssl_check_certificate (int fd, const char *host)
|
||||
logprintf (LOG_NOTQUIET,
|
||||
_("%s: no certificate subject alternative name matches\n"
|
||||
"\trequested host name %s.\n"),
|
||||
severity, quote_n (1, host));
|
||||
severity, quote_n (1, sni_hostname));
|
||||
success = false;
|
||||
}
|
||||
|
||||
xfree(sni_hostname);
|
||||
}
|
||||
|
||||
|
||||
if (alt_name_checked == false)
|
||||
{
|
||||
/* Test commomName */
|
||||
@@ -698,7 +952,7 @@ ssl_check_certificate (int fd, const char *host)
|
||||
|
||||
xentry = X509_NAME_get_entry(xname,i);
|
||||
sdata = X509_NAME_ENTRY_get_data(xentry);
|
||||
if (strlen (common_name) != ASN1_STRING_length (sdata))
|
||||
if (strlen (common_name) != (size_t) ASN1_STRING_length (sdata))
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, _("\
|
||||
%s: certificate common name is invalid (contains a NUL character).\n\
|
||||
@@ -710,6 +964,13 @@ ssl_check_certificate (int fd, const char *host)
|
||||
}
|
||||
}
|
||||
|
||||
pinsuccess = pkp_pin_peer_pubkey (cert, opt.pinnedpubkey);
|
||||
if (!pinsuccess)
|
||||
{
|
||||
logprintf (LOG_ALWAYS, _("The public key does not match pinned public key!\n"));
|
||||
success = false;
|
||||
}
|
||||
|
||||
|
||||
if (success)
|
||||
DEBUGP (("X509 certificate successfully verified and matches host %s\n",
|
||||
@@ -717,13 +978,13 @@ ssl_check_certificate (int fd, const char *host)
|
||||
X509_free (cert);
|
||||
|
||||
no_cert:
|
||||
if (opt.check_cert && !success)
|
||||
if (opt.check_cert == CHECK_CERT_ON && !success)
|
||||
logprintf (LOG_NOTQUIET, _("\
|
||||
To connect to %s insecurely, use `--no-check-certificate'.\n"),
|
||||
quotearg_style (escape_quoting_style, host));
|
||||
|
||||
/* Allow --no-check-cert to disable certificate checking. */
|
||||
return opt.check_cert ? success : true;
|
||||
/* never return true if pinsuccess fails */
|
||||
return !pinsuccess ? false : (opt.check_cert == CHECK_CERT_ON ? success : true);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
350
src/options.h
350
src/options.h
@@ -1,7 +1,7 @@
|
||||
/* struct options.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -29,239 +29,278 @@ Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work. */
|
||||
|
||||
enum CHECK_CERT_MODES
|
||||
{
|
||||
CHECK_CERT_OFF,
|
||||
CHECK_CERT_ON,
|
||||
CHECK_CERT_QUIET
|
||||
};
|
||||
|
||||
struct options
|
||||
{
|
||||
int verbose; /* Are we verbose? (First set to -1,
|
||||
int verbose; /* Are we verbose? (First set to -1,
|
||||
hence not boolean.) */
|
||||
bool quiet; /* Are we quiet? */
|
||||
int ntry; /* Number of tries per URL */
|
||||
bool retry_connrefused; /* Treat CONNREFUSED as non-fatal. */
|
||||
bool background; /* Whether we should work in background. */
|
||||
bool ignore_length; /* Do we heed content-length at all? */
|
||||
bool recursive; /* Are we recursive? */
|
||||
bool spanhost; /* Do we span across hosts in
|
||||
recursion? */
|
||||
bool quiet; /* Are we quiet? */
|
||||
int ntry; /* Number of tries per URL */
|
||||
bool retry_connrefused; /* Treat CONNREFUSED as non-fatal. */
|
||||
bool background; /* Whether we should work in background. */
|
||||
bool ignore_length; /* Do we heed content-length at all? */
|
||||
bool recursive; /* Are we recursive? */
|
||||
bool spanhost; /* Do we span across hosts in
|
||||
recursion? */
|
||||
int max_redirect; /* Maximum number of times we'll allow
|
||||
a page to redirect. */
|
||||
bool relative_only; /* Follow only relative links. */
|
||||
bool no_parent; /* Restrict access to the parent
|
||||
directory. */
|
||||
int reclevel; /* Maximum level of recursion */
|
||||
bool dirstruct; /* Do we build the directory structure
|
||||
as we go along? */
|
||||
bool no_dirstruct; /* Do we hate dirstruct? */
|
||||
int cut_dirs; /* Number of directory components to cut. */
|
||||
bool add_hostdir; /* Do we add hostname directory? */
|
||||
bool protocol_directories; /* Whether to prepend "http"/"ftp" to dirs. */
|
||||
bool noclobber; /* Disables clobbering of existing
|
||||
data. */
|
||||
bool unlink; /* remove file before clobbering */
|
||||
char *dir_prefix; /* The top of directory tree */
|
||||
char *lfilename; /* Log filename */
|
||||
char *input_filename; /* Input filename */
|
||||
char *choose_config; /* Specified config file */
|
||||
bool force_html; /* Is the input file an HTML file? */
|
||||
bool relative_only; /* Follow only relative links. */
|
||||
bool no_parent; /* Restrict access to the parent
|
||||
directory. */
|
||||
int reclevel; /* Maximum level of recursion */
|
||||
bool dirstruct; /* Do we build the directory structure
|
||||
as we go along? */
|
||||
bool no_dirstruct; /* Do we hate dirstruct? */
|
||||
int cut_dirs; /* Number of directory components to cut. */
|
||||
bool add_hostdir; /* Do we add hostname directory? */
|
||||
bool protocol_directories; /* Whether to prepend "http"/"ftp" to dirs. */
|
||||
bool noclobber; /* Disables clobbering of existing data. */
|
||||
bool unlink; /* remove file before clobbering */
|
||||
char *dir_prefix; /* The top of directory tree */
|
||||
char *lfilename; /* Log filename */
|
||||
char *input_filename; /* Input filename */
|
||||
#ifdef HAVE_METALINK
|
||||
char *input_metalink; /* Input metalink file */
|
||||
bool metalink_over_http; /* Use Metalink if present in HTTP response */
|
||||
char *preferred_location; /* Preferred location for Metalink resources */
|
||||
#endif
|
||||
char *choose_config; /* Specified config file */
|
||||
bool noconfig; /* Ignore all config files? */
|
||||
bool force_html; /* Is the input file an HTML file? */
|
||||
|
||||
char *default_page; /* Alternative default page (index file) */
|
||||
|
||||
bool spider; /* Is Wget in spider mode? */
|
||||
bool spider; /* Is Wget in spider mode? */
|
||||
|
||||
char **accepts; /* List of patterns to accept. */
|
||||
char **rejects; /* List of patterns to reject. */
|
||||
char **excludes; /* List of excluded FTP directories. */
|
||||
char **includes; /* List of FTP directories to
|
||||
follow. */
|
||||
bool ignore_case; /* Whether to ignore case when
|
||||
matching dirs and files */
|
||||
char **accepts; /* List of patterns to accept. */
|
||||
char **rejects; /* List of patterns to reject. */
|
||||
const char **excludes; /* List of excluded FTP directories. */
|
||||
const char **includes; /* List of FTP directories to
|
||||
follow. */
|
||||
bool ignore_case; /* Whether to ignore case when
|
||||
matching dirs and files */
|
||||
|
||||
char *acceptregex_s; /* Patterns to accept (a regex string). */
|
||||
char *rejectregex_s; /* Patterns to reject (a regex string). */
|
||||
void *acceptregex; /* Patterns to accept (a regex struct). */
|
||||
void *rejectregex; /* Patterns to reject (a regex struct). */
|
||||
char *acceptregex_s; /* Patterns to accept (a regex string). */
|
||||
char *rejectregex_s; /* Patterns to reject (a regex string). */
|
||||
void *acceptregex; /* Patterns to accept (a regex struct). */
|
||||
void *rejectregex; /* Patterns to reject (a regex struct). */
|
||||
enum {
|
||||
#ifdef HAVE_LIBPCRE
|
||||
regex_type_pcre,
|
||||
#endif
|
||||
regex_type_posix
|
||||
} regex_type; /* The regex library. */
|
||||
void *(*regex_compile_fun)(const char *); /* Function to compile a regex. */
|
||||
} regex_type; /* The regex library. */
|
||||
void *(*regex_compile_fun)(const char *); /* Function to compile a regex. */
|
||||
bool (*regex_match_fun)(const void *, const char *); /* Function to match a string to a regex. */
|
||||
|
||||
char **domains; /* See host.c */
|
||||
#ifdef HAVE_LIBCARES
|
||||
char *bind_dns_address;
|
||||
char *dns_servers;
|
||||
#endif
|
||||
|
||||
char **domains; /* See host.c */
|
||||
char **exclude_domains;
|
||||
bool dns_cache; /* whether we cache DNS lookups. */
|
||||
bool dns_cache; /* whether we cache DNS lookups. */
|
||||
|
||||
char **follow_tags; /* List of HTML tags to recursively follow. */
|
||||
char **ignore_tags; /* List of HTML tags to ignore if recursing. */
|
||||
|
||||
bool follow_ftp; /* Are FTP URL-s followed in recursive
|
||||
retrieving? */
|
||||
bool retr_symlinks; /* Whether we retrieve symlinks in
|
||||
FTP. */
|
||||
char *output_document; /* The output file to which the
|
||||
documents will be printed. */
|
||||
char *warc_filename; /* WARC output filename */
|
||||
char *warc_tempdir; /* WARC temp dir */
|
||||
char *warc_cdx_dedup_filename; /* CDX file to be used for deduplication. */
|
||||
bool follow_ftp; /* Are FTP URL-s followed in recursive
|
||||
retrieving? */
|
||||
bool retr_symlinks; /* Whether we retrieve symlinks in
|
||||
FTP. */
|
||||
char *output_document; /* The output file to which the
|
||||
documents will be printed. */
|
||||
char *warc_filename; /* WARC output filename */
|
||||
char *warc_tempdir; /* WARC temp dir */
|
||||
char *warc_cdx_dedup_filename;/* CDX file to be used for deduplication. */
|
||||
wgint warc_maxsize; /* WARC max archive size */
|
||||
bool warc_compression_enabled; /* For GZIP compression. */
|
||||
bool warc_digests_enabled; /* For SHA1 digests. */
|
||||
bool warc_cdx_enabled; /* Create CDX files? */
|
||||
bool warc_keep_log; /* Store the log file in a WARC record. */
|
||||
char **warc_user_headers; /* User-defined WARC header(s). */
|
||||
bool warc_compression_enabled;/* For GZIP compression. */
|
||||
bool warc_digests_enabled; /* For SHA1 digests. */
|
||||
bool warc_cdx_enabled; /* Create CDX files? */
|
||||
bool warc_keep_log; /* Store the log file in a WARC record. */
|
||||
char **warc_user_headers; /* User-defined WARC header(s). */
|
||||
|
||||
char *user; /* Generic username */
|
||||
char *passwd; /* Generic password */
|
||||
char *user; /* Generic username */
|
||||
char *passwd; /* Generic password */
|
||||
bool ask_passwd; /* Ask for password? */
|
||||
|
||||
bool always_rest; /* Always use REST. */
|
||||
char *ftp_user; /* FTP username */
|
||||
char *ftp_passwd; /* FTP password */
|
||||
bool netrc; /* Whether to read .netrc. */
|
||||
bool ftp_glob; /* FTP globbing */
|
||||
bool ftp_pasv; /* Passive FTP. */
|
||||
bool always_rest; /* Always use REST. */
|
||||
wgint start_pos; /* Start position of a download. */
|
||||
char *ftp_user; /* FTP username */
|
||||
char *ftp_passwd; /* FTP password */
|
||||
bool netrc; /* Whether to read .netrc. */
|
||||
bool ftp_glob; /* FTP globbing */
|
||||
bool ftp_pasv; /* Passive FTP. */
|
||||
|
||||
char *http_user; /* HTTP username. */
|
||||
char *http_passwd; /* HTTP password. */
|
||||
char **user_headers; /* User-defined header(s). */
|
||||
bool http_keep_alive; /* whether we use keep-alive */
|
||||
char *http_user; /* HTTP username. */
|
||||
char *http_passwd; /* HTTP password. */
|
||||
char **user_headers; /* User-defined header(s). */
|
||||
bool http_keep_alive; /* whether we use keep-alive */
|
||||
|
||||
bool use_proxy; /* Do we use proxy? */
|
||||
bool allow_cache; /* Do we allow server-side caching? */
|
||||
bool use_proxy; /* Do we use proxy? */
|
||||
bool allow_cache; /* Do we allow server-side caching? */
|
||||
char *http_proxy, *ftp_proxy, *https_proxy;
|
||||
char **no_proxy;
|
||||
char *base_href;
|
||||
char *progress_type; /* progress indicator type. */
|
||||
char *progress_type; /* progress indicator type. */
|
||||
int show_progress; /* Show only the progress bar */
|
||||
bool noscroll; /* Don't scroll the filename in the progressbar */
|
||||
char *proxy_user; /*oli*/
|
||||
char *proxy_passwd;
|
||||
|
||||
double read_timeout; /* The read/write timeout. */
|
||||
double dns_timeout; /* The DNS timeout. */
|
||||
double connect_timeout; /* The connect timeout. */
|
||||
double read_timeout; /* The read/write timeout. */
|
||||
double dns_timeout; /* The DNS timeout. */
|
||||
double connect_timeout; /* The connect timeout. */
|
||||
|
||||
bool random_wait; /* vary from 0 .. wait secs by random()? */
|
||||
double wait; /* The wait period between retrievals. */
|
||||
double waitretry; /* The wait period between retries. - HEH */
|
||||
bool use_robots; /* Do we heed robots.txt? */
|
||||
bool random_wait; /* vary from 0 .. wait secs by random()? */
|
||||
double wait; /* The wait period between retrievals. */
|
||||
double waitretry; /* The wait period between retries. - HEH */
|
||||
bool use_robots; /* Do we heed robots.txt? */
|
||||
|
||||
wgint limit_rate; /* Limit the download rate to this
|
||||
many bps. */
|
||||
SUM_SIZE_INT quota; /* Maximum file size to download and
|
||||
store. */
|
||||
wgint limit_rate; /* Limit the download rate to this
|
||||
many bps. */
|
||||
SUM_SIZE_INT quota; /* Maximum file size to download and
|
||||
store. */
|
||||
|
||||
bool server_response; /* Do we print server response? */
|
||||
bool save_headers; /* Do we save headers together with
|
||||
file? */
|
||||
bool content_on_error; /* Do we output the content when the HTTP
|
||||
status code indicates a server error */
|
||||
bool server_response; /* Do we print server response? */
|
||||
bool save_headers; /* Do we save headers together with
|
||||
file? */
|
||||
bool content_on_error; /* Do we output the content when the HTTP
|
||||
status code indicates a server error */
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
bool debug; /* Debugging on/off */
|
||||
#endif
|
||||
bool debug; /* Debugging on/off */
|
||||
|
||||
#ifdef USE_WATT32
|
||||
bool wdebug; /* Watt-32 tcp/ip debugging on/off */
|
||||
#endif
|
||||
|
||||
bool timestamping; /* Whether to use time-stamping. */
|
||||
bool timestamping; /* Whether to use time-stamping. */
|
||||
bool if_modified_since; /* Whether to use conditional get requests. */
|
||||
|
||||
bool backup_converted; /* Do we save pre-converted files as *.orig? */
|
||||
bool backups; /* Are numeric backups made? */
|
||||
bool backup_converted; /* Do we save pre-converted files as *.orig? */
|
||||
int backups; /* Are numeric backups made? */
|
||||
|
||||
char *useragent; /* User-Agent string, which can be set
|
||||
to something other than Wget. */
|
||||
char *referer; /* Naughty Referer, which can be
|
||||
set to something other than
|
||||
NULL. */
|
||||
bool convert_links; /* Will the links be converted
|
||||
locally? */
|
||||
bool remove_listing; /* Do we remove .listing files
|
||||
generated by FTP? */
|
||||
bool htmlify; /* Do we HTML-ify the OS-dependent
|
||||
listings? */
|
||||
char *useragent; /* User-Agent string, which can be set
|
||||
to something other than Wget. */
|
||||
char *referer; /* Naughty Referer, which can be
|
||||
set to something other than
|
||||
NULL. */
|
||||
bool convert_links; /* Will the links be converted
|
||||
locally? */
|
||||
bool convert_file_only; /* Convert only the file portion of the URI (i.e. basename).
|
||||
Leave everything else untouched. */
|
||||
|
||||
bool remove_listing; /* Do we remove .listing files
|
||||
generated by FTP? */
|
||||
bool htmlify; /* Do we HTML-ify the OS-dependent
|
||||
listings? */
|
||||
|
||||
char *dot_style;
|
||||
wgint dot_bytes; /* How many bytes in a printing
|
||||
dot. */
|
||||
int dots_in_line; /* How many dots in one line. */
|
||||
int dot_spacing; /* How many dots between spacings. */
|
||||
wgint dot_bytes; /* How many bytes in a printing
|
||||
dot. */
|
||||
int dots_in_line; /* How many dots in one line. */
|
||||
int dot_spacing; /* How many dots between spacings. */
|
||||
|
||||
bool delete_after; /* Whether the files will be deleted
|
||||
after download. */
|
||||
bool delete_after; /* Whether the files will be deleted
|
||||
after download. */
|
||||
|
||||
bool adjust_extension; /* Use ".html" extension on all text/html? */
|
||||
bool adjust_extension; /* Use ".html" extension on all text/html? */
|
||||
|
||||
bool page_requisites; /* Whether we need to download all files
|
||||
necessary to display a page properly. */
|
||||
char *bind_address; /* What local IP address to bind to. */
|
||||
bool page_requisites; /* Whether we need to download all files
|
||||
necessary to display a page properly. */
|
||||
char *bind_address; /* What local IP address to bind to. */
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
enum {
|
||||
secure_protocol_auto,
|
||||
secure_protocol_sslv2,
|
||||
secure_protocol_sslv3,
|
||||
secure_protocol_tlsv1
|
||||
} secure_protocol; /* type of secure protocol to use. */
|
||||
bool check_cert; /* whether to validate the server's cert */
|
||||
char *cert_file; /* external client certificate to use. */
|
||||
char *private_key; /* private key file (if not internal). */
|
||||
secure_protocol_tlsv1,
|
||||
secure_protocol_tlsv1_1,
|
||||
secure_protocol_tlsv1_2,
|
||||
secure_protocol_pfs
|
||||
} secure_protocol; /* type of secure protocol to use. */
|
||||
int check_cert; /* whether to validate the server's cert */
|
||||
char *cert_file; /* external client certificate to use. */
|
||||
char *private_key; /* private key file (if not internal). */
|
||||
enum keyfile_type {
|
||||
keyfile_pem,
|
||||
keyfile_asn1
|
||||
} cert_type; /* type of client certificate file */
|
||||
} cert_type; /* type of client certificate file */
|
||||
enum keyfile_type
|
||||
private_key_type; /* type of private key file */
|
||||
private_key_type; /* type of private key file */
|
||||
|
||||
char *ca_directory; /* CA directory (hash files) */
|
||||
char *ca_cert; /* CA certificate file to use */
|
||||
char *ca_directory; /* CA directory (hash files) */
|
||||
char *ca_cert; /* CA certificate file to use */
|
||||
char *crl_file; /* file with CRLs */
|
||||
|
||||
char *pinnedpubkey; /* Public key (PEM/DER) file, or any number
|
||||
of base64 encoded sha256 hashes preceded by
|
||||
\'sha256//\' and seperated by \';\', to verify
|
||||
peer against */
|
||||
|
||||
char *random_file; /* file with random data to seed the PRNG */
|
||||
char *egd_file; /* file name of the egd daemon socket */
|
||||
char *random_file; /* file with random data to seed the PRNG */
|
||||
char *egd_file; /* file name of the egd daemon socket */
|
||||
bool https_only; /* whether to follow HTTPS only */
|
||||
bool ftps_resume_ssl;
|
||||
bool ftps_fallback_to_ftp;
|
||||
bool ftps_implicit;
|
||||
bool ftps_clear_data_connection;
|
||||
#endif /* HAVE_SSL */
|
||||
|
||||
bool cookies; /* whether cookies are used. */
|
||||
char *cookies_input; /* file we're loading the cookies from. */
|
||||
char *cookies_output; /* file we're saving the cookies to. */
|
||||
bool keep_session_cookies; /* whether session cookies should be
|
||||
saved and loaded. */
|
||||
bool cookies; /* whether cookies are used. */
|
||||
char *cookies_input; /* file we're loading the cookies from. */
|
||||
char *cookies_output; /* file we're saving the cookies to. */
|
||||
bool keep_session_cookies; /* whether session cookies should be
|
||||
saved and loaded. */
|
||||
|
||||
char *post_data; /* POST query string */
|
||||
char *post_file_name; /* File to post */
|
||||
char *post_data; /* POST query string */
|
||||
char *post_file_name; /* File to post */
|
||||
char *method; /* HTTP Method to use in Header */
|
||||
char *body_data; /* HTTP Method Data String */
|
||||
char *body_file; /* HTTP Method File */
|
||||
|
||||
enum {
|
||||
restrict_unix,
|
||||
restrict_vms,
|
||||
restrict_windows
|
||||
} restrict_files_os; /* file name restriction ruleset. */
|
||||
bool restrict_files_ctrl; /* non-zero if control chars in URLs
|
||||
are restricted from appearing in
|
||||
generated file names. */
|
||||
} restrict_files_os; /* file name restriction ruleset. */
|
||||
bool restrict_files_ctrl; /* non-zero if control chars in URLs
|
||||
are restricted from appearing in
|
||||
generated file names. */
|
||||
bool restrict_files_nonascii; /* non-zero if bytes with values greater
|
||||
than 127 are restricted. */
|
||||
enum {
|
||||
restrict_no_case_restriction,
|
||||
restrict_lowercase,
|
||||
restrict_uppercase
|
||||
} restrict_files_case; /* file name case restriction. */
|
||||
} restrict_files_case; /* file name case restriction. */
|
||||
|
||||
bool strict_comments; /* whether strict SGML comments are
|
||||
enforced. */
|
||||
bool strict_comments; /* whether strict SGML comments are
|
||||
enforced. */
|
||||
|
||||
bool preserve_perm; /* whether remote permissions are used
|
||||
or that what is set by umask. */
|
||||
or that what is set by umask. */
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
bool ipv4_only; /* IPv4 connections have been requested. */
|
||||
bool ipv6_only; /* IPv4 connections have been requested. */
|
||||
bool ipv4_only; /* IPv4 connections have been requested. */
|
||||
bool ipv6_only; /* IPv4 connections have been requested. */
|
||||
#endif
|
||||
enum {
|
||||
prefer_ipv4,
|
||||
prefer_ipv6,
|
||||
prefer_none
|
||||
} prefer_family; /* preferred address family when more
|
||||
than one type is available */
|
||||
} prefer_family; /* preferred address family when more
|
||||
than one type is available */
|
||||
|
||||
bool content_disposition; /* Honor HTTP Content-Disposition header. */
|
||||
bool content_disposition; /* Honor HTTP Content-Disposition header. */
|
||||
bool auth_without_challenge; /* Issue Basic authentication creds without
|
||||
waiting for a challenge. */
|
||||
|
||||
@@ -274,12 +313,19 @@ struct options
|
||||
int ftp_stmlf; /* Force Stream_LF format for binary FTP. */
|
||||
#endif /* def __VMS */
|
||||
|
||||
bool useservertimestamps; /* Update downloaded files' timestamps to
|
||||
match those on server? */
|
||||
bool useservertimestamps; /* Update downloaded files' timestamps to
|
||||
match those on server? */
|
||||
|
||||
bool show_all_dns_entries; /* Show all the DNS entries when resolving a
|
||||
name. */
|
||||
bool show_all_dns_entries; /* Show all the DNS entries when resolving a
|
||||
name. */
|
||||
bool report_bps; /*Output bandwidth in bits format*/
|
||||
|
||||
char *rejected_log; /* The file to log rejected URLS to. */
|
||||
|
||||
#ifdef HAVE_HSTS
|
||||
bool hsts;
|
||||
char *hsts_file;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern struct options opt;
|
||||
|
||||
370
src/progress.c
370
src/progress.c
@@ -1,6 +1,6 @@
|
||||
/* Download progress.
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
2010, 2011 Free Software Foundation, Inc.
|
||||
2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -36,38 +36,41 @@ as that of the covered work. */
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_WCHAR_H
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
#include <wchar.h>
|
||||
#include <mbiter.h>
|
||||
|
||||
#include "progress.h"
|
||||
#include "utils.h"
|
||||
#include "retr.h"
|
||||
#include "c-strcase.h"
|
||||
|
||||
struct progress_implementation {
|
||||
const char *name;
|
||||
bool interactive;
|
||||
void *(*create) (wgint, wgint);
|
||||
void *(*create) (const char *, wgint, wgint);
|
||||
void (*update) (void *, wgint, double);
|
||||
void (*draw) (void *);
|
||||
void (*finish) (void *, double);
|
||||
void (*set_params) (const char *);
|
||||
void (*set_params) (char *);
|
||||
};
|
||||
|
||||
/* Necessary forward declarations. */
|
||||
|
||||
static void *dot_create (wgint, wgint);
|
||||
static void *dot_create (const char *, wgint, wgint);
|
||||
static void dot_update (void *, wgint, double);
|
||||
static void dot_finish (void *, double);
|
||||
static void dot_set_params (const char *);
|
||||
static void dot_draw (void *);
|
||||
static void dot_set_params (char *);
|
||||
|
||||
static void *bar_create (wgint, wgint);
|
||||
static void *bar_create (const char *, wgint, wgint);
|
||||
static void bar_update (void *, wgint, double);
|
||||
static void bar_draw (void *);
|
||||
static void bar_finish (void *, double);
|
||||
static void bar_set_params (const char *);
|
||||
static void bar_set_params (char *);
|
||||
|
||||
static struct progress_implementation implementations[] = {
|
||||
{ "dot", 0, dot_create, dot_update, dot_finish, dot_set_params },
|
||||
{ "bar", 1, bar_create, bar_update, bar_finish, bar_set_params }
|
||||
{ "dot", 0, dot_create, dot_update, dot_draw, dot_finish, dot_set_params },
|
||||
{ "bar", 1, bar_create, bar_update, bar_draw, bar_finish, bar_set_params }
|
||||
};
|
||||
static struct progress_implementation *current_impl;
|
||||
static int current_impl_locked;
|
||||
@@ -109,7 +112,7 @@ set_progress_implementation (const char *name)
|
||||
{
|
||||
size_t i, namelen;
|
||||
struct progress_implementation *pi = implementations;
|
||||
const char *colon;
|
||||
char *colon;
|
||||
|
||||
if (!name)
|
||||
name = DEFAULT_PROGRESS_IMPLEMENTATION;
|
||||
@@ -151,7 +154,7 @@ progress_schedule_redirect (void)
|
||||
advance. */
|
||||
|
||||
void *
|
||||
progress_create (wgint initial, wgint total)
|
||||
progress_create (const char *f_download, wgint initial, wgint total)
|
||||
{
|
||||
/* Check if the log status has changed under our feet. */
|
||||
if (output_redirected)
|
||||
@@ -161,7 +164,7 @@ progress_create (wgint initial, wgint total)
|
||||
output_redirected = 0;
|
||||
}
|
||||
|
||||
return current_impl->create (initial, total);
|
||||
return current_impl->create (f_download, initial, total);
|
||||
}
|
||||
|
||||
/* Return true if the progress gauge is "interactive", i.e. if it can
|
||||
@@ -170,7 +173,7 @@ progress_create (wgint initial, wgint total)
|
||||
and current update. */
|
||||
|
||||
bool
|
||||
progress_interactive_p (void *progress)
|
||||
progress_interactive_p (void *progress _GL_UNUSED)
|
||||
{
|
||||
return current_impl->interactive;
|
||||
}
|
||||
@@ -182,6 +185,7 @@ void
|
||||
progress_update (void *progress, wgint howmuch, double dltime)
|
||||
{
|
||||
current_impl->update (progress, howmuch, dltime);
|
||||
current_impl->draw (progress);
|
||||
}
|
||||
|
||||
/* Tell the progress gauge to clean up. Calling this will free the
|
||||
@@ -192,7 +196,7 @@ progress_finish (void *progress, double dltime)
|
||||
{
|
||||
current_impl->finish (progress, dltime);
|
||||
}
|
||||
|
||||
|
||||
/* Dot-printing. */
|
||||
|
||||
struct dot_progress {
|
||||
@@ -204,6 +208,7 @@ struct dot_progress {
|
||||
int accumulated; /* number of bytes accumulated after
|
||||
the last printed dot */
|
||||
|
||||
double dltime; /* download time so far */
|
||||
int rows; /* number of rows printed so far */
|
||||
int dots; /* number of dots printed in this row */
|
||||
|
||||
@@ -213,7 +218,7 @@ struct dot_progress {
|
||||
/* Dot-progress backend for progress_create. */
|
||||
|
||||
static void *
|
||||
dot_create (wgint initial, wgint total)
|
||||
dot_create (const char *f_download _GL_UNUSED, wgint initial, wgint total)
|
||||
{
|
||||
struct dot_progress *dp = xnew0 (struct dot_progress);
|
||||
dp->initial_length = initial;
|
||||
@@ -237,18 +242,18 @@ dot_create (wgint initial, wgint total)
|
||||
/* Align the [ skipping ... ] line with the dots. To do
|
||||
that, insert the number of spaces equal to the number of
|
||||
digits in the skipped amount in K. */
|
||||
logprintf (LOG_VERBOSE, _("\n%*s[ skipping %sK ]"),
|
||||
logprintf (LOG_PROGRESS, _("\n%*s[ skipping %sK ]"),
|
||||
2 + skipped_k_len, "",
|
||||
number_to_static_string (skipped_k));
|
||||
}
|
||||
|
||||
logprintf (LOG_VERBOSE, "\n%6sK",
|
||||
logprintf (LOG_PROGRESS, "\n%6sK",
|
||||
number_to_static_string (skipped / 1024));
|
||||
for (; remainder >= dot_bytes; remainder -= dot_bytes)
|
||||
{
|
||||
if (dp->dots % opt.dot_spacing == 0)
|
||||
logputs (LOG_VERBOSE, " ");
|
||||
logputs (LOG_VERBOSE, ",");
|
||||
logputs (LOG_PROGRESS, " ");
|
||||
logputs (LOG_PROGRESS, ",");
|
||||
++dp->dots;
|
||||
}
|
||||
assert (dp->dots < opt.dots_in_line);
|
||||
@@ -289,7 +294,7 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last)
|
||||
been retrieved. 12.8% will round to 12% because the 13% mark
|
||||
has not yet been reached. 100% is only shown when done. */
|
||||
int percentage = 100.0 * bytes_displayed / dp->total_length;
|
||||
logprintf (LOG_VERBOSE, "%3d%%", percentage);
|
||||
logprintf (LOG_PROGRESS, "%3d%%", percentage);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -306,7 +311,7 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last)
|
||||
if (dp->rows == dp->initial_length / ROW_BYTES)
|
||||
bytes_this_row -= dp->initial_length % ROW_BYTES;
|
||||
rate = calc_rate (bytes_this_row, dltime - dp->last_timer_value, &units);
|
||||
logprintf (LOG_VERBOSE, " %4.*f%c",
|
||||
logprintf (LOG_PROGRESS, " %4.*f%c",
|
||||
rate >= 99.95 ? 0 : rate >= 9.995 ? 1 : 2,
|
||||
rate, names[units]);
|
||||
dp->last_timer_value = dltime;
|
||||
@@ -323,7 +328,7 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last)
|
||||
wgint bytes_sofar = bytes_displayed - dp->initial_length;
|
||||
double eta = dltime * bytes_remaining / bytes_sofar;
|
||||
if (eta < INT_MAX - 1)
|
||||
logprintf (LOG_VERBOSE, " %s",
|
||||
logprintf (LOG_PROGRESS, " %s",
|
||||
eta_to_human_short ((int) (eta + 0.5), true));
|
||||
}
|
||||
}
|
||||
@@ -331,10 +336,10 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last)
|
||||
{
|
||||
/* When done, print the total download time */
|
||||
if (dltime >= 10)
|
||||
logprintf (LOG_VERBOSE, "=%s",
|
||||
logprintf (LOG_PROGRESS, "=%s",
|
||||
eta_to_human_short ((int) (dltime + 0.5), true));
|
||||
else
|
||||
logprintf (LOG_VERBOSE, "=%ss", print_decimal (dltime));
|
||||
logprintf (LOG_PROGRESS, "=%ss", print_decimal (dltime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,6 +347,14 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last)
|
||||
|
||||
static void
|
||||
dot_update (void *progress, wgint howmuch, double dltime)
|
||||
{
|
||||
struct dot_progress *dp = progress;
|
||||
dp->accumulated += howmuch;
|
||||
dp->dltime = dltime;
|
||||
}
|
||||
|
||||
static void
|
||||
dot_draw (void *progress)
|
||||
{
|
||||
struct dot_progress *dp = progress;
|
||||
int dot_bytes = opt.dot_bytes;
|
||||
@@ -349,16 +362,15 @@ dot_update (void *progress, wgint howmuch, double dltime)
|
||||
|
||||
log_set_flush (false);
|
||||
|
||||
dp->accumulated += howmuch;
|
||||
for (; dp->accumulated >= dot_bytes; dp->accumulated -= dot_bytes)
|
||||
{
|
||||
if (dp->dots == 0)
|
||||
logprintf (LOG_VERBOSE, "\n%6sK",
|
||||
logprintf (LOG_PROGRESS, "\n%6sK",
|
||||
number_to_static_string (dp->rows * ROW_BYTES / 1024));
|
||||
|
||||
if (dp->dots % opt.dot_spacing == 0)
|
||||
logputs (LOG_VERBOSE, " ");
|
||||
logputs (LOG_VERBOSE, ".");
|
||||
logputs (LOG_PROGRESS, " ");
|
||||
logputs (LOG_PROGRESS, ".");
|
||||
|
||||
++dp->dots;
|
||||
if (dp->dots >= opt.dots_in_line)
|
||||
@@ -366,7 +378,7 @@ dot_update (void *progress, wgint howmuch, double dltime)
|
||||
++dp->rows;
|
||||
dp->dots = 0;
|
||||
|
||||
print_row_stats (dp, dltime, false);
|
||||
print_row_stats (dp, dp->dltime, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,13 +397,13 @@ dot_finish (void *progress, double dltime)
|
||||
log_set_flush (false);
|
||||
|
||||
if (dp->dots == 0)
|
||||
logprintf (LOG_VERBOSE, "\n%6sK",
|
||||
logprintf (LOG_PROGRESS, "\n%6sK",
|
||||
number_to_static_string (dp->rows * ROW_BYTES / 1024));
|
||||
for (i = dp->dots; i < opt.dots_in_line; i++)
|
||||
{
|
||||
if (i % opt.dot_spacing == 0)
|
||||
logputs (LOG_VERBOSE, " ");
|
||||
logputs (LOG_VERBOSE, " ");
|
||||
logputs (LOG_PROGRESS, " ");
|
||||
logputs (LOG_PROGRESS, " ");
|
||||
}
|
||||
|
||||
print_row_stats (dp, dltime, true);
|
||||
@@ -407,7 +419,7 @@ dot_finish (void *progress, double dltime)
|
||||
giga. */
|
||||
|
||||
static void
|
||||
dot_set_params (const char *params)
|
||||
dot_set_params (char *params)
|
||||
{
|
||||
if (!params || !*params)
|
||||
params = opt.dot_style;
|
||||
@@ -416,7 +428,7 @@ dot_set_params (const char *params)
|
||||
return;
|
||||
|
||||
/* We use this to set the retrieval style. */
|
||||
if (!strcasecmp (params, "default"))
|
||||
if (!c_strcasecmp (params, "default"))
|
||||
{
|
||||
/* Default style: 1K dots, 10 dots in a cluster, 50 dots in a
|
||||
line. */
|
||||
@@ -424,7 +436,7 @@ dot_set_params (const char *params)
|
||||
opt.dot_spacing = 10;
|
||||
opt.dots_in_line = 50;
|
||||
}
|
||||
else if (!strcasecmp (params, "binary"))
|
||||
else if (!c_strcasecmp (params, "binary"))
|
||||
{
|
||||
/* "Binary" retrieval: 8K dots, 16 dots in a cluster, 48 dots
|
||||
(384K) in a line. */
|
||||
@@ -432,7 +444,7 @@ dot_set_params (const char *params)
|
||||
opt.dot_spacing = 16;
|
||||
opt.dots_in_line = 48;
|
||||
}
|
||||
else if (!strcasecmp (params, "mega"))
|
||||
else if (!c_strcasecmp (params, "mega"))
|
||||
{
|
||||
/* "Mega" retrieval, for retrieving very long files; each dot is
|
||||
64K, 8 dots in a cluster, 6 clusters (3M) in a line. */
|
||||
@@ -440,7 +452,7 @@ dot_set_params (const char *params)
|
||||
opt.dot_spacing = 8;
|
||||
opt.dots_in_line = 48;
|
||||
}
|
||||
else if (!strcasecmp (params, "giga"))
|
||||
else if (!c_strcasecmp (params, "giga"))
|
||||
{
|
||||
/* "Giga" retrieval, for retrieving very very *very* long files;
|
||||
each dot is 1M, 8 dots in a cluster, 4 clusters (32M) in a
|
||||
@@ -454,7 +466,7 @@ dot_set_params (const char *params)
|
||||
_("Invalid dot style specification %s; leaving unchanged.\n"),
|
||||
quote (params));
|
||||
}
|
||||
|
||||
|
||||
/* "Thermometer" (bar) progress. */
|
||||
|
||||
/* Assumed screen width if we can't find the real value. */
|
||||
@@ -495,6 +507,7 @@ static volatile sig_atomic_t received_sigwinch;
|
||||
#define ETA_REFRESH_INTERVAL 0.99
|
||||
|
||||
struct bar_progress {
|
||||
const char *f_download; /* Filename of the downloaded file */
|
||||
wgint initial_length; /* how many bytes have been downloaded
|
||||
previously. */
|
||||
wgint total_length; /* expected total byte count when the
|
||||
@@ -505,6 +518,7 @@ struct bar_progress {
|
||||
measured since the beginning of
|
||||
download. */
|
||||
|
||||
double dltime; /* download time so far */
|
||||
int width; /* screen width we're using at the
|
||||
time the progress gauge was
|
||||
created. this is different from
|
||||
@@ -551,7 +565,7 @@ static void create_image (struct bar_progress *, double, bool);
|
||||
static void display_image (char *);
|
||||
|
||||
static void *
|
||||
bar_create (wgint initial, wgint total)
|
||||
bar_create (const char *f_download, wgint initial, wgint total)
|
||||
{
|
||||
struct bar_progress *bp = xnew0 (struct bar_progress);
|
||||
|
||||
@@ -562,6 +576,7 @@ bar_create (wgint initial, wgint total)
|
||||
|
||||
bp->initial_length = initial;
|
||||
bp->total_length = total;
|
||||
bp->f_download = f_download;
|
||||
|
||||
/* Initialize screen_width if this hasn't been done or if it might
|
||||
have changed, as indicated by receiving SIGWINCH. */
|
||||
@@ -579,7 +594,8 @@ bar_create (wgint initial, wgint total)
|
||||
bp->width = screen_width - 1;
|
||||
/* + enough space for the terminating zero, and hopefully enough room
|
||||
* for multibyte characters. */
|
||||
bp->buffer = xmalloc (bp->width + 100);
|
||||
#define BUF_LEN (bp->width + 100)
|
||||
bp->buffer = xmalloc (BUF_LEN);
|
||||
|
||||
logputs (LOG_VERBOSE, "\n");
|
||||
|
||||
@@ -595,8 +611,8 @@ static void
|
||||
bar_update (void *progress, wgint howmuch, double dltime)
|
||||
{
|
||||
struct bar_progress *bp = progress;
|
||||
bool force_screen_update = false;
|
||||
|
||||
bp->dltime = dltime;
|
||||
bp->count += howmuch;
|
||||
if (bp->total_length > 0
|
||||
&& bp->count + bp->initial_length > bp->total_length)
|
||||
@@ -608,6 +624,13 @@ bar_update (void *progress, wgint howmuch, double dltime)
|
||||
bp->total_length = bp->initial_length + bp->count;
|
||||
|
||||
update_speed_ring (bp, howmuch, dltime);
|
||||
}
|
||||
|
||||
static void
|
||||
bar_draw (void *progress)
|
||||
{
|
||||
bool force_screen_update = false;
|
||||
struct bar_progress *bp = progress;
|
||||
|
||||
/* If SIGWINCH (the window size change signal) been received,
|
||||
determine the new screen size and update the screen. */
|
||||
@@ -628,13 +651,13 @@ bar_update (void *progress, wgint howmuch, double dltime)
|
||||
received_sigwinch = 0;
|
||||
}
|
||||
|
||||
if (dltime - bp->last_screen_update < REFRESH_INTERVAL && !force_screen_update)
|
||||
if (bp->dltime - bp->last_screen_update < REFRESH_INTERVAL && !force_screen_update)
|
||||
/* Don't update more often than five times per second. */
|
||||
return;
|
||||
|
||||
create_image (bp, dltime, false);
|
||||
create_image (bp, bp->dltime, false);
|
||||
display_image (bp->buffer);
|
||||
bp->last_screen_update = dltime;
|
||||
bp->last_screen_update = bp->dltime;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -650,7 +673,8 @@ bar_finish (void *progress, double dltime)
|
||||
create_image (bp, dltime, true);
|
||||
display_image (bp->buffer);
|
||||
|
||||
logputs (LOG_VERBOSE, "\n\n");
|
||||
logputs (LOG_VERBOSE, "\n");
|
||||
logputs (LOG_PROGRESS, "\n");
|
||||
|
||||
xfree (bp->buffer);
|
||||
xfree (bp);
|
||||
@@ -670,7 +694,7 @@ bar_finish (void *progress, double dltime)
|
||||
The idea is that for fast downloads, we get the speed over exactly
|
||||
the last three seconds. For slow downloads (where a network read
|
||||
takes more than 150ms to complete), we get the speed over a larger
|
||||
time period, as large as it takes to complete thirty reads. This
|
||||
time period, as large as it takes to complete twenty reads. This
|
||||
is good because slow downloads tend to fluctuate more and a
|
||||
3-second average would be too erratic. */
|
||||
|
||||
@@ -791,8 +815,39 @@ count_cols (const char *mbs)
|
||||
}
|
||||
return cols;
|
||||
}
|
||||
|
||||
static int
|
||||
cols_to_bytes (const char *mbs, const int cols, int *ncols)
|
||||
{
|
||||
int p_cols = 0, bytes = 0;
|
||||
mbchar_t mbc;
|
||||
mbi_iterator_t iter;
|
||||
mbi_init (iter, mbs, strlen(mbs));
|
||||
while (p_cols < cols && mbi_avail (iter))
|
||||
{
|
||||
mbc = mbi_cur (iter);
|
||||
p_cols += mb_width (mbc);
|
||||
/* The multibyte character has exceeded the total number of columns we
|
||||
* have available. The remaining bytes will be padded with a space. */
|
||||
if (p_cols > cols)
|
||||
{
|
||||
p_cols -= mb_width (mbc);
|
||||
break;
|
||||
}
|
||||
bytes += mb_len (mbc);
|
||||
mbi_advance (iter);
|
||||
}
|
||||
*ncols = p_cols;
|
||||
return bytes;
|
||||
}
|
||||
#else
|
||||
# define count_cols(mbs) ((int)(strlen(mbs)))
|
||||
static int count_cols (const char *mbs) { return (int) strlen(mbs); }
|
||||
static int
|
||||
cols_to_bytes (const char *mbs _GL_UNUSED, const int cols, int *ncols)
|
||||
{
|
||||
*ncols = cols;
|
||||
return cols;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const char *
|
||||
@@ -800,7 +855,7 @@ get_eta (int *bcd)
|
||||
{
|
||||
/* TRANSLATORS: "ETA" is English-centric, but this must
|
||||
be short, ideally 3 chars. Abbreviate if necessary. */
|
||||
static const char eta_str[] = N_(" eta %s");
|
||||
static const char eta_str[] = N_(" eta %s");
|
||||
static const char *eta_trans;
|
||||
static int bytes_cols_diff;
|
||||
if (eta_trans == NULL)
|
||||
@@ -842,26 +897,20 @@ get_eta (int *bcd)
|
||||
are confused when they see strchr (s, '\0') in the code. */
|
||||
#define move_to_end(s) s = strchr (s, '\0');
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a, b) ((a) >= (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
static void
|
||||
create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||||
{
|
||||
const int MAX_FILENAME_COLS = bp->width / 4;
|
||||
char *p = bp->buffer;
|
||||
wgint size = bp->initial_length + bp->count;
|
||||
|
||||
const char *size_grouped = with_thousand_seps (size);
|
||||
int size_grouped_len = count_cols (size_grouped);
|
||||
/* Difference between num cols and num bytes: */
|
||||
int size_grouped_diff = strlen (size_grouped) - size_grouped_len;
|
||||
int size_grouped_pad; /* Used to pad the field width for size_grouped. */
|
||||
|
||||
struct bar_progress_hist *hist = &bp->hist;
|
||||
int orig_filename_cols = count_cols (bp->f_download);
|
||||
|
||||
int padding;
|
||||
|
||||
/* The progress bar should look like this:
|
||||
xx% [=======> ] nn,nnn 12.34KB/s eta 36m 51s
|
||||
file xx% [=======> ] nnn.nnK 12.34KB/s eta 36m 51s
|
||||
|
||||
Calculate the geometry. The idea is to assign as much room as
|
||||
possible to the progress bar. The other idea is to never let
|
||||
@@ -870,38 +919,100 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||||
It would be especially bad for the progress bar to be resized
|
||||
randomly.
|
||||
|
||||
"file " - Downloaded filename - MAX_FILENAME_COLS chars + 1
|
||||
"xx% " or "100%" - percentage - 4 chars
|
||||
"[]" - progress bar decorations - 2 chars
|
||||
" nnn,nnn,nnn" - downloaded bytes - 12 chars or very rarely more
|
||||
" 12.5KB/s" - download rate - 9 chars
|
||||
" nnn.nnK" - downloaded bytes - 7 chars + 1
|
||||
" 12.5KB/s" - download rate - 8 chars + 1
|
||||
" eta 36m 51s" - ETA - 14 chars
|
||||
|
||||
"=====>..." - progress bar - the rest
|
||||
*/
|
||||
int dlbytes_size = 1 + MAX (size_grouped_len, 11);
|
||||
int progress_size = bp->width - (4 + 2 + dlbytes_size + 8 + 14);
|
||||
|
||||
/* TODO: Ask the Turkish Translators to fix their translation for the "done"
|
||||
* mode of progress bar. Use one less character. Once that is done, redice
|
||||
* PROGRESS_ETA_LEN by 1.
|
||||
*/
|
||||
#define PROGRESS_FILENAME_LEN MAX_FILENAME_COLS + 1
|
||||
#define PROGRESS_PERCENT_LEN 4
|
||||
#define PROGRESS_DECORAT_LEN 2
|
||||
#define PROGRESS_FILESIZE_LEN 7 + 1
|
||||
#define PROGRESS_DWNLOAD_RATE 8 + 2
|
||||
#define PROGRESS_ETA_LEN 15
|
||||
|
||||
int progress_size = bp->width - (PROGRESS_FILENAME_LEN + PROGRESS_PERCENT_LEN +
|
||||
PROGRESS_DECORAT_LEN + PROGRESS_FILESIZE_LEN +
|
||||
PROGRESS_DWNLOAD_RATE + PROGRESS_ETA_LEN);
|
||||
|
||||
/* The difference between the number of bytes used,
|
||||
and the number of columns used. */
|
||||
int bytes_cols_diff = 0;
|
||||
int cols_diff;
|
||||
const char *down_size;
|
||||
|
||||
memset (bp->buffer, '\0', BUF_LEN);
|
||||
|
||||
if (progress_size < 5)
|
||||
progress_size = 0;
|
||||
|
||||
if (orig_filename_cols <= MAX_FILENAME_COLS)
|
||||
{
|
||||
padding = MAX_FILENAME_COLS - orig_filename_cols;
|
||||
p += sprintf (p, "%s ", bp->f_download);
|
||||
memset (p, ' ', padding);
|
||||
p += padding;
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset_cols;
|
||||
int bytes_in_filename, offset_bytes, col;
|
||||
int *cols_ret = &col;
|
||||
|
||||
#define MIN_SCROLL_TEXT 5
|
||||
if ((orig_filename_cols > MAX_FILENAME_COLS + MIN_SCROLL_TEXT) &&
|
||||
!opt.noscroll &&
|
||||
!done)
|
||||
{
|
||||
offset_cols = ((int) bp->tick + orig_filename_cols + MAX_FILENAME_COLS / 2)
|
||||
% (orig_filename_cols + MAX_FILENAME_COLS);
|
||||
if (offset_cols > orig_filename_cols)
|
||||
{
|
||||
padding = MAX_FILENAME_COLS - (offset_cols - orig_filename_cols);
|
||||
memset(p, ' ', padding);
|
||||
p += padding;
|
||||
offset_cols = 0;
|
||||
}
|
||||
else
|
||||
padding = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
padding = 0;
|
||||
offset_cols = 0;
|
||||
}
|
||||
offset_bytes = cols_to_bytes (bp->f_download, offset_cols, cols_ret);
|
||||
bytes_in_filename = cols_to_bytes (bp->f_download + offset_bytes,
|
||||
MAX_FILENAME_COLS - padding,
|
||||
cols_ret);
|
||||
memcpy (p, bp->f_download + offset_bytes, bytes_in_filename);
|
||||
p += bytes_in_filename;
|
||||
padding = MAX_FILENAME_COLS - (padding + *cols_ret);
|
||||
memset (p, ' ', padding + 1);
|
||||
p += padding + 1;
|
||||
}
|
||||
|
||||
/* "xx% " */
|
||||
if (bp->total_length > 0)
|
||||
{
|
||||
int percentage = 100.0 * size / bp->total_length;
|
||||
assert (percentage <= 100);
|
||||
|
||||
if (percentage < 100)
|
||||
sprintf (p, "%2d%% ", percentage);
|
||||
else
|
||||
strcpy (p, "100%");
|
||||
p += 4;
|
||||
p += sprintf (p, "%3d%%", percentage);
|
||||
}
|
||||
else
|
||||
APPEND_LITERAL (" ");
|
||||
{
|
||||
memset (p, ' ', PROGRESS_PERCENT_LEN);
|
||||
p += PROGRESS_PERCENT_LEN;
|
||||
}
|
||||
|
||||
/* The progress bar: "[====> ]" or "[++==> ]". */
|
||||
if (progress_size && bp->total_length > 0)
|
||||
@@ -913,7 +1024,6 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||||
int dlsz = (double)size / bp->total_length * progress_size;
|
||||
|
||||
char *begin;
|
||||
int i;
|
||||
|
||||
assert (dlsz <= progress_size);
|
||||
assert (insz <= dlsz);
|
||||
@@ -923,18 +1033,19 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||||
|
||||
/* Print the initial portion of the download with '+' chars, the
|
||||
rest with '=' and one '>'. */
|
||||
for (i = 0; i < insz; i++)
|
||||
*p++ = '+';
|
||||
memset (p, '+', insz);
|
||||
p += insz;
|
||||
|
||||
dlsz -= insz;
|
||||
if (dlsz > 0)
|
||||
{
|
||||
for (i = 0; i < dlsz - 1; i++)
|
||||
*p++ = '=';
|
||||
memset (p, '=', dlsz-1);
|
||||
p += dlsz - 1;
|
||||
*p++ = '>';
|
||||
}
|
||||
|
||||
while (p - begin < progress_size)
|
||||
*p++ = ' ';
|
||||
memset (p, ' ', (progress_size - (p - begin)));
|
||||
p += (progress_size - (p - begin));
|
||||
*p++ = ']';
|
||||
}
|
||||
else if (progress_size)
|
||||
@@ -961,39 +1072,32 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||||
}
|
||||
*p++ = ']';
|
||||
|
||||
++bp->tick;
|
||||
}
|
||||
++bp->tick;
|
||||
|
||||
/* " 234,567,890" */
|
||||
sprintf (p, " %s", size_grouped);
|
||||
move_to_end (p);
|
||||
/* Pad with spaces to 11 chars for the size_grouped field;
|
||||
* couldn't use the field width specifier in sprintf, because
|
||||
* it counts in bytes, not characters. */
|
||||
for (size_grouped_pad = 11 - size_grouped_len;
|
||||
size_grouped_pad > 0;
|
||||
--size_grouped_pad)
|
||||
{
|
||||
*p++ = ' ';
|
||||
}
|
||||
/* " 234.56M" */
|
||||
down_size = human_readable (size, 1000, 2);
|
||||
cols_diff = PROGRESS_FILESIZE_LEN - count_cols (down_size);
|
||||
memset (p, ' ', cols_diff);
|
||||
p += cols_diff;
|
||||
p += sprintf (p, "%s", down_size);
|
||||
|
||||
/* " 12.52Kb/s or 12.52KB/s" */
|
||||
if (hist->total_time > 0 && hist->total_bytes)
|
||||
{
|
||||
static const char *short_units[] = { "B/s", "KB/s", "MB/s", "GB/s" };
|
||||
static const char *short_units_bits[] = { "b/s", "Kb/s", "Mb/s", "Gb/s" };
|
||||
static const char *short_units[] = { " B/s", "KB/s", "MB/s", "GB/s" };
|
||||
static const char *short_units_bits[] = { " b/s", "Kb/s", "Mb/s", "Gb/s" };
|
||||
int units = 0;
|
||||
/* Calculate the download speed using the history ring and
|
||||
recent data that hasn't made it to the ring yet. */
|
||||
wgint dlquant = hist->total_bytes + bp->recent_bytes;
|
||||
double dltime = hist->total_time + (dl_total_time - bp->recent_start);
|
||||
double dlspeed = calc_rate (dlquant, dltime, &units);
|
||||
sprintf (p, " %4.*f%s", dlspeed >= 99.95 ? 0 : dlspeed >= 9.995 ? 1 : 2,
|
||||
p += sprintf (p, " %4.*f%s", dlspeed >= 99.95 ? 0 : dlspeed >= 9.995 ? 1 : 2,
|
||||
dlspeed, !opt.report_bps ? short_units[units] : short_units_bits[units]);
|
||||
move_to_end (p);
|
||||
}
|
||||
else
|
||||
APPEND_LITERAL (" --.-K/s");
|
||||
APPEND_LITERAL (" --.-KB/s");
|
||||
|
||||
if (!done)
|
||||
{
|
||||
@@ -1028,14 +1132,14 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||||
bp->last_eta_time = dl_total_time;
|
||||
}
|
||||
|
||||
sprintf (p, get_eta(&bytes_cols_diff),
|
||||
p += sprintf (p, get_eta(&bytes_cols_diff),
|
||||
eta_to_human_short (eta, false));
|
||||
move_to_end (p);
|
||||
}
|
||||
else if (bp->total_length > 0)
|
||||
{
|
||||
skip_eta:
|
||||
APPEND_LITERAL (" ");
|
||||
memset (p, ' ', PROGRESS_ETA_LEN);
|
||||
p += PROGRESS_ETA_LEN;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1045,22 +1149,38 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
||||
int ncols;
|
||||
|
||||
/* Note to translators: this should not take up more room than
|
||||
available here. Abbreviate if necessary. */
|
||||
strcpy (p, _(" in "));
|
||||
available here (6 columns). Abbreviate if necessary. */
|
||||
strcpy (p, _(" in "));
|
||||
nbytes = strlen (p);
|
||||
ncols = count_cols (p);
|
||||
bytes_cols_diff = nbytes - ncols;
|
||||
p += nbytes;
|
||||
if (dl_total_time >= 10)
|
||||
strcpy (p, eta_to_human_short ((int) (dl_total_time + 0.5), false));
|
||||
ncols += sprintf (p + nbytes, "%s", eta_to_human_short ((int) (dl_total_time + 0.5), false));
|
||||
else
|
||||
sprintf (p, "%ss", print_decimal (dl_total_time));
|
||||
move_to_end (p);
|
||||
ncols += sprintf (p + nbytes, "%ss", print_decimal (dl_total_time));
|
||||
p += ncols + bytes_cols_diff;
|
||||
memset (p, ' ', PROGRESS_ETA_LEN - ncols);
|
||||
p += PROGRESS_ETA_LEN - ncols;
|
||||
}
|
||||
|
||||
while (p - bp->buffer - bytes_cols_diff - size_grouped_diff < bp->width)
|
||||
*p++ = ' ';
|
||||
padding = bp->width - count_cols (bp->buffer);
|
||||
assert (padding >= 0 && "Padding length became non-positive!");
|
||||
padding = padding > 0 ? padding : 0;
|
||||
memset (p, ' ', padding);
|
||||
p += padding;
|
||||
*p = '\0';
|
||||
|
||||
/* 2014-11-14 Darshit Shah <darnir@gmail.com>
|
||||
* Assert that the length of the progress bar is lesser than the size of the
|
||||
* screen with which we are dealing. This assertion *MUST* always be removed
|
||||
* from the release code since we do not want Wget to crash and burn when the
|
||||
* assertion fails. Instead Wget should continue downloading and display a
|
||||
* horrible and irritating progress bar that spams the screen with newlines.
|
||||
*
|
||||
* By default, all assertions are disabled in a Wget build and are enabled
|
||||
* only with the --enable-assert configure option.
|
||||
*/
|
||||
assert (count_cols (bp->buffer) == bp->width);
|
||||
}
|
||||
|
||||
/* Print the contents of the buffer as a one-line ASCII "image" so
|
||||
@@ -1070,33 +1190,33 @@ static void
|
||||
display_image (char *buf)
|
||||
{
|
||||
bool old = log_set_save_context (false);
|
||||
logputs (LOG_VERBOSE, "\r");
|
||||
logputs (LOG_VERBOSE, buf);
|
||||
logputs (LOG_PROGRESS, "\r");
|
||||
logputs (LOG_PROGRESS, buf);
|
||||
log_set_save_context (old);
|
||||
}
|
||||
|
||||
static void
|
||||
bar_set_params (const char *params)
|
||||
bar_set_params (char *params)
|
||||
{
|
||||
char *term = getenv ("TERM");
|
||||
if (params)
|
||||
{
|
||||
char *param = strtok (params, ":");
|
||||
do
|
||||
{
|
||||
if (0 == strcmp (param, "force"))
|
||||
current_impl_locked = 1;
|
||||
else if (0 == strcmp (param, "noscroll"))
|
||||
opt.noscroll = true;
|
||||
} while ((param = strtok (NULL, ":")) != NULL);
|
||||
}
|
||||
|
||||
if (params
|
||||
&& 0 == strcmp (params, "force"))
|
||||
current_impl_locked = 1;
|
||||
|
||||
if ((opt.lfilename
|
||||
if (((opt.lfilename && opt.show_progress != 1)
|
||||
#ifdef HAVE_ISATTY
|
||||
/* The progress bar doesn't make sense if the output is not a
|
||||
TTY -- when logging to file, it is better to review the
|
||||
dots. */
|
||||
|| !isatty (fileno (stderr))
|
||||
#endif
|
||||
/* Normally we don't depend on terminal type because the
|
||||
progress bar only uses ^M to move the cursor to the
|
||||
beginning of line, which works even on dumb terminals. But
|
||||
Jamie Zawinski reports that ^M and ^H tricks don't work in
|
||||
Emacs shell buffers, and only make a mess. */
|
||||
|| (term && 0 == strcmp (term, "emacs"))
|
||||
)
|
||||
&& !current_impl_locked)
|
||||
{
|
||||
@@ -1112,7 +1232,7 @@ bar_set_params (const char *params)
|
||||
|
||||
#ifdef SIGWINCH
|
||||
void
|
||||
progress_handle_sigwinch (int sig)
|
||||
progress_handle_sigwinch (int sig _GL_UNUSED)
|
||||
{
|
||||
received_sigwinch = 1;
|
||||
signal (SIGWINCH, progress_handle_sigwinch);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Download progress.
|
||||
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
2010, 2011 Free Software Foundation, Inc.
|
||||
2010, 2011, 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -35,7 +35,7 @@ bool valid_progress_implementation_p (const char *);
|
||||
void set_progress_implementation (const char *);
|
||||
void progress_schedule_redirect (void);
|
||||
|
||||
void *progress_create (wgint, wgint);
|
||||
void *progress_create (const char *, wgint, wgint);
|
||||
bool progress_interactive_p (void *);
|
||||
void progress_update (void *, wgint, double);
|
||||
void progress_finish (void *, double);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Portable timers.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free
|
||||
Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -291,7 +291,7 @@ windows_resolution (void)
|
||||
return 10; /* according to MSDN */
|
||||
}
|
||||
#endif /* PTIMER_WINDOWS */
|
||||
|
||||
|
||||
/* The code below this point is independent of timer implementation. */
|
||||
|
||||
struct ptimer {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Declarations for ptimer.c.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free
|
||||
Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -31,7 +31,7 @@ as that of the covered work. */
|
||||
#ifndef PTIMER_H
|
||||
#define PTIMER_H
|
||||
|
||||
struct ptimer; /* forward declaration; all struct
|
||||
struct ptimer; /* forward declaration; all struct
|
||||
members are private */
|
||||
|
||||
struct ptimer *ptimer_new (void);
|
||||
|
||||
387
src/recur.c
387
src/recur.c
@@ -1,7 +1,7 @@
|
||||
/* Handling of recursive HTTP retrieving.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -50,7 +50,8 @@ as that of the covered work. */
|
||||
#include "html-url.h"
|
||||
#include "css-url.h"
|
||||
#include "spider.h"
|
||||
|
||||
#include "exits.h"
|
||||
|
||||
/* Functions for maintaining the URL queue. */
|
||||
|
||||
struct queue_element {
|
||||
@@ -159,12 +160,42 @@ url_dequeue (struct url_queue *queue, struct iri **i,
|
||||
xfree (qel);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool download_child_p (const struct urlpos *, struct url *, int,
|
||||
struct url *, struct hash_table *, struct iri *);
|
||||
static bool descend_redirect_p (const char *, struct url *, int,
|
||||
struct url *, struct hash_table *, struct iri *);
|
||||
|
||||
static void blacklist_add (struct hash_table *blacklist, const char *url)
|
||||
{
|
||||
char *url_unescaped = xstrdup (url);
|
||||
|
||||
url_unescape (url_unescaped);
|
||||
string_set_add (blacklist, url_unescaped);
|
||||
xfree (url_unescaped);
|
||||
}
|
||||
|
||||
static int blacklist_contains (struct hash_table *blacklist, const char *url)
|
||||
{
|
||||
char *url_unescaped = xstrdup(url);
|
||||
int ret;
|
||||
|
||||
url_unescape (url_unescaped);
|
||||
ret = string_set_contains (blacklist, url_unescaped);
|
||||
xfree (url_unescaped);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WG_RR_SUCCESS, WG_RR_BLACKLIST, WG_RR_NOTHTTPS, WG_RR_NONHTTP, WG_RR_ABSOLUTE,
|
||||
WG_RR_DOMAIN, WG_RR_PARENT, WG_RR_LIST, WG_RR_REGEX, WG_RR_RULES,
|
||||
WG_RR_SPANNEDHOST, WG_RR_ROBOTS
|
||||
} reject_reason;
|
||||
|
||||
static reject_reason download_child (const struct urlpos *, struct url *, int,
|
||||
struct url *, struct hash_table *, struct iri *);
|
||||
static reject_reason descend_redirect (const char *, struct url *, int,
|
||||
struct url *, struct hash_table *, struct iri *);
|
||||
static void write_reject_log_header (FILE *);
|
||||
static void write_reject_log_reason (FILE *, reject_reason,
|
||||
const struct url *, const struct url *);
|
||||
|
||||
/* Retrieve a part of the web beginning with START_URL. This used to
|
||||
be called "recursive retrieval", because the old function was
|
||||
@@ -201,17 +232,21 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
|
||||
struct iri *i = iri_new ();
|
||||
|
||||
#define COPYSTR(x) (x) ? xstrdup(x) : NULL;
|
||||
FILE *rejectedlog = NULL; /* Don't write a rejected log. */
|
||||
|
||||
/* Duplicate pi struct if not NULL */
|
||||
if (pi)
|
||||
{
|
||||
#define COPYSTR(x) (x) ? xstrdup(x) : NULL;
|
||||
i->uri_encoding = COPYSTR (pi->uri_encoding);
|
||||
i->content_encoding = COPYSTR (pi->content_encoding);
|
||||
i->utf8_encode = pi->utf8_encode;
|
||||
#undef COPYSTR
|
||||
}
|
||||
#ifdef ENABLE_IRI
|
||||
else
|
||||
set_uri_encoding (i, opt.locale, true);
|
||||
#undef COPYSTR
|
||||
#endif
|
||||
|
||||
queue = url_queue_new ();
|
||||
blacklist = make_string_hash_table (0);
|
||||
@@ -220,7 +255,15 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
just URL so we enqueue the canonical form of the URL. */
|
||||
url_enqueue (queue, i, xstrdup (start_url_parsed->url), NULL, 0, true,
|
||||
false);
|
||||
string_set_add (blacklist, start_url_parsed->url);
|
||||
blacklist_add (blacklist, start_url_parsed->url);
|
||||
|
||||
if (opt.rejected_log)
|
||||
{
|
||||
rejectedlog = fopen (opt.rejected_log, "w");
|
||||
write_reject_log_header (rejectedlog);
|
||||
if (!rejectedlog)
|
||||
logprintf (LOG_NOTQUIET, "%s: %s\n", opt.rejected_log, strerror (errno));
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
@@ -244,34 +287,31 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
break;
|
||||
|
||||
/* ...and download it. Note that this download is in most cases
|
||||
unconditional, as download_child_p already makes sure a file
|
||||
unconditional, as download_child already makes sure a file
|
||||
doesn't get enqueued twice -- and yet this check is here, and
|
||||
not in download_child_p. This is so that if you run `wget -r
|
||||
not in download_child. This is so that if you run `wget -r
|
||||
URL1 URL2', and a random URL is encountered once under URL1
|
||||
and again under URL2, but at a different (possibly smaller)
|
||||
depth, we want the URL's children to be taken into account
|
||||
the second time. */
|
||||
if (dl_url_file_map && hash_table_contains (dl_url_file_map, url))
|
||||
{
|
||||
bool is_css_bool;
|
||||
|
||||
file = xstrdup (hash_table_get (dl_url_file_map, url));
|
||||
|
||||
DEBUGP (("Already downloaded \"%s\", reusing it from \"%s\".\n",
|
||||
url, file));
|
||||
|
||||
/* this sucks, needs to be combined! */
|
||||
if (html_allowed
|
||||
&& downloaded_html_set
|
||||
&& string_set_contains (downloaded_html_set, file))
|
||||
if ((is_css_bool = (css_allowed
|
||||
&& downloaded_css_set
|
||||
&& string_set_contains (downloaded_css_set, file)))
|
||||
|| (html_allowed
|
||||
&& downloaded_html_set
|
||||
&& string_set_contains (downloaded_html_set, file)))
|
||||
{
|
||||
descend = true;
|
||||
is_css = false;
|
||||
}
|
||||
if (css_allowed
|
||||
&& downloaded_css_set
|
||||
&& string_set_contains (downloaded_css_set, file))
|
||||
{
|
||||
descend = true;
|
||||
is_css = true;
|
||||
is_css = is_css_bool;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -280,52 +320,69 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
char *redirected = NULL;
|
||||
struct url *url_parsed = url_parse (url, &url_err, i, true);
|
||||
|
||||
status = retrieve_url (url_parsed, url, &file, &redirected, referer,
|
||||
&dt, false, i, true);
|
||||
|
||||
if (html_allowed && file && status == RETROK
|
||||
&& (dt & RETROKF) && (dt & TEXTHTML))
|
||||
if (!url_parsed)
|
||||
{
|
||||
descend = true;
|
||||
is_css = false;
|
||||
}
|
||||
|
||||
/* a little different, css_allowed can override content type
|
||||
lots of web servers serve css with an incorrect content type
|
||||
*/
|
||||
if (file && status == RETROK
|
||||
&& (dt & RETROKF) &&
|
||||
((dt & TEXTCSS) || css_allowed))
|
||||
{
|
||||
descend = true;
|
||||
is_css = true;
|
||||
}
|
||||
|
||||
if (redirected)
|
||||
{
|
||||
/* We have been redirected, possibly to another host, or
|
||||
different path, or wherever. Check whether we really
|
||||
want to follow it. */
|
||||
if (descend)
|
||||
{
|
||||
if (!descend_redirect_p (redirected, url_parsed, depth,
|
||||
start_url_parsed, blacklist, i))
|
||||
descend = false;
|
||||
else
|
||||
/* Make sure that the old pre-redirect form gets
|
||||
blacklisted. */
|
||||
string_set_add (blacklist, url);
|
||||
}
|
||||
|
||||
xfree (url);
|
||||
url = redirected;
|
||||
char *error = url_error (url, url_err);
|
||||
logprintf (LOG_NOTQUIET, "%s: %s.\n",url, error);
|
||||
xfree (error);
|
||||
inform_exit_status (URLERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
xfree (url);
|
||||
url = xstrdup (url_parsed->url);
|
||||
|
||||
status = retrieve_url (url_parsed, url, &file, &redirected, referer,
|
||||
&dt, false, i, true);
|
||||
|
||||
if (html_allowed && file && status == RETROK
|
||||
&& (dt & RETROKF) && (dt & TEXTHTML))
|
||||
{
|
||||
descend = true;
|
||||
is_css = false;
|
||||
}
|
||||
|
||||
/* a little different, css_allowed can override content type
|
||||
lots of web servers serve css with an incorrect content type
|
||||
*/
|
||||
if (file && status == RETROK
|
||||
&& (dt & RETROKF) &&
|
||||
((dt & TEXTCSS) || css_allowed))
|
||||
{
|
||||
descend = true;
|
||||
is_css = true;
|
||||
}
|
||||
|
||||
if (redirected)
|
||||
{
|
||||
/* We have been redirected, possibly to another host, or
|
||||
different path, or wherever. Check whether we really
|
||||
want to follow it. */
|
||||
if (descend)
|
||||
{
|
||||
reject_reason r = descend_redirect (redirected, url_parsed,
|
||||
depth, start_url_parsed, blacklist, i);
|
||||
if (r == WG_RR_SUCCESS)
|
||||
{
|
||||
/* Make sure that the old pre-redirect form gets
|
||||
blacklisted. */
|
||||
blacklist_add (blacklist, url);
|
||||
}
|
||||
else
|
||||
{
|
||||
write_reject_log_reason (rejectedlog, r, url_parsed, start_url_parsed);
|
||||
descend = false;
|
||||
}
|
||||
}
|
||||
|
||||
xfree (url);
|
||||
url = redirected;
|
||||
}
|
||||
else
|
||||
{
|
||||
xfree (url);
|
||||
url = xstrdup (url_parsed->url);
|
||||
}
|
||||
url_free (url_parsed);
|
||||
}
|
||||
url_free(url_parsed);
|
||||
}
|
||||
|
||||
if (opt.spider)
|
||||
@@ -391,12 +448,16 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
|
||||
for (; child; child = child->next)
|
||||
{
|
||||
reject_reason r;
|
||||
|
||||
if (child->ignore_when_downloading)
|
||||
continue;
|
||||
if (dash_p_leaf_HTML && !child->link_inline_p)
|
||||
continue;
|
||||
if (download_child_p (child, url_parsed, depth, start_url_parsed,
|
||||
blacklist, i))
|
||||
|
||||
r = download_child (child, url_parsed, depth,
|
||||
start_url_parsed, blacklist, i);
|
||||
if (r == WG_RR_SUCCESS)
|
||||
{
|
||||
ci = iri_new ();
|
||||
set_uri_encoding (ci, i->content_encoding, false);
|
||||
@@ -407,7 +468,11 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
/* We blacklist the URL we have enqueued, because we
|
||||
don't want to enqueue (and hence download) the
|
||||
same URL twice. */
|
||||
string_set_add (blacklist, child->url->url);
|
||||
blacklist_add (blacklist, child->url->url);
|
||||
}
|
||||
else
|
||||
{
|
||||
write_reject_log_reason (rejectedlog, r, child->url, url_parsed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,11 +508,14 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
}
|
||||
|
||||
xfree (url);
|
||||
xfree_null (referer);
|
||||
xfree_null (file);
|
||||
xfree (referer);
|
||||
xfree (file);
|
||||
iri_free (i);
|
||||
}
|
||||
|
||||
if (rejectedlog)
|
||||
fclose (rejectedlog);
|
||||
|
||||
/* If anything is left of the queue due to a premature exit, free it
|
||||
now. */
|
||||
{
|
||||
@@ -460,7 +528,7 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
{
|
||||
iri_free (d6);
|
||||
xfree (d1);
|
||||
xfree_null (d2);
|
||||
xfree (d2);
|
||||
}
|
||||
}
|
||||
url_queue_delete (queue);
|
||||
@@ -483,40 +551,43 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
||||
by storing these URLs to BLACKLIST. This may or may not help. It
|
||||
will help if those URLs are encountered many times. */
|
||||
|
||||
static bool
|
||||
download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
static reject_reason
|
||||
download_child (const struct urlpos *upos, struct url *parent, int depth,
|
||||
struct url *start_url_parsed, struct hash_table *blacklist,
|
||||
struct iri *iri)
|
||||
{
|
||||
struct url *u = upos->url;
|
||||
const char *url = u->url;
|
||||
bool u_scheme_like_http;
|
||||
reject_reason reason = WG_RR_SUCCESS;
|
||||
|
||||
DEBUGP (("Deciding whether to enqueue \"%s\".\n", url));
|
||||
|
||||
if (string_set_contains (blacklist, url))
|
||||
if (blacklist_contains (blacklist, url))
|
||||
{
|
||||
if (opt.spider)
|
||||
{
|
||||
char *referrer = url_string (parent, URL_AUTH_HIDE_PASSWD);
|
||||
DEBUGP (("download_child_p: parent->url is: %s\n", quote (parent->url)));
|
||||
DEBUGP (("download_child: parent->url is: %s\n", quote (parent->url)));
|
||||
visited_url (url, referrer);
|
||||
xfree (referrer);
|
||||
}
|
||||
DEBUGP (("Already on the black list.\n"));
|
||||
reason = WG_RR_BLACKLIST;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Several things to check for:
|
||||
1. if scheme is not http, and we don't load it
|
||||
2. check for relative links (if relative_only is set)
|
||||
3. check for domain
|
||||
4. check for no-parent
|
||||
5. check for excludes && includes
|
||||
6. check for suffix
|
||||
7. check for same host (if spanhost is unset), with possible
|
||||
1. if scheme is not https and https_only requested
|
||||
2. if scheme is not http, and we don't load it
|
||||
3. check for relative links (if relative_only is set)
|
||||
4. check for domain
|
||||
5. check for no-parent
|
||||
6. check for excludes && includes
|
||||
7. check for suffix
|
||||
8. check for same host (if spanhost is unset), with possible
|
||||
gethostbyname baggage
|
||||
8. check for robots.txt
|
||||
9. check for robots.txt
|
||||
|
||||
Addendum: If the URL is FTP, and it is to be loaded, only the
|
||||
domain and suffix settings are "stronger".
|
||||
@@ -528,13 +599,27 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
More time- and memory- consuming tests should be put later on
|
||||
the list. */
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
if (opt.https_only && u->scheme != SCHEME_HTTPS)
|
||||
{
|
||||
DEBUGP (("Not following non-HTTPS links.\n"));
|
||||
reason = WG_RR_NOTHTTPS;
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Determine whether URL under consideration has a HTTP-like scheme. */
|
||||
u_scheme_like_http = schemes_are_similar_p (u->scheme, SCHEME_HTTP);
|
||||
|
||||
/* 1. Schemes other than HTTP are normally not recursed into. */
|
||||
if (!u_scheme_like_http && !(u->scheme == SCHEME_FTP && opt.follow_ftp))
|
||||
if (!u_scheme_like_http && !((u->scheme == SCHEME_FTP
|
||||
#ifdef HAVE_SSL
|
||||
|| u->scheme == SCHEME_FTPS
|
||||
#endif
|
||||
) && opt.follow_ftp))
|
||||
{
|
||||
DEBUGP (("Not following non-HTTP schemes.\n"));
|
||||
reason = WG_RR_NONHTTP;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -544,6 +629,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
if (opt.relative_only && !upos->link_relative_p)
|
||||
{
|
||||
DEBUGP (("It doesn't really look like a relative link.\n"));
|
||||
reason = WG_RR_ABSOLUTE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -552,6 +638,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
if (!accept_domain (u))
|
||||
{
|
||||
DEBUGP (("The domain was not accepted.\n"));
|
||||
reason = WG_RR_DOMAIN;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -571,6 +658,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
{
|
||||
DEBUGP (("Going to \"%s\" would escape \"%s\" with no_parent on.\n",
|
||||
u->dir, start_url_parsed->dir));
|
||||
reason = WG_RR_PARENT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -583,12 +671,14 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
if (!accdir (u->dir))
|
||||
{
|
||||
DEBUGP (("%s (%s) is excluded/not-included.\n", url, u->dir));
|
||||
reason = WG_RR_LIST;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
if (!accept_url (url))
|
||||
{
|
||||
DEBUGP (("%s is excluded/not-included through regex.\n", url));
|
||||
reason = WG_RR_REGEX;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -613,6 +703,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
{
|
||||
DEBUGP (("%s (%s) does not match acc/rej rules.\n",
|
||||
url, u->file));
|
||||
reason = WG_RR_RULES;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -623,6 +714,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
{
|
||||
DEBUGP (("This is not the same hostname as the parent's (%s and %s).\n",
|
||||
u->host, parent->host));
|
||||
reason = WG_RR_SPANNEDHOST;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -641,7 +733,7 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
files after downloading or we're just running a spider. */
|
||||
if (opt.delete_after || opt.spider)
|
||||
{
|
||||
logprintf (LOG_VERBOSE, "Removing %s.\n", rfile);
|
||||
logprintf (LOG_VERBOSE, _("Removing %s.\n"), rfile);
|
||||
if (unlink (rfile))
|
||||
logprintf (LOG_NOTQUIET, "unlink: %s\n",
|
||||
strerror (errno));
|
||||
@@ -664,36 +756,37 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
|
||||
if (!res_match_path (specs, u->path))
|
||||
{
|
||||
DEBUGP (("Not following %s because robots.txt forbids it.\n", url));
|
||||
string_set_add (blacklist, url);
|
||||
blacklist_add (blacklist, url);
|
||||
reason = WG_RR_ROBOTS;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* The URL has passed all the tests. It can be placed in the
|
||||
download queue. */
|
||||
DEBUGP (("Decided to load it.\n"));
|
||||
out:
|
||||
|
||||
return true;
|
||||
if (reason == WG_RR_SUCCESS)
|
||||
/* The URL has passed all the tests. It can be placed in the
|
||||
download queue. */
|
||||
DEBUGP (("Decided to load it.\n"));
|
||||
else
|
||||
DEBUGP (("Decided NOT to load it.\n"));
|
||||
|
||||
out:
|
||||
DEBUGP (("Decided NOT to load it.\n"));
|
||||
|
||||
return false;
|
||||
return reason;
|
||||
}
|
||||
|
||||
/* This function determines whether we will consider downloading the
|
||||
children of a URL whose download resulted in a redirection,
|
||||
possibly to another host, etc. It is needed very rarely, and thus
|
||||
it is merely a simple-minded wrapper around download_child_p. */
|
||||
it is merely a simple-minded wrapper around download_child. */
|
||||
|
||||
static bool
|
||||
descend_redirect_p (const char *redirected, struct url *orig_parsed, int depth,
|
||||
static reject_reason
|
||||
descend_redirect (const char *redirected, struct url *orig_parsed, int depth,
|
||||
struct url *start_url_parsed, struct hash_table *blacklist,
|
||||
struct iri *iri)
|
||||
{
|
||||
struct url *new_parsed;
|
||||
struct urlpos *upos;
|
||||
bool success;
|
||||
reject_reason reason;
|
||||
|
||||
assert (orig_parsed != NULL);
|
||||
|
||||
@@ -703,16 +796,104 @@ descend_redirect_p (const char *redirected, struct url *orig_parsed, int depth,
|
||||
upos = xnew0 (struct urlpos);
|
||||
upos->url = new_parsed;
|
||||
|
||||
success = download_child_p (upos, orig_parsed, depth,
|
||||
reason = download_child (upos, orig_parsed, depth,
|
||||
start_url_parsed, blacklist, iri);
|
||||
|
||||
if (reason == WG_RR_SUCCESS)
|
||||
blacklist_add (blacklist, upos->url->url);
|
||||
else
|
||||
DEBUGP (("Redirection \"%s\" failed the test.\n", redirected));
|
||||
|
||||
url_free (new_parsed);
|
||||
xfree (upos);
|
||||
|
||||
if (!success)
|
||||
DEBUGP (("Redirection \"%s\" failed the test.\n", redirected));
|
||||
return reason;
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
/* This function writes the rejected log header. */
|
||||
static void
|
||||
write_reject_log_header (FILE *f)
|
||||
{
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
/* Note: Update this header when columns change in any way. */
|
||||
fprintf (f, "REASON\t"
|
||||
"U_URL\tU_SCHEME\tU_HOST\tU_PORT\tU_PATH\tU_PARAMS\tU_QUERY\tU_FRAGMENT\t"
|
||||
"P_URL\tP_SCHEME\tP_HOST\tP_PORT\tP_PATH\tP_PARAMS\tP_QUERY\tP_FRAGMENT\n");
|
||||
}
|
||||
|
||||
/* This function writes a URL to the reject log. Internal use only. */
|
||||
static void
|
||||
write_reject_log_url (FILE *fp, const struct url *url)
|
||||
{
|
||||
const char *escaped_str;
|
||||
const char *scheme_str;
|
||||
|
||||
if (!fp)
|
||||
return;
|
||||
|
||||
escaped_str = url_escape (url->url);
|
||||
|
||||
switch (url->scheme)
|
||||
{
|
||||
case SCHEME_HTTP: scheme_str = "SCHEME_HTTP"; break;
|
||||
#ifdef HAVE_SSL
|
||||
case SCHEME_HTTPS: scheme_str = "SCHEME_HTTPS"; break;
|
||||
case SCHEME_FTPS: scheme_str = "SCHEME_FTPS"; break;
|
||||
#endif
|
||||
case SCHEME_FTP: scheme_str = "SCHEME_FTP"; break;
|
||||
default: scheme_str = "SCHEME_INVALID"; break;
|
||||
}
|
||||
|
||||
fprintf (fp, "%s\t%s\t%s\t%i\t%s\t%s\t%s\t%s",
|
||||
escaped_str,
|
||||
scheme_str,
|
||||
url->host,
|
||||
url->port,
|
||||
url->path,
|
||||
url->params ? url->params : "",
|
||||
url->query ? url->query : "",
|
||||
url->fragment ? url->fragment : "");
|
||||
|
||||
xfree (escaped_str);
|
||||
}
|
||||
|
||||
/* This function writes out information on why a URL was rejected and its
|
||||
context from download_child such as the URL being rejected and it's
|
||||
parent's URL. The format it uses is comma separated values but with tabs. */
|
||||
static void
|
||||
write_reject_log_reason (FILE *fp, reject_reason reason,
|
||||
const struct url *url, const struct url *parent)
|
||||
{
|
||||
const char *reason_str;
|
||||
|
||||
if (!fp)
|
||||
return;
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case WG_RR_SUCCESS: reason_str = "SUCCESS"; break;
|
||||
case WG_RR_BLACKLIST: reason_str = "BLACKLIST"; break;
|
||||
case WG_RR_NOTHTTPS: reason_str = "NOTHTTPS"; break;
|
||||
case WG_RR_NONHTTP: reason_str = "NONHTTP"; break;
|
||||
case WG_RR_ABSOLUTE: reason_str = "ABSOLUTE"; break;
|
||||
case WG_RR_DOMAIN: reason_str = "DOMAIN"; break;
|
||||
case WG_RR_PARENT: reason_str = "PARENT"; break;
|
||||
case WG_RR_LIST: reason_str = "LIST"; break;
|
||||
case WG_RR_REGEX: reason_str = "REGEX"; break;
|
||||
case WG_RR_RULES: reason_str = "RULES"; break;
|
||||
case WG_RR_SPANNEDHOST: reason_str = "SPANNEDHOST"; break;
|
||||
case WG_RR_ROBOTS: reason_str = "ROBOTS"; break;
|
||||
default: reason_str = "UNKNOWN"; break;
|
||||
}
|
||||
|
||||
fprintf (fp, "%s\t", reason_str);
|
||||
write_reject_log_url (fp, url);
|
||||
fprintf (fp, "\t");
|
||||
write_reject_log_url (fp, parent);
|
||||
fprintf (fp, "\n");
|
||||
}
|
||||
|
||||
/* vim:set sts=2 sw=2 cino+={s: */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Declarations for recur.c.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
|
||||
33
src/res.c
33
src/res.c
@@ -1,6 +1,6 @@
|
||||
/* Support for Robot Exclusion Standard (RES).
|
||||
Copyright (C) 2001, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Foundation, Inc.
|
||||
Copyright (C) 2001, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free
|
||||
Software Foundation, Inc.
|
||||
|
||||
This file is part of Wget.
|
||||
|
||||
@@ -81,6 +81,7 @@ as that of the covered work. */
|
||||
#include "url.h"
|
||||
#include "retr.h"
|
||||
#include "res.h"
|
||||
#include "c-strcase.h"
|
||||
|
||||
#ifdef TESTING
|
||||
#include "test.h"
|
||||
@@ -97,7 +98,7 @@ struct robot_specs {
|
||||
int size;
|
||||
struct path_info *paths;
|
||||
};
|
||||
|
||||
|
||||
/* Parsing the robot spec. */
|
||||
|
||||
/* Check whether AGENT (a string of length LENGTH) equals "wget" or
|
||||
@@ -403,10 +404,10 @@ free_specs (struct robot_specs *specs)
|
||||
int i;
|
||||
for (i = 0; i < specs->count; i++)
|
||||
xfree (specs->paths[i].path);
|
||||
xfree_null (specs->paths);
|
||||
xfree (specs->paths);
|
||||
xfree (specs);
|
||||
}
|
||||
|
||||
|
||||
/* Matching of a path according to the specs. */
|
||||
|
||||
/* If C is '%' and (ptr[1], ptr[2]) form a hexadecimal number, and if
|
||||
@@ -471,7 +472,7 @@ res_match_path (const struct robot_specs *specs, const char *path)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Registering the specs. */
|
||||
|
||||
static struct hash_table *registered_specs;
|
||||
@@ -521,7 +522,7 @@ res_get_specs (const char *host, int port)
|
||||
return NULL;
|
||||
return hash_table_get (registered_specs, hp);
|
||||
}
|
||||
|
||||
|
||||
/* Loading the robots file. */
|
||||
|
||||
#define RES_SPECS_LOCATION "/robots.txt"
|
||||
@@ -578,11 +579,10 @@ res_retrieve_file (const char *url, char **file, struct iri *iri)
|
||||
allocated the file name, deallocate is here so that the
|
||||
caller doesn't have to worry about it. */
|
||||
xfree (*file);
|
||||
*file = NULL;
|
||||
}
|
||||
return err == RETROK;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
is_robots_txt_url (const char *url)
|
||||
{
|
||||
@@ -593,7 +593,7 @@ is_robots_txt_url (const char *url)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
res_cleanup (void)
|
||||
{
|
||||
@@ -611,15 +611,15 @@ res_cleanup (void)
|
||||
registered_specs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
const char *
|
||||
test_is_robots_txt_url()
|
||||
test_is_robots_txt_url(void)
|
||||
{
|
||||
int i;
|
||||
struct {
|
||||
char *url;
|
||||
unsigned i;
|
||||
static const struct {
|
||||
const char *url;
|
||||
bool expected_result;
|
||||
} test_array[] = {
|
||||
{ "http://www.yoyodyne.com/robots.txt", true },
|
||||
@@ -627,7 +627,7 @@ test_is_robots_txt_url()
|
||||
{ "http://www.yoyodyne.com/somepath/robots.txt", false },
|
||||
};
|
||||
|
||||
for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i)
|
||||
for (i = 0; i < countof(test_array); ++i)
|
||||
{
|
||||
mu_assert ("test_is_robots_txt_url: wrong result",
|
||||
is_robots_txt_url (test_array[i].url) == test_array[i].expected_result);
|
||||
@@ -641,4 +641,3 @@ test_is_robots_txt_url()
|
||||
/*
|
||||
* vim: et ts=2 sw=2
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Declarations for res.c.
|
||||
Copyright (C) 2001, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Copyright (C) 2001, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of Wget.
|
||||
|
||||
250
src/retr.c
250
src/retr.c
@@ -1,7 +1,7 @@
|
||||
/* File retrieval.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -37,6 +37,9 @@ as that of the covered work. */
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#ifdef VMS
|
||||
# include <unixio.h> /* For delete(). */
|
||||
#endif
|
||||
|
||||
#include "exits.h"
|
||||
#include "utils.h"
|
||||
@@ -53,6 +56,7 @@ as that of the covered work. */
|
||||
#include "ptimer.h"
|
||||
#include "html-url.h"
|
||||
#include "iri.h"
|
||||
#include "hsts.h"
|
||||
|
||||
/* Total size of downloaded files. Used to enforce quota. */
|
||||
SUM_SIZE_INT total_downloaded_bytes;
|
||||
@@ -67,7 +71,7 @@ FILE *output_stream;
|
||||
/* Whether output_document is a regular file we can manipulate,
|
||||
i.e. not `-' or a device file. */
|
||||
bool output_stream_regular;
|
||||
|
||||
|
||||
static struct {
|
||||
wgint chunk_bytes;
|
||||
double chunk_start;
|
||||
@@ -133,16 +137,12 @@ limit_bandwidth (wgint bytes, struct ptimer *timer)
|
||||
limit_data.chunk_start = ptimer_read (timer);
|
||||
}
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(i, j) ((i) <= (j) ? (i) : (j))
|
||||
#endif
|
||||
|
||||
/* Write data in BUF to OUT. However, if *SKIP is non-zero, skip that
|
||||
amount of data and decrease SKIP. Increment *TOTAL by the amount
|
||||
of data written. If OUT2 is not NULL, also write BUF to OUT2.
|
||||
In case of error writing to OUT, -1 is returned. In case of error
|
||||
writing to OUT2, -2 is returned. In case of any other error,
|
||||
1 is returned. */
|
||||
writing to OUT2, -2 is returned. Return 1 if the whole BUF was
|
||||
skipped. */
|
||||
|
||||
static int
|
||||
write_data (FILE *out, FILE *out2, const char *buf, int bufsize,
|
||||
@@ -223,7 +223,8 @@ write_data (FILE *out, FILE *out2, const char *buf, int bufsize,
|
||||
data to OUT2, -3 is returned. */
|
||||
|
||||
int
|
||||
fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
|
||||
fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, wgint startpos,
|
||||
|
||||
wgint *qtyread, wgint *qtywritten, double *elapsed, int flags,
|
||||
FILE *out2)
|
||||
{
|
||||
@@ -259,13 +260,18 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
|
||||
if (flags & rb_skip_startpos)
|
||||
skip = startpos;
|
||||
|
||||
if (opt.verbose)
|
||||
if (opt.show_progress)
|
||||
{
|
||||
const char *filename_progress;
|
||||
/* If we're skipping STARTPOS bytes, pass 0 as the INITIAL
|
||||
argument to progress_create because the indicator doesn't
|
||||
(yet) know about "skipping" data. */
|
||||
wgint start = skip ? 0 : startpos;
|
||||
progress = progress_create (start, start + toread);
|
||||
if (opt.dir_prefix)
|
||||
filename_progress = downloaded_filename + strlen (opt.dir_prefix) + 1;
|
||||
else
|
||||
filename_progress = downloaded_filename;
|
||||
progress = progress_create (filename_progress, start, start + toread);
|
||||
progress_interactive = progress_interactive_p (progress);
|
||||
}
|
||||
|
||||
@@ -374,9 +380,11 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
|
||||
|
||||
if (ret > 0)
|
||||
{
|
||||
int write_res;
|
||||
|
||||
sum_read += ret;
|
||||
int write_res = write_data (out, out2, dlbuf, ret, &skip, &sum_written);
|
||||
if (write_res != 0)
|
||||
write_res = write_data (out, out2, dlbuf, ret, &skip, &sum_written);
|
||||
if (write_res < 0)
|
||||
{
|
||||
ret = (write_res == -3) ? -3 : -2;
|
||||
goto out;
|
||||
@@ -408,7 +416,7 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
|
||||
if (progress)
|
||||
progress_update (progress, ret, ptimer_read (timer));
|
||||
#ifdef WINDOWS
|
||||
if (toread > 0 && !opt.quiet)
|
||||
if (toread > 0 && opt.show_progress)
|
||||
ws_percenttitle (100.0 *
|
||||
(startpos + sum_read) / (startpos + toread));
|
||||
#endif
|
||||
@@ -430,11 +438,11 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
|
||||
if (qtywritten)
|
||||
*qtywritten += sum_written;
|
||||
|
||||
free (dlbuf);
|
||||
xfree (dlbuf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Read a hunk of data from FD, up until a terminator. The hunk is
|
||||
limited by whatever the TERMINATOR callback chooses as its
|
||||
terminator. For example, if terminator stops at newline, the hunk
|
||||
@@ -539,7 +547,7 @@ fd_read_hunk (int fd, hunk_terminator_t terminator, long sizehint, long maxsize)
|
||||
rdlen = fd_read (fd, hunk + tail, remain, 0);
|
||||
if (rdlen < 0)
|
||||
{
|
||||
xfree_null (hunk);
|
||||
xfree (hunk);
|
||||
return NULL;
|
||||
}
|
||||
tail += rdlen;
|
||||
@@ -584,7 +592,7 @@ fd_read_hunk (int fd, hunk_terminator_t terminator, long sizehint, long maxsize)
|
||||
}
|
||||
|
||||
static const char *
|
||||
line_terminator (const char *start, const char *peeked, int peeklen)
|
||||
line_terminator (const char *start _GL_UNUSED, const char *peeked, int peeklen)
|
||||
{
|
||||
const char *p = memchr (peeked, '\n', peeklen);
|
||||
if (p)
|
||||
@@ -611,7 +619,7 @@ fd_read_line (int fd)
|
||||
{
|
||||
return fd_read_hunk (fd, line_terminator, 128, FD_READ_LINE_MAX);
|
||||
}
|
||||
|
||||
|
||||
/* Return a printed representation of the download rate, along with
|
||||
the units appropriate for the download speed. */
|
||||
|
||||
@@ -646,7 +654,7 @@ calc_rate (wgint bytes, double secs, int *units)
|
||||
{
|
||||
double dlrate;
|
||||
double bibyte = 1000.0;
|
||||
|
||||
|
||||
if (!opt.report_bps)
|
||||
bibyte = 1024.0;
|
||||
|
||||
@@ -675,22 +683,25 @@ calc_rate (wgint bytes, double secs, int *units)
|
||||
|
||||
return dlrate;
|
||||
}
|
||||
|
||||
|
||||
#define SUSPEND_POST_DATA do { \
|
||||
post_data_suspended = true; \
|
||||
saved_post_data = opt.post_data; \
|
||||
saved_post_file_name = opt.post_file_name; \
|
||||
opt.post_data = NULL; \
|
||||
opt.post_file_name = NULL; \
|
||||
|
||||
#define SUSPEND_METHOD do { \
|
||||
method_suspended = true; \
|
||||
saved_body_data = opt.body_data; \
|
||||
saved_body_file_name = opt.body_file; \
|
||||
saved_method = opt.method; \
|
||||
opt.body_data = NULL; \
|
||||
opt.body_file = NULL; \
|
||||
opt.method = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define RESTORE_POST_DATA do { \
|
||||
if (post_data_suspended) \
|
||||
#define RESTORE_METHOD do { \
|
||||
if (method_suspended) \
|
||||
{ \
|
||||
opt.post_data = saved_post_data; \
|
||||
opt.post_file_name = saved_post_file_name; \
|
||||
post_data_suspended = false; \
|
||||
opt.body_data = saved_body_data; \
|
||||
opt.body_file = saved_body_file_name; \
|
||||
opt.method = saved_method; \
|
||||
method_suspended = false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -715,12 +726,13 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
char *mynewloc, *proxy;
|
||||
struct url *u = orig_parsed, *proxy_url;
|
||||
int up_error_code; /* url parse error code */
|
||||
char *local_file;
|
||||
char *local_file = NULL;
|
||||
int redirection_count = 0;
|
||||
|
||||
bool post_data_suspended = false;
|
||||
char *saved_post_data = NULL;
|
||||
char *saved_post_file_name = NULL;
|
||||
bool method_suspended = false;
|
||||
char *saved_body_data = NULL;
|
||||
char *saved_method = NULL;
|
||||
char *saved_body_file_name = NULL;
|
||||
|
||||
/* If dt is NULL, use local storage. */
|
||||
if (!dt)
|
||||
@@ -742,7 +754,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
|
||||
result = NOCONERROR;
|
||||
mynewloc = NULL;
|
||||
local_file = NULL;
|
||||
xfree(local_file);
|
||||
proxy_url = NULL;
|
||||
|
||||
proxy = getproxy (u);
|
||||
@@ -753,7 +765,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
pi->utf8_encode = false;
|
||||
|
||||
/* Parse the proxy URL. */
|
||||
proxy_url = url_parse (proxy, &up_error_code, NULL, true);
|
||||
proxy_url = url_parse (proxy, &up_error_code, pi, true);
|
||||
if (!proxy_url)
|
||||
{
|
||||
char *error = url_error (proxy, up_error_code);
|
||||
@@ -761,7 +773,9 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
proxy, error);
|
||||
xfree (url);
|
||||
xfree (error);
|
||||
RESTORE_POST_DATA;
|
||||
xfree (proxy);
|
||||
iri_free (pi);
|
||||
RESTORE_METHOD;
|
||||
result = PROXERR;
|
||||
goto bail;
|
||||
}
|
||||
@@ -770,10 +784,14 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
logprintf (LOG_NOTQUIET, _("Error in proxy URL %s: Must be HTTP.\n"), proxy);
|
||||
url_free (proxy_url);
|
||||
xfree (url);
|
||||
RESTORE_POST_DATA;
|
||||
xfree (proxy);
|
||||
iri_free (pi);
|
||||
RESTORE_METHOD;
|
||||
result = PROXERR;
|
||||
goto bail;
|
||||
}
|
||||
iri_free(pi);
|
||||
xfree (proxy);
|
||||
}
|
||||
|
||||
if (u->scheme == SCHEME_HTTP
|
||||
@@ -782,10 +800,28 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
#endif
|
||||
|| (proxy_url && proxy_url->scheme == SCHEME_HTTP))
|
||||
{
|
||||
#ifdef HAVE_HSTS
|
||||
#ifdef TESTING
|
||||
/* we don't link against main.o when we're testing */
|
||||
hsts_store_t hsts_store = NULL;
|
||||
#else
|
||||
extern hsts_store_t hsts_store;
|
||||
#endif
|
||||
|
||||
if (opt.hsts && hsts_store)
|
||||
{
|
||||
if (hsts_match (hsts_store, u))
|
||||
logprintf (LOG_VERBOSE, "URL transformed to HTTPS due to an HSTS policy\n");
|
||||
}
|
||||
#endif
|
||||
result = http_loop (u, orig_parsed, &mynewloc, &local_file, refurl, dt,
|
||||
proxy_url, iri);
|
||||
}
|
||||
else if (u->scheme == SCHEME_FTP)
|
||||
else if (u->scheme == SCHEME_FTP
|
||||
#ifdef HAVE_SSL
|
||||
|| u->scheme == SCHEME_FTPS
|
||||
#endif
|
||||
)
|
||||
{
|
||||
/* If this is a redirection, temporarily turn off opt.ftp_glob
|
||||
and opt.recursive, both being undesirable when following
|
||||
@@ -794,14 +830,19 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
if (redirection_count)
|
||||
oldrec = glob = false;
|
||||
|
||||
result = ftp_loop (u, &local_file, dt, proxy_url, recursive, glob);
|
||||
result = ftp_loop (u, orig_parsed, &local_file, dt, proxy_url,
|
||||
recursive, glob);
|
||||
recursive = oldrec;
|
||||
|
||||
/* There is a possibility of having HTTP being redirected to
|
||||
FTP. In these cases we must decide whether the text is HTML
|
||||
according to the suffix. The HTML suffixes are `.html',
|
||||
`.htm' and a few others, case-insensitive. */
|
||||
if (redirection_count && local_file && u->scheme == SCHEME_FTP)
|
||||
if (redirection_count && local_file && (u->scheme == SCHEME_FTP
|
||||
#ifdef HAVE_SSL
|
||||
|| u->scheme == SCHEME_FTPS
|
||||
#endif
|
||||
))
|
||||
{
|
||||
if (has_html_suffix_p (local_file))
|
||||
*dt |= TEXTHTML;
|
||||
@@ -822,8 +863,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
|
||||
assert (mynewloc != NULL);
|
||||
|
||||
if (local_file)
|
||||
xfree (local_file);
|
||||
xfree (local_file);
|
||||
|
||||
/* The HTTP specs only allow absolute URLs to appear in
|
||||
redirects, but a ton of boneheaded webservers and CGIs out
|
||||
@@ -833,11 +873,15 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
xfree (mynewloc);
|
||||
mynewloc = construced_newloc;
|
||||
|
||||
/* Reset UTF-8 encoding state, keep the URI encoding and reset
|
||||
#ifdef ENABLE_IRI
|
||||
/* Reset UTF-8 encoding state, set the URI encoding and reset
|
||||
the content encoding. */
|
||||
iri->utf8_encode = opt.enable_iri;
|
||||
if (opt.encoding_remote)
|
||||
set_uri_encoding (iri, opt.encoding_remote, true);
|
||||
set_content_encoding (iri, NULL);
|
||||
xfree_null (iri->orig_url);
|
||||
xfree (iri->orig_url);
|
||||
#endif
|
||||
|
||||
/* Now, see if this new location makes sense. */
|
||||
newloc_parsed = url_parse (mynewloc, &up_error_code, iri, true);
|
||||
@@ -853,7 +897,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
xfree (url);
|
||||
xfree (mynewloc);
|
||||
xfree (error);
|
||||
RESTORE_POST_DATA;
|
||||
RESTORE_METHOD;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
@@ -875,7 +919,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
}
|
||||
xfree (url);
|
||||
xfree (mynewloc);
|
||||
RESTORE_POST_DATA;
|
||||
RESTORE_METHOD;
|
||||
result = WRONGCODE;
|
||||
goto bail;
|
||||
}
|
||||
@@ -894,15 +938,19 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
index page; that redirection is clearly a GET. We "suspend"
|
||||
POST data for the duration of the redirections, and restore
|
||||
it when we're done.
|
||||
|
||||
RFC2616 HTTP/1.1 introduces code 307 Temporary Redirect
|
||||
specifically to preserve the method of the request.
|
||||
*/
|
||||
if (result != NEWLOCATION_KEEP_POST && !post_data_suspended)
|
||||
SUSPEND_POST_DATA;
|
||||
|
||||
RFC2616 HTTP/1.1 introduces code 307 Temporary Redirect
|
||||
specifically to preserve the method of the request.
|
||||
*/
|
||||
if (result != NEWLOCATION_KEEP_POST && !method_suspended)
|
||||
SUSPEND_METHOD;
|
||||
|
||||
goto redirected;
|
||||
}
|
||||
else
|
||||
{
|
||||
xfree(mynewloc);
|
||||
}
|
||||
|
||||
/* Try to not encode in UTF-8 if fetching failed */
|
||||
if (!(*dt & RETROKF) && iri->utf8_encode)
|
||||
@@ -916,6 +964,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
if (u)
|
||||
{
|
||||
DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url)));
|
||||
xfree (url);
|
||||
url = xstrdup (u->url);
|
||||
iri_fallbacked = 1;
|
||||
goto redirected;
|
||||
@@ -924,7 +973,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
DEBUGP (("[Couldn't fallback to non-utf8 for %s\n", quote (url)));
|
||||
}
|
||||
|
||||
if (local_file && u && *dt & RETROKF)
|
||||
if (local_file && u && (*dt & RETROKF || opt.content_on_error))
|
||||
{
|
||||
register_download (u->url, local_file);
|
||||
|
||||
@@ -941,7 +990,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
if (file)
|
||||
*file = local_file ? local_file : NULL;
|
||||
else
|
||||
xfree_null (local_file);
|
||||
xfree (local_file);
|
||||
|
||||
if (orig_parsed != u)
|
||||
{
|
||||
@@ -962,11 +1011,12 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
|
||||
xfree (url);
|
||||
}
|
||||
|
||||
RESTORE_POST_DATA;
|
||||
RESTORE_METHOD;
|
||||
|
||||
bail:
|
||||
if (register_status)
|
||||
inform_exit_status (result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -996,13 +1046,13 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
if (url_valid_scheme (url))
|
||||
{
|
||||
int dt,url_err;
|
||||
uerr_t status;
|
||||
struct url *url_parsed = url_parse (url, &url_err, iri, true);
|
||||
if (!url_parsed)
|
||||
{
|
||||
char *error = url_error (url, url_err);
|
||||
logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error);
|
||||
xfree (error);
|
||||
iri_free (iri);
|
||||
return URLERROR;
|
||||
}
|
||||
|
||||
@@ -1019,15 +1069,16 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
if (dt & TEXTHTML)
|
||||
html = true;
|
||||
|
||||
#ifdef ENABLE_IRI
|
||||
/* If we have a found a content encoding, use it.
|
||||
* ( == is okay, because we're checking for identical object) */
|
||||
if (iri->content_encoding != opt.locale)
|
||||
set_uri_encoding (iri, iri->content_encoding, false);
|
||||
set_uri_encoding (iri, iri->content_encoding, false);
|
||||
#endif
|
||||
|
||||
/* Reset UTF-8 encode status */
|
||||
iri->utf8_encode = opt.enable_iri;
|
||||
xfree_null (iri->orig_url);
|
||||
iri->orig_url = NULL;
|
||||
xfree (iri->orig_url);
|
||||
|
||||
input_file = url_file;
|
||||
}
|
||||
@@ -1037,12 +1088,12 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
url_list = (html ? get_urls_html (input_file, NULL, NULL, iri)
|
||||
: get_urls_file (input_file));
|
||||
|
||||
xfree_null (url_file);
|
||||
xfree (url_file);
|
||||
|
||||
for (cur_url = url_list; cur_url; cur_url = cur_url->next, ++*count)
|
||||
{
|
||||
char *filename = NULL, *new_file = NULL;
|
||||
int dt;
|
||||
char *filename = NULL, *new_file = NULL, *proxy;
|
||||
int dt = 0;
|
||||
struct iri *tmpiri = iri_dup (iri);
|
||||
struct url *parsed_url = NULL;
|
||||
|
||||
@@ -1057,13 +1108,22 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
|
||||
parsed_url = url_parse (cur_url->url->url, NULL, tmpiri, true);
|
||||
|
||||
proxy = getproxy (cur_url->url);
|
||||
if ((opt.recursive || opt.page_requisites)
|
||||
&& (cur_url->url->scheme != SCHEME_FTP || getproxy (cur_url->url)))
|
||||
&& ((cur_url->url->scheme != SCHEME_FTP
|
||||
#ifdef HAVE_SSL
|
||||
&& cur_url->url->scheme != SCHEME_FTPS
|
||||
#endif
|
||||
) || proxy))
|
||||
{
|
||||
int old_follow_ftp = opt.follow_ftp;
|
||||
|
||||
/* Turn opt.follow_ftp on in case of recursive FTP retrieval */
|
||||
if (cur_url->url->scheme == SCHEME_FTP)
|
||||
if (cur_url->url->scheme == SCHEME_FTP
|
||||
#ifdef HAVE_SSL
|
||||
|| cur_url->url->scheme == SCHEME_FTPS
|
||||
#endif
|
||||
)
|
||||
opt.follow_ftp = 1;
|
||||
|
||||
status = retrieve_tree (parsed_url ? parsed_url : cur_url->url,
|
||||
@@ -1076,6 +1136,7 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
cur_url->url->url, &filename,
|
||||
&new_file, NULL, &dt, opt.recursive, tmpiri,
|
||||
true);
|
||||
xfree (proxy);
|
||||
|
||||
if (parsed_url)
|
||||
url_free (parsed_url);
|
||||
@@ -1090,8 +1151,8 @@ Removing file due to --delete-after in retrieve_from_file():\n"));
|
||||
dt &= ~RETROKF;
|
||||
}
|
||||
|
||||
xfree_null (new_file);
|
||||
xfree_null (filename);
|
||||
xfree (new_file);
|
||||
xfree (filename);
|
||||
iri_free (tmpiri);
|
||||
}
|
||||
|
||||
@@ -1167,7 +1228,7 @@ free_urlpos (struct urlpos *l)
|
||||
struct urlpos *next = l->next;
|
||||
if (l->url)
|
||||
url_free (l->url);
|
||||
xfree_null (l->local_name);
|
||||
xfree (l->local_name);
|
||||
xfree (l);
|
||||
l = next;
|
||||
}
|
||||
@@ -1177,7 +1238,16 @@ free_urlpos (struct urlpos *l)
|
||||
void
|
||||
rotate_backups(const char *fname)
|
||||
{
|
||||
int maxlen = strlen (fname) + 1 + numdigit (opt.backups) + 1;
|
||||
#ifdef __VMS
|
||||
# define SEP "_"
|
||||
# define AVS ";*" /* All-version suffix. */
|
||||
# define AVSL (sizeof (AVS) - 1)
|
||||
#else
|
||||
# define SEP "."
|
||||
# define AVSL 0
|
||||
#endif
|
||||
|
||||
int maxlen = strlen (fname) + sizeof (SEP) + numdigit (opt.backups) + AVSL;
|
||||
char *from = (char *)alloca (maxlen);
|
||||
char *to = (char *)alloca (maxlen);
|
||||
struct_stat sb;
|
||||
@@ -1189,12 +1259,24 @@ rotate_backups(const char *fname)
|
||||
|
||||
for (i = opt.backups; i > 1; i--)
|
||||
{
|
||||
sprintf (from, "%s.%d", fname, i - 1);
|
||||
sprintf (to, "%s.%d", fname, i);
|
||||
#ifdef VMS
|
||||
/* Delete (all versions of) any existing max-suffix file, to avoid
|
||||
* creating multiple versions of it. (On VMS, rename() will
|
||||
* create a new version of an existing destination file, not
|
||||
* destroy/overwrite it.)
|
||||
*/
|
||||
if (i == opt.backups)
|
||||
{
|
||||
sprintf (to, "%s%s%d%s", fname, SEP, i, AVS);
|
||||
delete (to);
|
||||
}
|
||||
#endif
|
||||
sprintf (to, "%s%s%d", fname, SEP, i);
|
||||
sprintf (from, "%s%s%d", fname, SEP, i - 1);
|
||||
rename (from, to);
|
||||
}
|
||||
|
||||
sprintf (to, "%s.%d", fname, 1);
|
||||
sprintf (to, "%s%s%d", fname, SEP, 1);
|
||||
rename(fname, to);
|
||||
}
|
||||
|
||||
@@ -1207,7 +1289,6 @@ getproxy (struct url *u)
|
||||
{
|
||||
char *proxy = NULL;
|
||||
char *rewritten_url;
|
||||
static char rewritten_storage[1024];
|
||||
|
||||
if (!opt.use_proxy)
|
||||
return NULL;
|
||||
@@ -1223,6 +1304,9 @@ getproxy (struct url *u)
|
||||
case SCHEME_HTTPS:
|
||||
proxy = opt.https_proxy ? opt.https_proxy : getenv ("https_proxy");
|
||||
break;
|
||||
case SCHEME_FTPS:
|
||||
proxy = opt.ftp_proxy ? opt.ftp_proxy : getenv ("ftps_proxy");
|
||||
break;
|
||||
#endif
|
||||
case SCHEME_FTP:
|
||||
proxy = opt.ftp_proxy ? opt.ftp_proxy : getenv ("ftp_proxy");
|
||||
@@ -1237,13 +1321,9 @@ getproxy (struct url *u)
|
||||
getproxy() to return static storage. */
|
||||
rewritten_url = rewrite_shorthand_url (proxy);
|
||||
if (rewritten_url)
|
||||
{
|
||||
strncpy (rewritten_storage, rewritten_url, sizeof (rewritten_storage));
|
||||
rewritten_storage[sizeof (rewritten_storage) - 1] = '\0';
|
||||
proxy = rewritten_storage;
|
||||
}
|
||||
return rewritten_url;
|
||||
|
||||
return proxy;
|
||||
return strdup(proxy);
|
||||
}
|
||||
|
||||
/* Returns true if URL would be downloaded through a proxy. */
|
||||
@@ -1252,9 +1332,13 @@ bool
|
||||
url_uses_proxy (struct url * u)
|
||||
{
|
||||
bool ret;
|
||||
char *proxy;
|
||||
|
||||
if (!u)
|
||||
return false;
|
||||
ret = getproxy (u) != NULL;
|
||||
proxy = getproxy (u);
|
||||
ret = proxy != NULL;
|
||||
xfree (proxy);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Declarations for retr.c.
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
|
||||
Inc.
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
|
||||
@@ -34,6 +34,8 @@ as that of the covered work. */
|
||||
|
||||
#include "url.h"
|
||||
|
||||
extern int numurls;
|
||||
|
||||
/* These global vars should be made static to retr.c and exported via
|
||||
functions! */
|
||||
extern SUM_SIZE_INT total_downloaded_bytes;
|
||||
@@ -50,7 +52,7 @@ enum {
|
||||
rb_chunked_transfer_encoding = 4
|
||||
};
|
||||
|
||||
int fd_read_body (int, FILE *, wgint, wgint, wgint *, wgint *, double *, int, FILE *);
|
||||
int fd_read_body (const char *, int, FILE *, wgint, wgint, wgint *, wgint *, double *, int, FILE *);
|
||||
|
||||
typedef const char *(*hunk_terminator_t) (const char *, const char *, int);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Keep track of visited URLs in spider mode.
|
||||
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2015 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is part of GNU Wget.
|
||||
@@ -45,13 +45,13 @@ static struct hash_table *nonexisting_urls_set;
|
||||
|
||||
/* Cleanup the data structures associated with this file. */
|
||||
|
||||
static void
|
||||
void
|
||||
spider_cleanup (void)
|
||||
{
|
||||
if (nonexisting_urls_set)
|
||||
string_set_free (nonexisting_urls_set);
|
||||
}
|
||||
|
||||
|
||||
/* Remembers broken links. */
|
||||
void
|
||||
nonexisting_url (const char *url)
|
||||
@@ -97,4 +97,3 @@ print_broken_links (void)
|
||||
/*
|
||||
* vim: et ts=2 sw=2
|
||||
*/
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user