blob: 5c380a366d9f70fbafdb582254b3efbe490d51a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/* Exit status handling.
Copyright (C) 2009-2012, 2015, 2018-2023 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/>.
*/
#include "wget.h"
#include "exits.h"
static int final_exit_status = WGET_EXIT_SUCCESS;
/* XXX: I don't like that newly-added uerr_t codes will doubtless fall
through the craccks, or the fact that we seem to have way more
codes than we know what to do with. Need to go through and sort
through the truly essential codes, and merge the rest with
those. Quite a few are never even used!
Quite a few of the codes below would have no business being
returned to retrieve_url's caller, but since it's very difficult to
determine which do and which don't, I grab virtually all of them to
be safe. */
static int
get_status_for_err (uerr_t err)
{
switch (err)
{
case RETROK:
return WGET_EXIT_SUCCESS;
case FOPENERR: case FOPEN_EXCL_ERR: case FWRITEERR: case WRITEFAILED:
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:
case READERR: case TRYLIMEXC:
return WGET_EXIT_NETWORK_FAIL;
case VERIFCERTERR:
return WGET_EXIT_SSL_AUTH_FAIL;
case FTPLOGINC: case FTPLOGREFUSED: case AUTHFAILED:
return WGET_EXIT_SERVER_AUTH_FAIL;
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 GATEWAYTIMEOUT:
return WGET_EXIT_SERVER_ERROR;
case URLERROR: case QUOTEXC: case SSLINITFAILED: case UNKNOWNATTR:
default:
return WGET_EXIT_UNKNOWN;
}
}
/* inform_exit_status
*
* Ensure that Wget's exit status will reflect the problem indicated
* by ERR, unless the exit status has already been set to reflect a more
* important problem. */
void
inform_exit_status (uerr_t err)
{
int new_status = get_status_for_err (err);
if (new_status != WGET_EXIT_SUCCESS
&& (final_exit_status == WGET_EXIT_SUCCESS
|| new_status < final_exit_status))
{
final_exit_status = new_status;
}
}
int
get_exit_status (void)
{
return
(final_exit_status == WGET_EXIT_UNKNOWN)
? 1
: final_exit_status;
}
|