]> sjero.net Git - wget/blob - src/exits.c
mass change: update copyright years.
[wget] / src / exits.c
1 /* Command line parsing.
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3    2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
4    Inc.
5
6    This file is part of GNU Wget.
7
8    GNU Wget is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    GNU Wget is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with Wget.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "wget.h"
23 #include "exits.h"
24
25 /* Final exit code possibilities. Exit codes 1 and 2 are reserved
26  * for situations that lead to direct exits from Wget, not using the
27  * value of final_exit_status. */
28 enum
29   {
30     WGET_EXIT_SUCCESS = 0,
31
32     WGET_EXIT_MINIMUM = 3,
33     WGET_EXIT_IO_FAIL = WGET_EXIT_MINIMUM,
34     WGET_EXIT_NETWORK_FAIL = 4,
35     WGET_EXIT_SSL_AUTH_FAIL = 5,
36     WGET_EXIT_SERVER_AUTH_FAIL = 6,
37     WGET_EXIT_PROTOCOL_ERROR = 7,
38     WGET_EXIT_SERVER_ERROR = 8,
39
40     WGET_EXIT_UNKNOWN
41   };
42
43 static int final_exit_status = WGET_EXIT_SUCCESS;
44
45 /* XXX: I don't like that newly-added uerr_t codes will doubtless fall
46    through the craccks, or the fact that we seem to have way more
47    codes than we know what to do with. Need to go through and sort
48    through the truly essential codes, and merge the rest with
49    those. Quite a few are never even used!
50
51    Quite a few of the codes below would have no business being
52    returned to retrieve_url's caller, but since it's very difficult to
53    determine which do and which don't, I grab virtually all of them to
54    be safe. */
55 static int
56 get_status_for_err (uerr_t err)
57 {
58   switch (err)
59     {
60     case RETROK:
61       return WGET_EXIT_SUCCESS;
62     case FOPENERR: case FOPEN_EXCL_ERR: case FWRITEERR: case WRITEFAILED:
63     case UNLINKERR:
64       return WGET_EXIT_IO_FAIL;
65     case NOCONERROR: case HOSTERR: case CONSOCKERR: case CONERROR:
66     case CONSSLERR: case CONIMPOSSIBLE: case FTPRERR: case FTPINVPASV:
67     case READERR: case TRYLIMEXC:
68       return WGET_EXIT_NETWORK_FAIL;
69     case VERIFCERTERR:
70       return WGET_EXIT_SSL_AUTH_FAIL;
71     case FTPLOGINC: case FTPLOGREFUSED: case AUTHFAILED:
72       return WGET_EXIT_SERVER_AUTH_FAIL;
73     case HEOF: case HERR:
74       return WGET_EXIT_PROTOCOL_ERROR;
75     case WRONGCODE: case FTPPORTERR: case FTPSYSERR:
76     case FTPNSFOD: case FTPUNKNOWNTYPE: case FTPSRVERR:
77     case FTPRETRINT: case FTPRESTFAIL: case FTPNOPASV:
78     case CONTNOTSUPPORTED: case RANGEERR: case RETRBADPATTERN:
79     case PROXERR:
80       return WGET_EXIT_SERVER_ERROR;
81     case URLERROR: case QUOTEXC: case SSLINITFAILED:
82     default:
83       return WGET_EXIT_UNKNOWN;
84     }
85 }
86
87 /* inform_exit_status
88  *
89  * Ensure that Wget's exit status will reflect the problem indicated
90  * by ERR, unless the exit status has already been set to reflect a more
91  * important problem. */
92 void
93 inform_exit_status (uerr_t err)
94 {
95   int new_status = get_status_for_err (err);
96
97   if (new_status != WGET_EXIT_SUCCESS
98       && (final_exit_status == WGET_EXIT_SUCCESS
99           || new_status < final_exit_status))
100     {
101       final_exit_status = new_status;
102     }
103 }
104
105 int
106 get_exit_status (void)
107 {
108   return
109     (final_exit_status == WGET_EXIT_UNKNOWN)
110       ? 1
111       : final_exit_status;
112 }
113