summaryrefslogtreecommitdiffstats
path: root/lib/libftpio
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1996-08-21 01:12:11 +0000
committerjkh <jkh@FreeBSD.org>1996-08-21 01:12:11 +0000
commitfc1487cdb0526da63e7c8dbf92b1bcf3e66d356c (patch)
treed73ecb14dd9b2627668e78e4f23d5fb3178ac09d /lib/libftpio
parentbf3127c24bb5de8cab749074a2c4004f51bdc0c5 (diff)
downloadFreeBSD-src-fc1487cdb0526da63e7c8dbf92b1bcf3e66d356c.zip
FreeBSD-src-fc1487cdb0526da63e7c8dbf92b1bcf3e66d356c.tar.gz
Add an ftpErrString() function for returning human readable failure
codes. Submitted-By: Archie Cobbs <archie@whistle.com>
Diffstat (limited to 'lib/libftpio')
-rw-r--r--lib/libftpio/Makefile17
-rw-r--r--lib/libftpio/ftp.errors44
-rw-r--r--lib/libftpio/ftpio.39
-rw-r--r--lib/libftpio/ftpio.c13
-rw-r--r--lib/libftpio/ftpio.h11
5 files changed, 88 insertions, 6 deletions
diff --git a/lib/libftpio/Makefile b/lib/libftpio/Makefile
index fc46bf6..d7254d3 100644
--- a/lib/libftpio/Makefile
+++ b/lib/libftpio/Makefile
@@ -1,10 +1,25 @@
LIB= ftpio
CFLAGS+= -I${.CURDIR} -Wall
-SRCS= ftpio.c
+SRCS= ftpio.c ftperr.c
MAN3= ftpio.3
+CLEANFILES+= ftperr.c
beforeinstall:
cd ${.CURDIR}; cmp -s ftpio.h ${DESTDIR}/usr/include/ftpio.h || \
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 ftpio.h ${DESTDIR}/usr/include
+ftperr.c: ftp.errors
+ @echo '#include <stdio.h>' > ${.TARGET}
+ @echo '#include "ftpio.h"' >> ${.TARGET}
+ @echo "struct ftperr ftpErrList[] = {" \ >> ${.TARGET}
+ @cat ${.ALLSRC} \
+ | grep -v ^# \
+ | sort \
+ | while read NUM STRING; do \
+ echo " { $${NUM}, \"$${STRING}\" },"; \
+ done >> ${.TARGET}
+ @echo "};" >> ${.TARGET}
+ @echo -n "int const ftpErrListLength = " >> ${.TARGET}
+ @echo "sizeof(ftpErrList) / sizeof(*ftpErrList);" >> ${.TARGET}
+
.include <bsd.lib.mk>
diff --git a/lib/libftpio/ftp.errors b/lib/libftpio/ftp.errors
new file mode 100644
index 0000000..26cb4f6
--- /dev/null
+++ b/lib/libftpio/ftp.errors
@@ -0,0 +1,44 @@
+# $Id$
+#
+# This list is taken from RFC 959.
+# It probably needs a going over.
+#
+110 Restart marker reply
+120 Service ready in a few minutes
+125 Data connection already open; transfer starting
+150 File status okay; about to open data connection
+200 Command okay
+202 Command not implemented, superfluous at this site
+211 System status, or system help reply
+212 Directory status
+213 File status
+214 Help message
+215 Set system type
+220 Service ready for new user
+221 Service closing control connection
+225 Data connection open; no transfer in progress
+226 Requested file action successful
+227 Entering Passive Mode
+230 User logged in, proceed
+250 Requested file action okay, completed
+257 File/directory created
+331 User name okay, need password
+332 Need account for login
+350 Requested file action pending further information
+421 Service not available, closing control connection
+425 Can't open data connection
+426 Connection closed; transfer aborted
+450 File unavailable (e.g., file busy)
+451 Requested action aborted: local error in processing
+452 Insufficient storage space in system
+500 Syntax error, command unrecognized
+501 Syntax error in parameters or arguments
+502 Command not implemented
+503 Bad sequence of commands
+504 Command not implemented for that parameter
+530 Not logged in
+532 Need account for storing files
+550 File unavailable (e.g., file not found, no access)
+551 Requested action aborted. Page type unknown
+552 Exceeded storage allocation
+553 File name not allowed
diff --git a/lib/libftpio/ftpio.3 b/lib/libftpio/ftpio.3
index df09e3a..8c57dd8 100644
--- a/lib/libftpio/ftpio.3
+++ b/lib/libftpio/ftpio.3
@@ -48,6 +48,8 @@
.Fn ftpChdir "FILE *stream, char *dirname"
.Ft int
.Fn ftpErrno "FILE *stream"
+.Ft const char *
+.Fn ftpErrString "int errno"
.Ft time_t
.Fn ftpGetModtime "FILE *stream, char *file"
.Ft size_t
@@ -95,6 +97,8 @@ On success, zero is returned. On failure, the error code from the server.
.Fn ftpErrno
returns the server failure code for the last operation (useful for seeing
more about what happened if you're familiar with FTP error codes).
+.Fn ftpErrString
+returns a human readable version of the supplied server failure code.
.Pp
.Fn ftpGet
attempts to retreive the file named by the
@@ -187,8 +191,7 @@ all my tests.
.Sh HISTORY
Started life as Poul-Henning Kamp's ftp driver for the system installation
utility, later significantly mutated into a more general form as an
-extension of stdio and given a TCL interface (not enabled by default)
-by Jordan Hubbard. Also incorporates some ideas and extensions from
-Jean-Marc Zucconi.
+extension of stdio by Jordan Hubbard. Also incorporates some ideas and
+extensions from Jean-Marc Zucconi.
.Sh AUTHORS
Jordan Hubbard, Poul-Henning Kamp and Jean-Marc Zucconi
diff --git a/lib/libftpio/ftpio.c b/lib/libftpio/ftpio.c
index c9b18ca..e0555e2 100644
--- a/lib/libftpio/ftpio.c
+++ b/lib/libftpio/ftpio.c
@@ -14,7 +14,7 @@
* Turned inside out. Now returns xfers as new file ids, not as a special
* `state' of FTP_t
*
- * $Id: ftpio.c,v 1.8 1996/07/04 00:55:20 jkh Exp $
+ * $Id: ftpio.c,v 1.9 1996/08/03 11:58:53 jkh Exp $
*
*/
@@ -165,6 +165,17 @@ ftpErrno(FILE *fp)
return ftp->errno;
}
+const char *
+ftpErrString(int errno)
+{
+ int k;
+
+ for (k = 0; k < ftpErrListLength; k++)
+ if (ftpErrList[k].num == errno)
+ return(ftpErrList[k].string);
+ return("Unknown error");
+}
+
size_t
ftpGetSize(FILE *fp, char *name)
{
diff --git a/lib/libftpio/ftpio.h b/lib/libftpio/ftpio.h
index e7a964b..49da730 100644
--- a/lib/libftpio/ftpio.h
+++ b/lib/libftpio/ftpio.h
@@ -20,7 +20,7 @@
* Turned inside out. Now returns xfers as new file ids, not as a special
* `state' of FTP_t
*
- * $Id: ftpio.h,v 1.5 1996/07/04 00:55:21 jkh Exp $
+ * $Id: ftpio.h,v 1.6 1996/08/03 11:58:54 jkh Exp $
*/
/* Internal housekeeping data structure for FTP sessions */
@@ -36,6 +36,14 @@ typedef struct {
int is_verbose;
} *FTP_t;
+/* Structure we use to match FTP error codes with readable strings */
+struct ftperr {
+ const int num;
+ const char *string;
+};
+extern struct ftperr ftpErrList[];
+extern int const ftpErrListLength;
+
/* Exported routines - deal only with FILE* type */
extern FILE *ftpLogin(char *host, char *user, char *passwd, int port, int verbose);
extern int ftpChdir(FILE *fp, char *dir);
@@ -50,5 +58,6 @@ extern void ftpVerbose(FILE *fp, int status);
extern FILE *ftpGetURL(char *url, char *user, char *passwd);
extern FILE *ftpPutURL(char *url, char *user, char *passwd);
extern time_t ftpGetModtime(FILE *fp, char *s);
+extern const char *ftpErrString(int errno);
#endif /* _FTP_H_INCLUDE */
OpenPOWER on IntegriCloud