summaryrefslogtreecommitdiffstats
path: root/lib/libftpio
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1996-11-14 06:59:41 +0000
committerache <ache@FreeBSD.org>1996-11-14 06:59:41 +0000
commit22406d98dcada3e438c6d4b3b707192f7fb71969 (patch)
treefddc91814c20d646f9cb4eb065e29ea8c51cf709 /lib/libftpio
parent922ccfd39574911c8000211ea9fcb454fcc70265 (diff)
downloadFreeBSD-src-22406d98dcada3e438c6d4b3b707192f7fb71969.zip
FreeBSD-src-22406d98dcada3e438c6d4b3b707192f7fb71969.tar.gz
For functions ftpGetURL, ftpPutURL, ftpLogin it was impossible to know
FTP error return code because 1) They return NULL, it means that ftpErrno can't be used because it takes file pointer 2) They don't have FILE-type argument as f.e. ftpGet/ftpPut to use it for ftpErrno instead. For that functions I add yet one int* type argument to store FTP error return code. It is impossible to add some global variable for that reason, because user can have multiply FTP connections opened at the same time. So, interface changed, major number bumped. Userland changes will follows. Minor bugfixes, the code: Forget to close file in few places, when failure occurse Forget to NULL cached host name, multiply free is possible
Diffstat (limited to 'lib/libftpio')
-rw-r--r--lib/libftpio/Makefile2
-rw-r--r--lib/libftpio/ftpio.312
-rw-r--r--lib/libftpio/ftpio.c42
-rw-r--r--lib/libftpio/ftpio.h8
4 files changed, 44 insertions, 20 deletions
diff --git a/lib/libftpio/Makefile b/lib/libftpio/Makefile
index bfb9de2..ce86c16 100644
--- a/lib/libftpio/Makefile
+++ b/lib/libftpio/Makefile
@@ -4,7 +4,7 @@ SRCS= ftpio.c ftperr.c
MAN3= ftpio.3
CLEANFILES+= ftperr.c
-SHLIB_MAJOR= 3
+SHLIB_MAJOR= 4
SHLIB_MINOR= 0
beforeinstall:
diff --git a/lib/libftpio/ftpio.3 b/lib/libftpio/ftpio.3
index 4304c1c..8476ec7 100644
--- a/lib/libftpio/ftpio.3
+++ b/lib/libftpio/ftpio.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $Id$
+.\" $Id: ftpio.3,v 1.11 1996/10/05 22:26:51 wosch Exp $
.\"
.Dd June 17, 1996
.Dt ftpio 3
@@ -44,7 +44,7 @@
.Sh SYNOPSIS
.Fd #include <ftpio.h>
.Ft FILE *
-.Fn ftpLogin "char *host" "char *user" "char *passwd" "int ftp_port" "int verbose"
+.Fn ftpLogin "char *host" "char *user" "char *passwd" "int ftp_port" "int verbose" "int *retcode"
.Ft int
.Fn ftpChdir "FILE *stream, char *dirname"
.Ft int
@@ -68,9 +68,9 @@
.Ft void
.Fn ftpVerbose "FILE *stream, int status"
.Ft FILE *
-.Fn ftpGetURL "char *url, char *user, char *passwd"
+.Fn ftpGetURL "char *url, char *user, char *passwd, int *retcode"
.Ft FILE *
-.Fn ftpPutURL "char *url, char *user, char *passwd"
+.Fn ftpPutURL "char *url, char *user, char *passwd, int *retcode"
.Sh DESCRIPTION
These functions implement a high-level library for managing FTP connections.
@@ -87,8 +87,8 @@ defaults to the standard ftp port of 21) and
fields. If it is successful, a
standard stream descriptor is returned which should be passed to
subsequent FTP operations. On failure, NULL is returned and
-.Fn ftpErrno
-will return the error code returned by the foreign server.
+.Fa retcode
+will have the error code returned by the foreign server.
.Pp
.Fn ftpChdir
attempts to issue a server CD command to the directory named in
diff --git a/lib/libftpio/ftpio.c b/lib/libftpio/ftpio.c
index f9ef0cd..5df25b5 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.16 1996/11/14 05:05:26 ache Exp $
+ * $Id: ftpio.c,v 1.17 1996/11/14 05:22:12 ache Exp $
*
*/
@@ -253,11 +253,13 @@ ftpGet(FILE *fp, char *file, off_t *seekto)
/* Returns a standard FILE pointer type representing an open control connection */
FILE *
-ftpLogin(char *host, char *user, char *passwd, int port, int verbose)
+ftpLogin(char *host, char *user, char *passwd, int port, int verbose, int *retcode)
{
FTP_t n;
FILE *fp;
+ if (retcode)
+ *retcode = 0;
if (networkInit() != SUCCESS)
return NULL;
@@ -267,6 +269,8 @@ ftpLogin(char *host, char *user, char *passwd, int port, int verbose)
fp = funopen(n, ftp_read_method, ftp_write_method, NULL, ftp_close_method); /* BSD 4.4 function! */
fp->_file = n->fd_ctrl;
}
+ if (n && retcode)
+ *retcode = n->errno;
return fp;
}
@@ -299,7 +303,7 @@ ftpPassive(FILE *fp, int st)
}
FILE *
-ftpGetURL(char *url, char *user, char *passwd)
+ftpGetURL(char *url, char *user, char *passwd, int *retcode)
{
char host[255], name[255];
int port;
@@ -307,8 +311,10 @@ ftpGetURL(char *url, char *user, char *passwd)
static FILE *fp = NULL;
static char *prev_host;
+ if (retcode)
+ *retcode = 0;
if (get_url_info(url, host, &port, name) == SUCCESS) {
- if (prev_host) {
+ if (fp && prev_host) {
if (!strcmp(prev_host, host)) {
/* Try to use cached connection */
fp2 = ftpGet(fp, name, NULL);
@@ -316,20 +322,30 @@ ftpGetURL(char *url, char *user, char *passwd)
/* Connection timed out or was no longer valid */
fclose(fp);
free(prev_host);
+ prev_host = NULL;
}
else
return fp2;
}
else {
/* It's a different host now, flush old */
- free(prev_host);
fclose(fp);
+ free(prev_host);
+ prev_host = NULL;
}
}
- fp = ftpLogin(host, user, passwd, port, 0);
+ fp = ftpLogin(host, user, passwd, port, 0, retcode);
if (fp) {
fp2 = ftpGet(fp, name, NULL);
- prev_host = strdup(host);
+ if (!fp2) {
+ /* Connection timed out or was no longer valid */
+ if (retcode)
+ *retcode = ftpErrno(fp);
+ fclose(fp);
+ fp = NULL;
+ }
+ else
+ prev_host = strdup(host);
return fp2;
}
}
@@ -337,21 +353,29 @@ ftpGetURL(char *url, char *user, char *passwd)
}
FILE *
-ftpPutURL(char *url, char *user, char *passwd)
+ftpPutURL(char *url, char *user, char *passwd, int *retcode)
{
char host[255], name[255];
int port;
static FILE *fp = NULL;
FILE *fp2;
+ if (retcode)
+ *retcode = 0;
if (fp) { /* Close previous managed connection */
fclose(fp);
fp = NULL;
}
if (get_url_info(url, host, &port, name) == SUCCESS) {
- fp = ftpLogin(host, user, passwd, port, 0);
+ fp = ftpLogin(host, user, passwd, port, 0, retcode);
if (fp) {
fp2 = ftpPut(fp, name);
+ if (!fp2) {
+ if (retcode)
+ *retcode = ftpErrno(fp);
+ fclose(fp);
+ fp = NULL;
+ }
return fp2;
}
}
diff --git a/lib/libftpio/ftpio.h b/lib/libftpio/ftpio.h
index 7210531..b057c03 100644
--- a/lib/libftpio/ftpio.h
+++ b/lib/libftpio/ftpio.h
@@ -21,7 +21,7 @@
* Turned inside out. Now returns xfers as new file ids, not as a special
* `state' of FTP_t
*
- * $Id: ftpio.h,v 1.8 1996/09/19 17:28:34 peter Exp $
+ * $Id: ftpio.h,v 1.9 1996/11/14 05:22:12 ache Exp $
*/
/* Internal housekeeping data structure for FTP sessions */
@@ -46,7 +46,7 @@ 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 FILE *ftpLogin(char *host, char *user, char *passwd, int port, int verbose, int *retcode);
extern int ftpChdir(FILE *fp, char *dir);
extern int ftpErrno(FILE *fp);
extern off_t ftpGetSize(FILE *fp, char *file);
@@ -56,8 +56,8 @@ extern int ftpAscii(FILE *fp);
extern int ftpBinary(FILE *fp);
extern int ftpPassive(FILE *fp, int status);
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 FILE *ftpGetURL(char *url, char *user, char *passwd, int *retcode);
+extern FILE *ftpPutURL(char *url, char *user, char *passwd, int *retcode);
extern time_t ftpGetModtime(FILE *fp, char *s);
extern const char *ftpErrString(int errno);
OpenPOWER on IntegriCloud