mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-29 17:32:43 +00:00
Dump com_err, it's a stinking crock of shit.
This commit is contained in:
parent
6774c05335
commit
ba101983d5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=60924
@ -7,11 +7,11 @@ CFLAGS+= -DINET6
|
||||
.if !defined(DEBUG)
|
||||
CFLAGS+= -DNDEBUG
|
||||
.endif
|
||||
SRCS= fetch.c common.c ftp.c http.c file.c fetch_err.c \
|
||||
fetch_err.h ftperr.h httperr.h
|
||||
INCS= fetch.h ${.OBJDIR}/fetch_err.h
|
||||
SRCS= fetch.c common.c ftp.c http.c file.c \
|
||||
ftperr.h httperr.h
|
||||
INCS= fetch.h
|
||||
MAN3= fetch.3
|
||||
CLEANFILES= fetch_err.c fetch_err.h ftperr.h httperr.h
|
||||
CLEANFILES= ftperr.h httperr.h
|
||||
|
||||
SHLIB_MAJOR= 2
|
||||
SHLIB_MINOR= 0
|
||||
@ -38,10 +38,4 @@ httperr.h: http.errors
|
||||
@echo " { -1, FETCH_UNKNOWN, \"Unknown HTTP error\" }" >> ${.TARGET}
|
||||
@echo "};" >> ${.TARGET}
|
||||
|
||||
hdrs: fetch_err.h
|
||||
|
||||
.ORDER: fetch_err.c fetch_err.h
|
||||
fetch_err.c fetch_err.h: fetch_err.et
|
||||
compile_et ${.ALLSRC}
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
@ -33,9 +33,9 @@
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <com_err.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -58,31 +58,18 @@ static struct fetcherr _netdb_errlist[] = {
|
||||
{ -1, FETCH_UNKNOWN, "Unknown resolver error" }
|
||||
};
|
||||
|
||||
static int com_err_initialized;
|
||||
|
||||
/*** Error-reporting functions ***********************************************/
|
||||
|
||||
/*
|
||||
* Initialize the common error library
|
||||
*/
|
||||
static void
|
||||
_fetch_init_com_err(void)
|
||||
{
|
||||
initialize_ftch_error_table();
|
||||
com_err_initialized = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Map error code to string
|
||||
*/
|
||||
static int
|
||||
static struct fetcherr *
|
||||
_fetch_finderr(struct fetcherr *p, int e)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; p[i].num != -1; i++)
|
||||
if (p[i].num == e)
|
||||
break;
|
||||
return i;
|
||||
while (p->num != -1 && p->num != e)
|
||||
p++;
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -91,14 +78,9 @@ _fetch_finderr(struct fetcherr *p, int e)
|
||||
void
|
||||
_fetch_seterr(struct fetcherr *p, int e)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (!com_err_initialized)
|
||||
_fetch_init_com_err();
|
||||
|
||||
n = _fetch_finderr(p, e);
|
||||
fetchLastErrCode = p[n].cat;
|
||||
com_err("libfetch", fetchLastErrCode, "(%03d %s)", e, p[n].string);
|
||||
p = _fetch_finderr(p, e);
|
||||
fetchLastErrCode = p->cat;
|
||||
snprintf(fetchLastErrString, MAXERRSTRING, "%s", p->string);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -110,9 +92,6 @@ _fetch_syserr(void)
|
||||
int e;
|
||||
e = errno;
|
||||
|
||||
if (!com_err_initialized)
|
||||
_fetch_init_com_err();
|
||||
|
||||
switch (errno) {
|
||||
case 0:
|
||||
fetchLastErrCode = FETCH_OK;
|
||||
@ -163,34 +142,21 @@ _fetch_syserr(void)
|
||||
default:
|
||||
fetchLastErrCode = FETCH_UNKNOWN;
|
||||
}
|
||||
com_err("libfetch", fetchLastErrCode, "(%03d %s)", e, strerror(e));
|
||||
snprintf(fetchLastErrString, MAXERRSTRING, "%s", strerror(e));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Emit status message
|
||||
*/
|
||||
int
|
||||
void
|
||||
_fetch_info(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *s;
|
||||
|
||||
if (!com_err_initialized)
|
||||
_fetch_init_com_err();
|
||||
|
||||
va_start(ap, fmt);
|
||||
vasprintf(&s, fmt, ap);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (s == NULL) {
|
||||
com_err("libfetch", FETCH_MEMORY, "");
|
||||
return -1;
|
||||
} else {
|
||||
com_err("libfetch", FETCH_VERBOSE, "%s", s);
|
||||
free(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ struct fetcherr {
|
||||
|
||||
void _fetch_seterr(struct fetcherr *p, int e);
|
||||
void _fetch_syserr(void);
|
||||
int _fetch_info(char *fmt, ...);
|
||||
void _fetch_info(char *fmt, ...);
|
||||
int _fetch_connect(char *host, int port, int af, int verbose);
|
||||
int _fetch_getln(int fd, char **buf, size_t *size, size_t *len);
|
||||
int _fetch_add_entry(struct url_ent **p, int *size, int *len,
|
||||
|
@ -328,13 +328,8 @@ functions return 0 on success and -1 on failure.
|
||||
All other functions return a stream pointer which may be used to
|
||||
access the requested document, or NULL if an error occurred.
|
||||
.Pp
|
||||
.Nm Libfetch
|
||||
uses the Common Error Library
|
||||
.Nm ( libcom_err )
|
||||
to report errors.
|
||||
The error code passed to
|
||||
.Fn com_err
|
||||
is one of:
|
||||
The following error codes are defined in
|
||||
.Aq Pa fetch.h :
|
||||
.Bl -tag -width 18n
|
||||
.It Bq Er FETCH_ABORT
|
||||
Operation aborted
|
||||
@ -384,7 +379,6 @@ and
|
||||
environment variables, respectively, as the address of a proxy server
|
||||
to use for transferring files.
|
||||
.Sh SEE ALSO
|
||||
.Xr com_err 3 ,
|
||||
.Xr fetch 1 ,
|
||||
.Xr ftpio 3 ,
|
||||
.Xr ip 4 .
|
||||
@ -413,14 +407,6 @@ to use for transferring files.
|
||||
.%B File Transfer Protocol
|
||||
.%O RFC959
|
||||
.Re
|
||||
.Sh NOTES
|
||||
The
|
||||
.Nm fetch
|
||||
library uses the Common Error library, and applications which link
|
||||
with
|
||||
.Nm libfetch
|
||||
must therefore also link with
|
||||
.Nm libcom_err .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm fetch
|
||||
@ -493,4 +479,8 @@ The HTTP code needs a complete rewrite, or at least a serious cleanup.
|
||||
.Pp
|
||||
The man page is poorly written and produces badly formatted text.
|
||||
.Pp
|
||||
The error reporting mechanism is unsatisfactory.
|
||||
.Pp
|
||||
Some parts of the code are not fully reentrant.
|
||||
.Pp
|
||||
Tons of other stuff.
|
||||
|
@ -40,8 +40,9 @@
|
||||
#include "common.h"
|
||||
|
||||
|
||||
int fetchLastErrCode;
|
||||
int fetchTimeout;
|
||||
int fetchLastErrCode;
|
||||
char fetchLastErrString[MAXERRSTRING];
|
||||
int fetchTimeout;
|
||||
|
||||
|
||||
/*** Local data **************************************************************/
|
||||
|
@ -31,9 +31,7 @@
|
||||
#ifndef _FETCH_H_INCLUDED
|
||||
#define _FETCH_H_INCLUDED
|
||||
|
||||
#include <fetch_err.h>
|
||||
|
||||
#define _LIBFETCH_VER "libfetch/1.0"
|
||||
#define _LIBFETCH_VER "libfetch/2.0"
|
||||
|
||||
#define URL_SCHEMELEN 16
|
||||
#define URL_USERLEN 256
|
||||
@ -61,6 +59,27 @@ struct url_ent {
|
||||
struct url_stat stat;
|
||||
};
|
||||
|
||||
/* Error codes */
|
||||
#define FETCH_ABORT 1
|
||||
#define FETCH_AUTH 2
|
||||
#define FETCH_DOWN 3
|
||||
#define FETCH_EXISTS 4
|
||||
#define FETCH_FULL 5
|
||||
#define FETCH_INFO 6
|
||||
#define FETCH_MEMORY 7
|
||||
#define FETCH_MOVED 8
|
||||
#define FETCH_NETWORK 9
|
||||
#define FETCH_OK 10
|
||||
#define FETCH_PROTO 11
|
||||
#define FETCH_RESOLV 12
|
||||
#define FETCH_SERVER 13
|
||||
#define FETCH_TEMP 14
|
||||
#define FETCH_TIMEOUT 15
|
||||
#define FETCH_UNAVAIL 16
|
||||
#define FETCH_UNKNOWN 17
|
||||
#define FETCH_URL 18
|
||||
#define FETCH_VERBOSE 19
|
||||
|
||||
/* FILE-specific functions */
|
||||
FILE *fetchGetFile(struct url *, char *);
|
||||
FILE *fetchPutFile(struct url *, char *);
|
||||
@ -96,6 +115,8 @@ void fetchFreeURL(struct url *);
|
||||
|
||||
/* Last error code */
|
||||
extern int fetchLastErrCode;
|
||||
#define MAXERRSTRING 256
|
||||
extern char fetchLastErrString[MAXERRSTRING];
|
||||
extern int fetchTimeout;
|
||||
|
||||
#endif
|
||||
|
@ -1,50 +0,0 @@
|
||||
#-
|
||||
# Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer
|
||||
# in this position and unchanged.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
et ftch
|
||||
ec FETCH_ABORT, "Operation aborted"
|
||||
ec FETCH_AUTH, "Authentication failed"
|
||||
ec FETCH_DOWN, "Service unavailable"
|
||||
ec FETCH_EXISTS, "File exists"
|
||||
ec FETCH_FULL, "File system full"
|
||||
ec FETCH_INFO, "Informational response"
|
||||
ec FETCH_MEMORY, "Insufficient memory"
|
||||
ec FETCH_MOVED, "File has moved"
|
||||
ec FETCH_NETWORK, "Network error"
|
||||
ec FETCH_OK, "No error"
|
||||
ec FETCH_PROTO, "Protocol error"
|
||||
ec FETCH_RESOLV, "Resolver error"
|
||||
ec FETCH_SERVER, "Server error"
|
||||
ec FETCH_TEMP, "Temporary error"
|
||||
ec FETCH_TIMEOUT, "Operation timed out"
|
||||
ec FETCH_UNAVAIL, "File is not available"
|
||||
ec FETCH_UNKNOWN, "Unknown error"
|
||||
ec FETCH_URL, "Invalid URL"
|
||||
ec FETCH_VERBOSE, "Info:"
|
||||
end
|
Loading…
Reference in New Issue
Block a user