summaryrefslogtreecommitdiff
path: root/src/utilfuns/ftplib.c
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-05-12 08:21:30 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-05-12 08:21:30 -0400
commit7a00574163029c0c2b649878c95d5acbd083564a (patch)
treec13cc5736025834df2874ed87ee8598070025ea6 /src/utilfuns/ftplib.c
parentb745315323de9f27538edac9453205ca70e6186e (diff)
Imported Upstream version 1.7.2+dfsg
Diffstat (limited to 'src/utilfuns/ftplib.c')
-rw-r--r--src/utilfuns/ftplib.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/src/utilfuns/ftplib.c b/src/utilfuns/ftplib.c
index b184a91..a211973 100644
--- a/src/utilfuns/ftplib.c
+++ b/src/utilfuns/ftplib.c
@@ -1,23 +1,23 @@
/***************************************************************************/
-/* ftplib.c - callable ftp access routines */
-/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */
-/* 73 Catherine Street, South Bound Brook, NJ, 08880 */
-/* */
-/* This library is free software; you can redistribute it and/or */
-/* modify it under the terms of the GNU Library General Public */
-/* License as published by the Free Software Foundation; either */
-/* version 2 of the License, or (at your option) any later version. */
-/* */
-/* This library 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 */
-/* Library General Public License for more details. */
-/* */
-/* You should have received a copy of the GNU Library General Public */
-/* License along with this progam; if not, write to the */
-/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
-/* Boston, MA 02111-1307, USA. */
-/* */
+/* ftplib.c - callable ftp access routines */
+/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */
+/* 73 Catherine Street, South Bound Brook, NJ, 08880 */
+/* */
+/* This library is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU Library General Public */
+/* License as published by the Free Software Foundation; either */
+/* version 2 of the License, or (at your option) any later version. */
+/* */
+/* This library 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 */
+/* Library General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU Library General Public */
+/* License along with this progam; if not, write to the */
+/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
+/* Boston, MA 02111-1307, USA. */
+/* */
/***************************************************************************/
// changes made by Lorn Potter <llornkcor@handhelds.org>
//
@@ -126,15 +126,19 @@ struct NetBuf {
int cmode;
struct timeval idletime;
FtpCallback idlecb;
+ FtpCallbackWriter writercb;
void *idlearg;
+ void *writerarg;
int xfered;
int cbbytes;
int xfered1;
char response[256];
};
+#if 0
static char *version =
"ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau";
+#endif
GLOBALDEF int ftplib_debug = 0;
@@ -569,8 +573,10 @@ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl)
ctrl->ctrl = NULL;
ctrl->cmode = FTPLIB_DEFMODE;
ctrl->idlecb = NULL;
+ ctrl->writercb = NULL;
ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
ctrl->idlearg = NULL;
+ ctrl->writerarg = NULL;
ctrl->xfered = 0;
ctrl->xfered1 = 0;
ctrl->cbbytes = 0;
@@ -607,6 +613,10 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
nControl->idlecb = (FtpCallback) val;
rv = 1;
break;
+ case FTPLIB_CALLBACK_WRITER:
+ nControl->writercb = (FtpCallbackWriter) val;
+ rv = 1;
+ break;
case FTPLIB_IDLETIME:
v = (int) val;
rv = 1;
@@ -617,6 +627,10 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
rv = 1;
nControl->idlearg = (void *) val;
break;
+ case FTPLIB_CALLBACK_WRITERARG:
+ rv = 1;
+ nControl->writerarg = (void *) val;
+ break;
case FTPLIB_CALLBACKBYTES:
rv = 1;
nControl->cbbytes = (int) val;
@@ -807,6 +821,7 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
ctrl->dir = dir;
ctrl->idletime = nControl->idletime;
ctrl->idlearg = nControl->idlearg;
+ ctrl->writerarg = nControl->writerarg;
ctrl->xfered = 0;
ctrl->xfered1 = 0;
ctrl->cbbytes = nControl->cbbytes;
@@ -814,6 +829,7 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
ctrl->idlecb = nControl->idlecb;
else
ctrl->idlecb = NULL;
+ ctrl->writercb = nControl->writercb;
*nData = ctrl;
return 1;
}
@@ -1203,6 +1219,7 @@ static int FtpXfer(const char *localfile, const char *path,
FILE *local = NULL;
netbuf *nData;
int rv=1;
+ int writeResult = 0;
if (localfile != NULL)
{
@@ -1237,13 +1254,15 @@ static int FtpXfer(const char *localfile, const char *path,
}
else
{
- while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
- if (fwrite(dbuf, 1, l, local) <= 0)
+ while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) {
+ writeResult = (nData->writercb) ? nData->writercb(nData, dbuf, l, nData->writerarg) : fwrite(dbuf, 1, l, local);
+ if (writeResult <= 0)
{
- perror("localfile write");
+ perror("localstore write");
rv = 0;
break;
}
+ }
}
free(dbuf);
fflush(local);