From 5e03c718f4e7ff13cb6834eda737c269ebed02ad Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:04:52 +0200 Subject: Adding upstream version 1.21.3. Signed-off-by: Daniel Baumann --- src/exits.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/exits.c (limited to 'src/exits.c') diff --git a/src/exits.c b/src/exits.c new file mode 100644 index 0000000..adce4f9 --- /dev/null +++ b/src/exits.c @@ -0,0 +1,93 @@ +/* Exit status handling. + Copyright (C) 2009-2012, 2015, 2018-2022 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 . +*/ + +#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; +} -- cgit v1.2.3