New function wget_strerror()

* docs/Makefile.am: Add man page build for error functions
* include/wget/wget.h: Make WGET_E_* an enum wget_error_t,
  declare new function wget_strerror()
* libwget/Makefile.am: Add error.c
* libwget/error.c: New file
This commit is contained in:
Tim Rühsen
2018-08-17 17:09:49 +02:00
parent aa943de315
commit 6e22761f89
4 changed files with 79 additions and 13 deletions

View File

@ -9,6 +9,7 @@ man3_MANS =\
$(builddir)/man/man3/libwget-bitmap.3\
$(builddir)/man/man3/libwget-console.3\
$(builddir)/man/man3/libwget-dns-caching.3\
$(builddir)/man/man3/libwget-error.3\
$(builddir)/man/man3/libwget-hash.3\
$(builddir)/man/man3/libwget-hashmap.3\
$(builddir)/man/man3/libwget-io.3\

View File

@ -241,18 +241,23 @@ WGET_BEGIN_DECLS
#define WGET_HTTP_USER_DATA 2019
// definition of error conditions
#define WGET_E_SUCCESS 0 /* OK */
#define WGET_E_UNKNOWN -1 /* general error if nothing else appropriate */
#define WGET_E_INVALID -2 /* invalid value to function */
#define WGET_E_TIMEOUT -3 /* timeout condition */
#define WGET_E_CONNECT -4 /* connect failure */
#define WGET_E_HANDSHAKE -5 /* general TLS handshake failure */
#define WGET_E_CERTIFICATE -6 /* general TLS certificate failure */
#define WGET_E_TLS_DISABLED -7 /* TLS was not enabled at compile time */
#define WGET_E_GPG_DISABLED -8 /* GPGME was not enabled at compile time */
#define WGET_E_GPG_VER_FAIL -9 /* 1 or more non-valid signatures */
#define WGET_E_GPG_VER_ERR -11 /* Verification failed, GPGME error */
#define WGET_E_XML_PARSE_ERR -12 /* XML parsing failed */
typedef enum {
WGET_E_SUCCESS = 0, /* OK */
WGET_E_UNKNOWN = -1, /* general error if nothing else appropriate */
WGET_E_INVALID = -2, /* invalid value to function */
WGET_E_TIMEOUT = -3, /* timeout condition */
WGET_E_CONNECT = -4, /* connect failure */
WGET_E_HANDSHAKE = -5, /* general TLS handshake failure */
WGET_E_CERTIFICATE = -6, /* general TLS certificate failure */
WGET_E_TLS_DISABLED = -7, /* TLS was not enabled at compile time */
WGET_E_GPG_DISABLED = -8, /* GPGME was not enabled at compile time */
WGET_E_GPG_VER_FAIL = -9, /* 1 or more non-valid signatures */
WGET_E_GPG_VER_ERR = -11, /* Verification failed, GPGME error */
WGET_E_XML_PARSE_ERR = -12, /* XML parsing failed */
} wget_error_t;
WGETAPI const char *
wget_strerror(int err);
typedef void (*wget_global_get_func_t)(const char *, size_t);

View File

@ -7,7 +7,7 @@ libwget_la_SOURCES = \
decompressor.c dns_cache.c encoding.c hash_printf.c hashfile.c hashmap.c io.c hsts.c hpkp.c html_url.c http.c http.h \
http_parse.c init.c ip.c iri.c list.c log.c logger.c logger.h mem.c metalink.c net.c net.h netrc.c ocsp.c pipe.c \
plugin.c printf.c random.c robots.c rss_url.c sitemap_url.c ssl_gnutls.c stringmap.c strlcpy.c strscpy.c thread.c \
tls_session.c utils.c vector.c xalloc.c xml.c private.h http_highlevel.c
tls_session.c utils.c vector.c xalloc.c xml.c private.h http_highlevel.c error.c
libwget_la_CPPFLAGS =\
-fPIC -I$(top_srcdir)/include/wget -I$(srcdir) -I$(top_builddir)/lib -I$(top_srcdir)/lib $(CFLAG_VISIBILITY) -DBUILDING_LIBWGET \
-DWGETVER_FILE=\"$(top_builddir)/include/wget/wgetver.h\"

60
libwget/error.c Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright(c) 2018 Free Software Foundation, Inc.
*
* This file is part of libwget.
*
* Libwget is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libwget 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libwget. If not, see <https://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <wget.h>
#include "private.h"
/**
* \file
* \brief Error functions
* \defgroup libwget-error Error functions
* @{
*
* Here are th implementations of libwget error functions.
*/
/**
* \param[in] rc Error code from another libwget function
* \return A humanly readable string describing error
*
* Convert an internal libwget error code to a humanly readable string.
* The returned pointer must not be de-allocated by the caller.
*/
const char *wget_strerror(int err)
{
switch (err) {
case WGET_E_SUCCESS: return _("Success");
case WGET_E_UNKNOWN: return _("General error");
case WGET_E_INVALID: return _("Invalid value");
case WGET_E_TIMEOUT: return _("Timeout");
case WGET_E_CONNECT: return _("Connect error");
case WGET_E_HANDSHAKE: return _("Handshake error");
case WGET_E_CERTIFICATE: return _("Certificate error");
case WGET_E_TLS_DISABLED: return _("Wget has been built without TLS support");
case WGET_E_GPG_DISABLED: return _("Wget has been built without GPG support");
case WGET_E_GPG_VER_FAIL: return _("GPG signature is bad");
case WGET_E_GPG_VER_ERR: return _("GPG error");
case WGET_E_XML_PARSE_ERR: return _("Failed to parse XML");
default: return _("Unknown error");
}
}
/**@}*/