summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJudd Vinet <judd@archlinux.org>2004-01-04 18:53:32 +0100
committerJudd Vinet <judd@archlinux.org>2004-01-04 18:53:32 +0100
commit6d4c666a8e10cd1f531abc6d34593cf5802adab4 (patch)
tree2c82ba1c0a31aa94ec6736143a8eb90dd7ed75f2
parent68e24b947ea7da1e5e4c2e48109df737e8cda4f0 (diff)
downloadpacman-6d4c666a8e10cd1f531abc6d34593cf5802adab4.tar.gz
pacman-6d4c666a8e10cd1f531abc6d34593cf5802adab4.tar.xz
Imported from pacman-2.7.2.tar.gz
-rw-r--r--ChangeLog3
-rw-r--r--Makefile.in2
-rw-r--r--TODO20
-rw-r--r--libftp/ftplib.c2058
-rwxr-xr-xscripts/gensync2
-rwxr-xr-xscripts/makepkg92
-rwxr-xr-xscripts/makeworld2
-rw-r--r--src/pacman.c37
-rw-r--r--src/pacman.h2
-rw-r--r--src/pacsync.c2
10 files changed, 1115 insertions, 1105 deletions
diff --git a/ChangeLog b/ChangeLog
index c4c6ba85..2758ad6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
VERSION DESCRIPTION
-----------------------------------------------------------------------------
+2.7.2 - Supressed "No such file" messages during stripping
+ - Removed extra newlines in /var/log/pacman.log
+ - Added a --noextract option to makepkg to skip source extraction
2.7.1 - Fixed a couple obscure segfaults
- LogFiles were logging incorrect dates - fixed
- Cleaned up md5sum output in makepkg -g
diff --git a/Makefile.in b/Makefile.in
index 18827932..4f7b0801 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -34,7 +34,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
-PACVER = 2.7.1
+PACVER = 2.7.2
TOPDIR = @srcdir@
SRCDIR = $(TOPDIR)/src/
diff --git a/TODO b/TODO
index 08182cda..022d7f53 100644
--- a/TODO
+++ b/TODO
@@ -1,17 +1,15 @@
+- think about consolidating the -A/-U/-S options into one smart
+ install operation
+- replaces code doesn't run with -U or -A
+- when performing replaces, pacman should not remove old packages until
+ the conflict checks are passed
+- --info should work with --sync to display dependencies
+- add an ETA to the download progress bar
+- add HTTP/1.1 support
- fix the broken pipe bug
- handle version comparators in makepkg dep resolution (eg, glibc>=2.2.5)
- add post_remove, pre_install, pre_upgrade functions to scriptlets
-- record md5sums of all files in a package
+? record md5sums of all files in a package
? use 'set -e' in makepkg?
-x if a package fails, ask before aborting the full operation
- - can't -- further dependent packages may fail b/c of the first failure
- check $PACCONF env var
-? use a 'trust pacman' config option for downgrading?
-? build-time (source) dependencies in makepkg
-? run ldd on every executable in a newly built package to find required so's
- add a --pretend option
-- add a consistency/sanity check operation (md5 tracking for all files)
-- use package caches more for performance
-- clean up output a bit (message queue?)
-- use a files.cache db for --owns and db_find_conflicts
-
diff --git a/libftp/ftplib.c b/libftp/ftplib.c
index 004ede87..74fd6c5e 100644
--- a/libftp/ftplib.c
+++ b/libftp/ftplib.c
@@ -70,25 +70,25 @@
#endif
struct NetBuf {
- char *cput,*cget;
- int handle;
- int cavail,cleft;
- char *buf;
- int dir;
- netbuf *ctrl;
- netbuf *data;
- int cmode;
- struct timeval idletime;
- FtpCallback idlecb;
- void *idlearg;
- int xfered;
- int cbbytes;
- int xfered1;
- char response[256];
+ char *cput,*cget;
+ int handle;
+ int cavail,cleft;
+ char *buf;
+ int dir;
+ netbuf *ctrl;
+ netbuf *data;
+ int cmode;
+ struct timeval idletime;
+ FtpCallback idlecb;
+ void *idlearg;
+ int xfered;
+ int cbbytes;
+ int xfered1;
+ char response[256];
};
static char *version =
- "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau";
+"ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau";
GLOBALDEF int ftplib_debug = 0;
@@ -101,26 +101,26 @@ GLOBALDEF int ftplib_debug = 0;
#define net_write(x,y,z) send(x,y,z,0)
#define net_close closesocket
#endif
-
+
#if defined(NEED_MEMCCPY)
-/*
- * VAX C does not supply a memccpy routine so I provide my own
- */
+ /*
+ * VAX C does not supply a memccpy routine so I provide my own
+ */
void *memccpy(void *dest, const void *src, int c, size_t n)
{
- int i=0;
- const unsigned char *ip=src;
- unsigned char *op=dest;
+ int i=0;
+ const unsigned char *ip=src;
+ unsigned char *op=dest;
- while (i < n)
- {
- if ((*op++ = *ip++) == c)
- break;
- i++;
- }
- if (i == n)
- return NULL;
- return op;
+ while (i < n)
+ {
+ if ((*op++ = *ip++) == c)
+ break;
+ i++;
+ }
+ if (i == n)
+ return NULL;
+ return op;
}
#endif
#if defined(NEED_STRDUP)
@@ -129,11 +129,11 @@ void *memccpy(void *dest, const void *src, int c, size_t n)
*/
char *strdup(const char *src)
{
- int l = strlen(src) + 1;
- char *dst = malloc(l);
- if (dst)
- strcpy(dst,src);
- return dst;
+ int l = strlen(src) + 1;
+ char *dst = malloc(l);
+ if (dst)
+ strcpy(dst,src);
+ return dst;
}
#endif
@@ -145,36 +145,36 @@ char *strdup(const char *src)
*/
static int socket_wait(netbuf *ctl)
{
- fd_set fd,*rfd = NULL,*wfd = NULL;
- struct timeval tv;
- int rv = 0;
- if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL))
- return 1;
- if (ctl->dir == FTPLIB_WRITE)
- wfd = &fd;
- else
- rfd = &fd;
- FD_ZERO(&fd);
- do
- {
- FD_SET(ctl->handle,&fd);
- tv = ctl->idletime;
- rv = select(ctl->handle+1, rfd, wfd, NULL, &tv);
- if (rv == -1)
- {
- rv = 0;
- strncpy(ctl->ctrl->response, strerror(errno),
- sizeof(ctl->ctrl->response));
- break;
- }
- else if (rv > 0)
+ fd_set fd,*rfd = NULL,*wfd = NULL;
+ struct timeval tv;
+ int rv = 0;
+ if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL))
+ return 1;
+ if (ctl->dir == FTPLIB_WRITE)
+ wfd = &fd;
+ else
+ rfd = &fd;
+ FD_ZERO(&fd);
+ do
{
- rv = 1;
- break;
+ FD_SET(ctl->handle,&fd);
+ tv = ctl->idletime;
+ rv = select(ctl->handle+1, rfd, wfd, NULL, &tv);
+ if (rv == -1)
+ {
+ rv = 0;
+ strncpy(ctl->ctrl->response, strerror(errno),
+ sizeof(ctl->ctrl->response));
+ break;
+ }
+ else if (rv > 0)
+ {
+ rv = 1;
+ break;
+ }
}
- }
- while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg)));
- return rv;
+ while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg)));
+ return rv;
}
/*
@@ -184,73 +184,73 @@ static int socket_wait(netbuf *ctl)
*/
static int readline(char *buf,int max,netbuf *ctl)
{
- int x,retval = 0;
- char *end,*bp=buf;
- int eof = 0;
+ int x,retval = 0;
+ char *end,*bp=buf;
+ int eof = 0;
- if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ))
- return -1;
- if (max == 0)
- return 0;
- do
- {
- if (ctl->cavail > 0)
- {
- x = (max >= ctl->cavail) ? ctl->cavail : max-1;
- end = memccpy(bp,ctl->cget,'\n',x);
- if (end != NULL)
- x = end - bp;
- retval += x;
- bp += x;
- *bp = '\0';
- max -= x;
- ctl->cget += x;
- ctl->cavail -= x;
- if (end != NULL)
- {
- bp -= 2;
- if (strcmp(bp,"\r\n") == 0)
+ if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ))
+ return -1;
+ if (max == 0)
+ return 0;
+ do
+ {
+ if (ctl->cavail > 0)
{
- *bp++ = '\n';
- *bp++ = '\0';
- --retval;
+ x = (max >= ctl->cavail) ? ctl->cavail : max-1;
+ end = memccpy(bp,ctl->cget,'\n',x);
+ if (end != NULL)
+ x = end - bp;
+ retval += x;
+ bp += x;
+ *bp = '\0';
+ max -= x;
+ ctl->cget += x;
+ ctl->cavail -= x;
+ if (end != NULL)
+ {
+ bp -= 2;
+ if (strcmp(bp,"\r\n") == 0)
+ {
+ *bp++ = '\n';
+ *bp++ = '\0';
+ --retval;
+ }
+ break;
+ }
}
- break;
- }
- }
- if (max == 1)
- {
- *buf = '\0';
- break;
- }
- if (ctl->cput == ctl->cget)
- {
- ctl->cput = ctl->cget = ctl->buf;
- ctl->cavail = 0;
- ctl->cleft = FTPLIB_BUFSIZ;
- }
- if (eof)
- {
- if (retval == 0)
- retval = -1;
- break;
+ if (max == 1)
+ {
+ *buf = '\0';
+ break;
+ }
+ if (ctl->cput == ctl->cget)
+ {
+ ctl->cput = ctl->cget = ctl->buf;
+ ctl->cavail = 0;
+ ctl->cleft = FTPLIB_BUFSIZ;
+ }
+ if (eof)
+ {
+ if (retval == 0)
+ retval = -1;
+ break;
+ }
+ if (!socket_wait(ctl))
+ return retval;
+ if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1)
+ {
+ perror("read");
+ retval = -1;
+ break;
+ }
+ if (x == 0)
+ eof = 1;
+ ctl->cleft -= x;
+ ctl->cavail += x;
+ ctl->cput += x;
}
- if (!socket_wait(ctl))
- return retval;
- if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1)
- {
- perror("read");
- retval = -1;
- break;
- }
- if (x == 0)
- eof = 1;
- ctl->cleft -= x;
- ctl->cavail += x;
- ctl->cput += x;
- }
- while (1);
- return retval;
+ while (1);
+ return retval;
}
/*
@@ -260,57 +260,57 @@ static int readline(char *buf,int max,netbuf *ctl)
*/
static int writeline(char *buf, int len, netbuf *nData)
{
- int x, nb=0, w;
- char *ubp = buf, *nbp;
- char lc=0;
+ int x, nb=0, w;
+ char *ubp = buf, *nbp;
+ char lc=0;
- if (nData->dir != FTPLIB_WRITE)
- return -1;
- nbp = nData->buf;
- for (x=0; x < len; x++)
- {
- if ((*ubp == '\n') && (lc != '\r'))
+ if (nData->dir != FTPLIB_WRITE)
+ return -1;
+ nbp = nData->buf;
+ for (x=0; x < len; x++)
{
- if (nb == FTPLIB_BUFSIZ)
- {
- if (!socket_wait(nData))
- return x;
- w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
- if (w != FTPLIB_BUFSIZ)
+ if ((*ubp == '\n') && (lc != '\r'))
{
- printf("net_write(1) returned %d, errno = %d\n", w, errno);
- return(-1);
+ if (nb == FTPLIB_BUFSIZ)
+ {
+ if (!socket_wait(nData))
+ return x;
+ w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
+ if (w != FTPLIB_BUFSIZ)
+ {
+ printf("net_write(1) returned %d, errno = %d\n", w, errno);
+ return(-1);
+ }
+ nb = 0;
+ }
+ nbp[nb++] = '\r';
}
- nb = 0;
- }
- nbp[nb++] = '\r';
- }
- if (nb == FTPLIB_BUFSIZ)
- {
- if (!socket_wait(nData))
- return x;
- w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
- if (w != FTPLIB_BUFSIZ)
- {
- printf("net_write(2) returned %d, errno = %d\n", w, errno);
- return(-1);
- }
- nb = 0;
+ if (nb == FTPLIB_BUFSIZ)
+ {
+ if (!socket_wait(nData))
+ return x;
+ w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
+ if (w != FTPLIB_BUFSIZ)
+ {
+ printf("net_write(2) returned %d, errno = %d\n", w, errno);
+ return(-1);
+ }
+ nb = 0;
+ }
+ nbp[nb++] = lc = *ubp++;
}
- nbp[nb++] = lc = *ubp++;
- }
- if (nb)
- {
- if (!socket_wait(nData))
- return x;
- w = net_write(nData->handle, nbp, nb);
- if (w != nb)
+ if (nb)
{
- printf("net_write(3) returned %d, errno = %d\n", w, errno);
- return(-1);
+ if (!socket_wait(nData))
+ return x;
+ w = net_write(nData->handle, nbp, nb);
+ if (w != nb)
+ {
+ printf("net_write(3) returned %d, errno = %d\n", w, errno);
+ return(-1);
+ }
}
- }
- return len;
+ return len;
}
/*
@@ -321,34 +321,34 @@ static int writeline(char *buf, int len, netbuf *nData)
*/
static int readresp(char c, netbuf *nControl)
{
- char match[5];
- if (readline(nControl->response,256,nControl) == -1)
- {
- perror("Control socket read failed");
- return 0;
- }
- if (ftplib_debug > 1)
- fprintf(stderr,"%s",nControl->response);
- if (nControl->response[3] == '-')
- {
- strncpy(match,nControl->response,3);
- match[3] = ' ';
- match[4] = '\0';
- do
+ char match[5];
+ if (readline(nControl->response,256,nControl) == -1)
{
- if (readline(nControl->response,256,nControl) == -1)
- {
perror("Control socket read failed");
return 0;
- }
- if (ftplib_debug > 1)
+ }
+ if (ftplib_debug > 1)
fprintf(stderr,"%s",nControl->response);
+ if (nControl->response[3] == '-')
+ {
+ strncpy(match,nControl->response,3);
+ match[3] = ' ';
+ match[4] = '\0';
+ do
+ {
+ if (readline(nControl->response,256,nControl) == -1)
+ {
+ perror("Control socket read failed");
+ return 0;
+ }
+ if (ftplib_debug > 1)
+ fprintf(stderr,"%s",nControl->response);
+ }
+ while (strncmp(nControl->response,match,4));
}
- while (strncmp(nControl->response,match,4));
- }
- if (nControl->response[0] == c)
- return 1;
- return 0;
+ if (nControl->response[0] == c)
+ return 1;
+ return 0;
}
/*
@@ -357,12 +357,12 @@ static int readresp(char c, netbuf *nControl)
GLOBALDEF void FtpInit(void)
{
#if defined(_WIN32)
- WORD wVersionRequested;
- WSADATA wsadata;
- int err;
- wVersionRequested = MAKEWORD(1,1);
- if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0)
- fprintf(stderr,"Network failed to start: %d\n",err);
+ WORD wVersionRequested;
+ WSADATA wsadata;
+ int err;
+ wVersionRequested = MAKEWORD(1,1);
+ if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0)
+ fprintf(stderr,"Network failed to start: %d\n",err);
#endif
}
@@ -371,9 +371,9 @@ GLOBALDEF void FtpInit(void)
*/
GLOBALDEF char *FtpLastResponse(netbuf *nControl)
{
- if ((nControl) && (nControl->dir == FTPLIB_CONTROL))
- return nControl->response;
- return NULL;
+ if ((nControl) && (nControl->dir == FTPLIB_CONTROL))
+ return nControl->response;
+ return NULL;
}
/*
@@ -383,110 +383,110 @@ GLOBALDEF char *FtpLastResponse(netbuf *nControl)
*/
GLOBALDEF int FtpConnect(const char *host, netbuf **nControl)
{
- int sControl;
- struct sockaddr_in sin;
- struct hostent *phe;
- struct servent *pse;
- int on=1;
- netbuf *ctrl;
- char *lhost;
- char *pnum;
+ int sControl;
+ struct sockaddr_in sin;
+ struct hostent *phe;
+ struct servent *pse;
+ int on=1;
+ netbuf *ctrl;
+ char *lhost;
+ char *pnum;
- memset(&sin,0,sizeof(sin));
- sin.sin_family = AF_INET;
- lhost = strdup(host);
- pnum = strchr(lhost,':');
- if (pnum == NULL)
- {
+ memset(&sin,0,sizeof(sin));
+ sin.sin_family = AF_INET;
+ lhost = strdup(host);
+ pnum = strchr(lhost,':');
+ if (pnum == NULL)
+ {
#if defined(VMS)
- sin.sin_port = htons(21);
+ sin.sin_port = htons(21);
#else
- if ((pse = getservbyname("ftp","tcp")) == NULL)
- {
- perror("getservbyname");
- return 0;
- }
- sin.sin_port = pse->s_port;
+ if ((pse = getservbyname("ftp","tcp")) == NULL)
+ {
+ perror("getservbyname");
+ return 0;
+ }
+ sin.sin_port = pse->s_port;
#endif
- }
- else
- {
- *pnum++ = '\0';
- if (isdigit(*pnum))
- sin.sin_port = htons(atoi(pnum));
- else
- {
- pse = getservbyname(pnum,"tcp");
- if(pse == NULL) {
- perror("getservbyname");
- return 0;
- }
- sin.sin_port = pse->s_port;
+ }
+ else
+ {
+ *pnum++ = '\0';
+ if (isdigit(*pnum))
+ sin.sin_port = htons(atoi(pnum));
+ else
+ {
+ pse = getservbyname(pnum,"tcp");
+ if(pse == NULL) {
+ perror("getservbyname");
+ return 0;
}
- }
- if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
- {
- if ((phe = gethostbyname(lhost)) == NULL)
- {
- perror("gethostbyname");
- return 0;
- }
- memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
- }
- free(lhost);
- sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sControl == -1)
- {
- perror("socket");
- return 0;
- }
- if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
- SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
- {
- perror("setsockopt");
- net_close(sControl);
- return 0;
- }
- if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1)
- {
- perror("connect");
- net_close(sControl);
- return 0;
- }
- ctrl = calloc(1,sizeof(netbuf));
- if (ctrl == NULL)
- {
- perror("calloc");
- net_close(sControl);
- return 0;
- }
- ctrl->buf = malloc(FTPLIB_BUFSIZ);
- if (ctrl->buf == NULL)
- {
- perror("calloc");
- net_close(sControl);
- free(ctrl);
- return 0;
- }
- ctrl->handle = sControl;
- ctrl->dir = FTPLIB_CONTROL;
- ctrl->ctrl = NULL;
- ctrl->cmode = FTPLIB_DEFMODE;
- ctrl->idlecb = NULL;
- ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
- ctrl->idlearg = NULL;
- ctrl->xfered = 0;
- ctrl->xfered1 = 0;
- ctrl->cbbytes = 0;
- if (readresp('2', ctrl) == 0)
- {
- net_close(sControl);
- free(ctrl->buf);
- free(ctrl);
- return 0;
- }
- *nControl = ctrl;
- return 1;
+ sin.sin_port = pse->s_port;
+ }
+ }
+ if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
+ {
+ if ((phe = gethostbyname(lhost)) == NULL)
+ {
+ perror("gethostbyname");
+ return 0;
+ }
+ memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
+ }
+ free(lhost);
+ sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (sControl == -1)
+ {
+ perror("socket");
+ return 0;
+ }
+ if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
+ SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
+ {
+ perror("setsockopt");
+ net_close(sControl);
+ return 0;
+ }
+ if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+ {
+ perror("connect");
+ net_close(sControl);
+ return 0;
+ }
+ ctrl = calloc(1,sizeof(netbuf));
+ if (ctrl == NULL)
+ {
+ perror("calloc");
+ net_close(sControl);
+ return 0;
+ }
+ ctrl->buf = malloc(FTPLIB_BUFSIZ);
+ if (ctrl->buf == NULL)
+ {
+ perror("calloc");
+ net_close(sControl);
+ free(ctrl);
+ return 0;
+ }
+ ctrl->handle = sControl;
+ ctrl->dir = FTPLIB_CONTROL;
+ ctrl->ctrl = NULL;
+ ctrl->cmode = FTPLIB_DEFMODE;
+ ctrl->idlecb = NULL;
+ ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
+ ctrl->idlearg = NULL;
+ ctrl->xfered = 0;
+ ctrl->xfered1 = 0;
+ ctrl->cbbytes = 0;
+ if (readresp('2', ctrl) == 0)
+ {
+ net_close(sControl);
+ free(ctrl->buf);
+ free(ctrl);
+ return 0;
+ }
+ *nControl = ctrl;
+ return 1;
}
/*
@@ -496,37 +496,37 @@ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl)
*/
GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
{
- int v,rv=0;
- switch (opt)
- {
- case FTPLIB_CONNMODE:
- v = (int) val;
- if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT))
+ int v,rv=0;
+ switch (opt)
{
- nControl->cmode = v;
- rv = 1;
+ case FTPLIB_CONNMODE:
+ v = (int) val;
+ if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT))
+ {
+ nControl->cmode = v;
+ rv = 1;
+ }
+ break;
+ case FTPLIB_CALLBACK:
+ nControl->idlecb = (FtpCallback) val;
+ rv = 1;
+ break;
+ case FTPLIB_IDLETIME:
+ v = (int) val;
+ rv = 1;
+ nControl->idletime.tv_sec = v / 1000;
+ nControl->idletime.tv_usec = (v % 1000) * 1000;
+ break;
+ case FTPLIB_CALLBACKARG:
+ rv = 1;
+ nControl->idlearg = (void *) val;
+ break;
+ case FTPLIB_CALLBACKBYTES:
+ rv = 1;
+ nControl->cbbytes = (int) val;
+ break;
}
- break;
- case FTPLIB_CALLBACK:
- nControl->idlecb = (FtpCallback) val;
- rv = 1;
- break;
- case FTPLIB_IDLETIME:
- v = (int) val;
- rv = 1;
- nControl->idletime.tv_sec = v / 1000;
- nControl->idletime.tv_usec = (v % 1000) * 1000;
- break;
- case FTPLIB_CALLBACKARG:
- rv = 1;
- nControl->idlearg = (void *) val;
- break;
- case FTPLIB_CALLBACKBYTES:
- rv = 1;
- nControl->cbbytes = (int) val;
- break;
- }
- return rv;
+ return rv;
}
/*
@@ -536,20 +536,20 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
*/
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
{
- char buf[256];
- if (nControl->dir != FTPLIB_CONTROL)
- return 0;
- if (ftplib_debug > 2)
- fprintf(stderr,"%s\n",cmd);
- if ((strlen(cmd) + 3) > sizeof(buf))
- return 0;
- sprintf(buf,"%s\r\n",cmd);
- if (net_write(nControl->handle,buf,strlen(buf)) <= 0)
- {
- perror("write");
- return 0;
- }
- return readresp(expresp, nControl);
+ char buf[256];
+ if (nControl->dir != FTPLIB_CONTROL)
+ return 0;
+ if (ftplib_debug > 2)
+ fprintf(stderr,"%s\n",cmd);
+ if ((strlen(cmd) + 3) > sizeof(buf))
+ return 0;
+ sprintf(buf,"%s\r\n",cmd);
+ if (net_write(nControl->handle,buf,strlen(buf)) <= 0)
+ {
+ perror("write");
+ return 0;
+ }
+ return readresp(expresp, nControl);
}
/*
@@ -559,20 +559,20 @@ static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
*/
GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl)
{
- char tempbuf[64];
+ char tempbuf[64];
- if (((strlen(user) + 7) > sizeof(tempbuf)) ||
- ((strlen(pass) + 7) > sizeof(tempbuf)))
- return 0;
- sprintf(tempbuf,"USER %s",user);
- if (!FtpSendCmd(tempbuf,'3',nControl))
- {
- if (nControl->response[0] == '2')
- return 1;
- return 0;
- }
- sprintf(tempbuf,"PASS %s",pass);
- return FtpSendCmd(tempbuf,'2',nControl);
+ if (((strlen(user) + 7) > sizeof(tempbuf)) ||
+ ((strlen(pass) + 7) > sizeof(tempbuf)))
+ return 0;
+ sprintf(tempbuf,"USER %s",user);
+ if (!FtpSendCmd(tempbuf,'3',nControl))
+ {
+ if (nControl->response[0] == '2')
+ return 1;
+ return 0;
+ }
+ sprintf(tempbuf,"PASS %s",pass);
+ return FtpSendCmd(tempbuf,'2',nControl);
}
/*
@@ -582,144 +582,144 @@ GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl)
*/
static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
{
- int sData;
- union {
- struct sockaddr sa;
- struct sockaddr_in in;
- } sin;
- struct linger lng = { 0, 0 };
- unsigned int l;
- int on=1;
- netbuf *ctrl;
- char *cp;
- unsigned int v[6];
- char buf[256];
+ int sData;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } sin;
+ struct linger lng = { 0, 0 };
+ unsigned int l;
+ int on=1;
+ netbuf *ctrl;
+ char *cp;
+ unsigned int v[6];
+ char buf[256];
- if (nControl->dir != FTPLIB_CONTROL)
- return -1;
- if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE))
- {
- sprintf(nControl->response, "Invalid direction %d\n", dir);
- return -1;
- }
- if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE))
- {
- sprintf(nControl->response, "Invalid mode %c\n", mode);
- return -1;
- }
- l = sizeof(sin);
- if (nControl->cmode == FTPLIB_PASSIVE)
- {
- memset(&sin, 0, l);
- sin.in.sin_family = AF_INET;
- if (!FtpSendCmd("PASV",'2',nControl))
- return -1;
- cp = strchr(nControl->response,'(');
- if (cp == NULL)
- return -1;
- cp++;
- sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]);
- sin.sa.sa_data[2] = v[2];
- sin.sa.sa_data[3] = v[3];
- sin.sa.sa_data[4] = v[4];
- sin.sa.sa_data[5] = v[5];
- sin.sa.sa_data[0] = v[0];
- sin.sa.sa_data[1] = v[1];
- }
- else
- {
- if (getsockname(nControl->handle, &sin.sa, &l) < 0)
+ if (nControl->dir != FTPLIB_CONTROL)
+ return -1;
+ if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE))
+ {
+ sprintf(nControl->response, "Invalid direction %d\n", dir);
+ return -1;
+ }
+ if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE))
{
- perror("getsockname");
- return 0;
+ sprintf(nControl->response, "Invalid mode %c\n", mode);
+ return -1;
}
- }
- sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
- if (sData == -1)
- {
- perror("socket");
- return -1;
- }
- if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR,
- SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1)
- {
- perror("setsockopt");
- net_close(sData);
- return -1;
- }
- if (setsockopt(sData,SOL_SOCKET,SO_LINGER,
- SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1)
- {
- perror("setsockopt");
- net_close(sData);
- return -1;
- }
- if (nControl->cmode == FTPLIB_PASSIVE)
- {
- if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1)
+ l = sizeof(sin);
+ if (nControl->cmode == FTPLIB_PASSIVE)
{
- perror("connect");
- net_close(sData);
- return -1;
+ memset(&sin, 0, l);
+ sin.in.sin_family = AF_INET;
+ if (!FtpSendCmd("PASV",'2',nControl))
+ return -1;
+ cp = strchr(nControl->response,'(');
+ if (cp == NULL)
+ return -1;
+ cp++;
+ sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]);
+ sin.sa.sa_data[2] = v[2];
+ sin.sa.sa_data[3] = v[3];
+ sin.sa.sa_data[4] = v[4];
+ sin.sa.sa_data[5] = v[5];
+ sin.sa.sa_data[0] = v[0];
+ sin.sa.sa_data[1] = v[1];
}
- }
- else
- {
- sin.in.sin_port = 0;
- if (bind(sData, &sin.sa, sizeof(sin)) == -1)
+ else
{
- perror("bind");
- net_close(sData);
- return 0;
+ if (getsockname(nControl->handle, &sin.sa, &l) < 0)
+ {
+ perror("getsockname");
+ return 0;
+ }
}
- if (listen(sData, 1) < 0)
+ sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
+ if (sData == -1)
{
- perror("listen");
- net_close(sData);
- return 0;
+ perror("socket");
+ return -1;
}
- if (getsockname(sData, &sin.sa, &l) < 0)
- return 0;
- sprintf(buf, "PORT %d,%d,%d,%d,%d,%d",
- (unsigned char) sin.sa.sa_data[2],
- (unsigned char) sin.sa.sa_data[3],
- (unsigned char) sin.sa.sa_data[4],
- (unsigned char) sin.sa.sa_data[5],
- (unsigned char) sin.sa.sa_data[0],
- (unsigned char) sin.sa.sa_data[1]);
- if (!FtpSendCmd(buf,'2',nControl))
+ if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR,
+ SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1)
{
- net_close(sData);
- return 0;
+ perror("setsockopt");
+ net_close(sData);
+ return -1;
}
- }
- ctrl = calloc(1,sizeof(netbuf));
- if (ctrl == NULL)
- {
- perror("calloc");
- net_close(sData);
- return -1;
- }
- if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL))
- {
- perror("calloc");
- net_close(sData);
- free(ctrl);
- return -1;
- }
- ctrl->handle = sData;
- ctrl->dir = dir;
- ctrl->idletime = nControl->idletime;
- ctrl->idlearg = nControl->idlearg;
- ctrl->xfered = 0;
- ctrl->xfered1 = 0;
- ctrl->cbbytes = nControl->cbbytes;
- if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes)
- ctrl->idlecb = nControl->idlecb;
- else
- ctrl->idlecb = NULL;
- *nData = ctrl;
- return 1;
+ if (setsockopt(sData,SOL_SOCKET,SO_LINGER,
+ SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1)
+ {
+ perror("setsockopt");
+ net_close(sData);
+ return -1;
+ }
+ if (nControl->cmode == FTPLIB_PASSIVE)
+ {
+ if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1)
+ {
+ perror("connect");
+ net_close(sData);
+ return -1;
+ }
+ }
+ else
+ {
+ sin.in.sin_port = 0;
+ if (bind(sData, &sin.sa, sizeof(sin)) == -1)
+ {
+ perror("bind");
+ net_close(sData);
+ return 0;
+ }
+ if (listen(sData, 1) < 0)
+ {
+ perror("listen");
+ net_close(sData);
+ return 0;
+ }
+ if (getsockname(sData, &sin.sa, &l) < 0)
+ return 0;
+ sprintf(buf, "PORT %d,%d,%d,%d,%d,%d",
+ (unsigned char) sin.sa.sa_data[2],
+ (unsigned char) sin.sa.sa_data[3],
+ (unsigned char) sin.sa.sa_data[4],
+ (unsigned char) sin.sa.sa_data[5],
+ (unsigned char) sin.sa.sa_data[0],
+ (unsigned char) sin.sa.sa_data[1]);
+ if (!FtpSendCmd(buf,'2',nControl))
+ {
+ net_close(sData);
+ return 0;
+ }
+ }
+ ctrl = calloc(1,sizeof(netbuf));
+ if (ctrl == NULL)
+ {
+ perror("calloc");
+ net_close(sData);
+ return -1;
+ }
+ if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL))
+ {
+ perror("calloc");
+ net_close(sData);
+ free(ctrl);
+ return -1;
+ }
+ ctrl->handle = sData;
+ ctrl->dir = dir;
+ ctrl->idletime = nControl->idletime;
+ ctrl->idlearg = nControl->idlearg;
+ ctrl->xfered = 0;
+ ctrl->xfered1 = 0;
+ ctrl->cbbytes = nControl->cbbytes;
+ if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes)
+ ctrl->idlecb = nControl->idlecb;
+ else
+ ctrl->idlecb = NULL;
+ *nData = ctrl;
+ return 1;
}
/*
@@ -729,68 +729,68 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
*/
static int FtpAcceptConnection(netbuf *nData, netbuf *nControl)
{
- int sData;
- struct sockaddr addr;
- unsigned int l;
- int i;
- struct timeval tv;
- fd_set mask;
- int rv;
+ int sData;
+ struct sockaddr addr;
+ unsigned int l;
+ int i;
+ struct timeval tv;
+ fd_set mask;
+ int rv;
- FD_ZERO(&mask);
- FD_SET(nControl->handle, &mask);
- FD_SET(nData->handle, &mask);
- tv.tv_usec = 0;
- tv.tv_sec = ACCEPT_TIMEOUT;
- i = nControl->handle;
- if (i < nData->handle)
- i = nData->handle;
- i = select(i+1, &mask, NULL, NULL, &tv);
- if (i == -1)
- {
- strncpy(nControl->response, strerror(errno),
- sizeof(nControl->response));
- net_close(nData->handle);
- nData->handle = 0;
- rv = 0;
- }
- else if (i == 0)
- {
- strcpy(nControl->response, "timed out waiting for connection");
- net_close(nData->handle);
- nData->handle = 0;
- rv = 0;
- }
- else
- {
- if (FD_ISSET(nData->handle, &mask))
+ FD_ZERO(&mask);
+ FD_SET(nControl->handle, &mask);
+ FD_SET(nData->handle, &mask);
+ tv.tv_usec = 0;
+ tv.tv_sec = ACCEPT_TIMEOUT;
+ i = nControl->handle;
+ if (i < nData->handle)
+ i = nData->handle;
+ i = select(i+1, &mask, NULL, NULL, &tv);
+ if (i == -1)
{
- l = sizeof(addr);
- sData = accept(nData->handle, &addr, &l);
- i = errno;
- net_close(nData->handle);
- if (sData > 0)
- {
- rv = 1;
- nData->handle = sData;
- }
- else
- {
- strncpy(nControl->response, strerror(i),
- sizeof(nControl->response));
+ strncpy(nControl->response, strerror(errno),
+ sizeof(nControl->response));
+ net_close(nData->handle);
nData->handle = 0;
rv = 0;
- }
}
- else if (FD_ISSET(nControl->handle, &mask))
+ else if (i == 0)
{
- net_close(nData->handle);
- nData->handle = 0;
- readresp('2', nControl);
- rv = 0;
+ strcpy(nControl->response, "timed out waiting for connection");
+ net_close(nData->handle);
+ nData->handle = 0;
+ rv = 0;
}
- }
- return rv;
+ else
+ {
+ if (FD_ISSET(nData->handle, &mask))
+ {
+ l = sizeof(addr);
+ sData = accept(nData->handle, &addr, &l);
+ i = errno;
+ net_close(nData->handle);
+ if (sData > 0)
+ {
+ rv = 1;
+ nData->handle = sData;
+ }
+ else
+ {
+ strncpy(nControl->response, strerror(i),
+ sizeof(nControl->response));
+ nData->handle = 0;
+ rv = 0;
+ }
+ }
+ else if (FD_ISSET(nControl->handle, &mask))
+ {
+ net_close(nData->handle);
+ nData->handle = 0;
+ readresp('2', nControl);
+ rv = 0;
+ }
+ }
+ return rv;
}
/*
@@ -799,71 +799,71 @@ static int FtpAcceptConnection(netbuf *nData, netbuf *nControl)
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
- netbuf **nData)
+ netbuf **nData)
{
- char buf[256];
- int dir;
- if ((path == NULL) &&
- ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ)))
- {
- sprintf(nControl->response,
- "Missing path argument for file transfer\n");
- return 0;
- }
- sprintf(buf, "TYPE %c", mode);
- if (!FtpSendCmd(buf, '2', nControl))
- return 0;
- switch (typ)
- {
- case FTPLIB_DIR:
- strcpy(buf,"NLST");
- dir = FTPLIB_READ;
- break;
- case FTPLIB_DIR_VERBOSE:
- strcpy(buf,"LIST");
- dir = FTPLIB_READ;
- break;
- case FTPLIB_FILE_READ:
- strcpy(buf,"RETR");
- dir = FTPLIB_READ;
- break;
- case FTPLIB_FILE_WRITE:
- strcpy(buf,"STOR");
- dir = FTPLIB_WRITE;
- break;
- default:
- sprintf(nControl->response, "Invalid open type %d\n", typ);
- return 0;
- }
- if (path != NULL)
- {
- int i = strlen(buf);
- buf[i++] = ' ';
- if ((strlen(path) + i) >= sizeof(buf))
- return 0;
- strcpy(&buf[i],path);
- }
- if (FtpOpenPort(nControl, nData, mode, dir) == -1)
- return 0;
- if (!FtpSendCmd(buf, '1', nControl))
- {
- FtpClose(*nData);
- *nData = NULL;
- return 0;
- }
- (*nData)->ctrl = nControl;
- nControl->data = *nData;
- if (nControl->cmode == FTPLIB_PORT)
- {
- if (!FtpAcceptConnection(*nData,nControl))
+ char buf[256];
+ int dir;
+ if ((path == NULL) &&
+ ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ)))
+ {
+ sprintf(nControl->response,
+ "Missing path argument for file transfer\n");
+ return 0;
+ }
+ sprintf(buf, "TYPE %c", mode);
+ if (!FtpSendCmd(buf, '2', nControl))
+ return 0;
+ switch (typ)
+ {
+ case FTPLIB_DIR:
+ strcpy(buf,"NLST");
+ dir = FTPLIB_READ;
+ break;
+ case FTPLIB_DIR_VERBOSE:
+ strcpy(buf,"LIST");
+ dir = FTPLIB_READ;
+ break;
+ case FTPLIB_FILE_READ:
+ strcpy(buf,"RETR");
+ dir = FTPLIB_READ;
+ break;
+ case FTPLIB_FILE_WRITE:
+ strcpy(buf,"STOR");
+ dir = FTPLIB_WRITE;
+ break;
+ default:
+ sprintf(nControl->response, "Invalid open type %d\n", typ);
+ return 0;
+ }
+ if (path != NULL)
{
- FtpClose(*nData);
- *nData = NULL;
- nControl->data = NULL;
- return 0;
+ int i = strlen(buf);
+ buf[i++] = ' ';
+ if ((strlen(path) + i) >= sizeof(buf))
+ return 0;
+ strcpy(&buf[i],path);
}
- }
- return 1;
+ if (FtpOpenPort(nControl, nData, mode, dir) == -1)
+ return 0;
+ if (!FtpSendCmd(buf, '1', nControl))
+ {
+ FtpClose(*nData);
+ *nData = NULL;
+ return 0;
+ }
+ (*nData)->ctrl = nControl;
+ nControl->data = *nData;
+ if (nControl->cmode == FTPLIB_PORT)
+ {
+ if (!FtpAcceptConnection(*nData,nControl))
+ {
+ FtpClose(*nData);
+ *nData = NULL;
+ nControl->data = NULL;
+ return 0;
+ }
+ }
+ return 1;
}
/*
@@ -871,32 +871,32 @@ GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
*/
GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData)
{
- int i;
- if (nData->dir != FTPLIB_READ)
- return 0;
- if (nData->buf)
- i = readline(buf, max, nData);
- else
- {
- i = socket_wait(nData);
- if (i != 1)
- return 0;
- i = net_read(nData->handle, buf, max);
- }
- if (i == -1)
- return 0;
- nData->xfered += i;
- if (nData->idlecb && nData->cbbytes)
- {
- nData->xfered1 += i;
- if (nData->xfered1 > nData->cbbytes)
- {
- if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0)
+ int i;
+ if (nData->dir != FTPLIB_READ)
return 0;
- nData->xfered1 = 0;
- }
- }
- return i;
+ if (nData->buf)
+ i = readline(buf, max, nData);
+ else
+ {
+ i = socket_wait(nData);
+ if (i != 1)
+ return 0;
+ i = net_read(nData->handle, buf, max);
+ }
+ if (i == -1)
+ return 0;
+ nData->xfered += i;
+ if (nData->idlecb && nData->cbbytes)
+ {
+ nData->xfered1 += i;
+ if (nData->xfered1 > nData->cbbytes)
+ {
+ if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0)
+ return 0;
+ nData->xfered1 = 0;
+ }
+ }
+ return i;
}
/*
@@ -904,29 +904,29 @@ GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData)
*/
GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData)
{
- int i;
- if (nData->dir != FTPLIB_WRITE)
- return 0;
- if (nData->buf)
- i = writeline(buf, len, nData);
- else
- {
- socket_wait(nData);
- i = net_write(nData->handle, buf, len);
- }
- if (i == -1)
- return 0;
- nData->xfered += i;
- if (nData->idlecb && nData->cbbytes)
- {
- nData->xfered1 += i;
- if (nData->xfered1 > nData->cbbytes)
- {
- nData->idlecb(nData, nData->xfered, nData->idlearg);
- nData->xfered1 = 0;
- }
- }
- return i;
+ int i;
+ if (nData->dir != FTPLIB_WRITE)
+ return 0;
+ if (nData->buf)
+ i = writeline(buf, len, nData);
+ else
+ {
+ socket_wait(nData);
+ i = net_write(nData->handle, buf, len);
+ }
+ if (i == -1)
+ return 0;
+ nData->xfered += i;
+ if (nData->idlecb && nData->cbbytes)
+ {
+ nData->xfered1 += i;
+ if (nData->xfered1 > nData->cbbytes)
+ {
+ nData->idlecb(nData, nData->xfered, nData->idlearg);
+ nData->xfered1 = 0;
+ }
+ }
+ return i;
}
/*
@@ -934,37 +934,37 @@ GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData)
*/
GLOBALDEF int FtpClose(netbuf *nData)
{
- netbuf *ctrl;
- switch (nData->dir)
- {
- case FTPLIB_WRITE:
- /* potential problem - if buffer flush fails, how to notify user? */
- if (nData->buf != NULL)
- writeline(NULL, 0, nData);
- case FTPLIB_READ:
- if (nData->buf)
- free(nData->buf);
- shutdown(nData->handle,2);
- net_close(nData->handle);
- ctrl = nData->ctrl;
- free(nData);
- if (ctrl)
+ netbuf *ctrl;
+ switch (nData->dir)
{
- ctrl->data = NULL;
- return(readresp('2', ctrl));
+ case FTPLIB_WRITE:
+ /* potential problem - if buffer flush fails, how to notify user? */
+ if (nData->buf != NULL)
+ writeline(NULL, 0, nData);
+ case FTPLIB_READ:
+ if (nData->buf)
+ free(nData->buf);
+ shutdown(nData->handle,2);
+ net_close(nData->handle);
+ ctrl = nData->ctrl;
+ free(nData);
+ if (ctrl)
+ {
+ ctrl->data = NULL;
+ return(readresp('2', ctrl));
+ }
+ return 1;
+ case FTPLIB_CONTROL:
+ if (nData->data)
+ {
+ nData->ctrl = NULL;
+ FtpClose(nData);
+ }
+ net_close(nData->handle);
+ free(nData);
+ return 0;
}
return 1;
- case FTPLIB_CONTROL:
- if (nData->data)
- {
- nData->ctrl = NULL;
- FtpClose(nData);
- }
- net_close(nData->handle);
- free(nData);
- return 0;
- }
- return 1;
}
/*
@@ -974,14 +974,14 @@ GLOBALDEF int FtpClose(netbuf *nData)
*/
GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl)
{
- char buf[256];
-
- if ((strlen(cmd) + 7) > sizeof(buf))
- return 0;
- sprintf(buf,"SITE %s",cmd);
- if (!FtpSendCmd(buf,'2',nControl))
- return 0;
- return 1;
+ char buf[256];
+
+ if ((strlen(cmd) + 7) > sizeof(buf))
+ return 0;
+ sprintf(buf,"SITE %s",cmd);
+ if (!FtpSendCmd(buf,'2',nControl))
+ return 0;
+ return 1;
}
/*
@@ -995,16 +995,16 @@ GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl)
*/
GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl)
{
- int l = max;
- char *b = buf;
- char *s;
- if (!FtpSendCmd("SYST",'2',nControl))
- return 0;
- s = &nControl->response[4];
- while ((--l) && (*s != ' '))
- *b++ = *s++;
- *b++ = '\0';
- return 1;
+ int l = max;
+ char *b = buf;
+ char *s;
+ if (!FtpSendCmd("SYST",'2',nControl))
+ return 0;
+ s = &nControl->response[4];
+ while ((--l) && (*s != ' '))
+ *b++ = *s++;
+ *b++ = '\0';
+ return 1;
}
/*
@@ -1014,14 +1014,14 @@ GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl)
*/
GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl)
{
- char buf[256];
+ char buf[256];
- if ((strlen(path) + 6) > sizeof(buf))
- return 0;
- sprintf(buf,"MKD %s",path);
- if (!FtpSendCmd(buf,'2', nControl))
- return 0;
- return 1;
+ if ((strlen(path) + 6) > sizeof(buf))
+ return 0;
+ sprintf(buf,"MKD %s",path);
+ if (!FtpSendCmd(buf,'2', nControl))
+ return 0;
+ return 1;
}
/*
@@ -1031,14 +1031,14 @@ GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl)
*/
GLOBALDEF int FtpChdir(const char *path, netbuf *nControl)
{
- char buf[256];
+ char buf[256];
- if ((strlen(path) + 6) > sizeof(buf))
- return 0;
- sprintf(buf,"CWD %s",path);
- if (!FtpSendCmd(buf,'2',nControl))
- return 0;
- return 1;
+ if ((strlen(path) + 6) > sizeof(buf))
+ return 0;
+ sprintf(buf,"CWD %s",path);
+ if (!FtpSendCmd(buf,'2',nControl))
+ return 0;
+ return 1;
}
/*
@@ -1048,9 +1048,9 @@ GLOBALDEF int FtpChdir(const char *path, netbuf *nControl)
*/
GLOBALDEF int FtpCDUp(netbuf *nControl)
{
- if (!FtpSendCmd("CDUP",'2',nControl))
- return 0;
- return 1;
+ if (!FtpSendCmd("CDUP",'2',nControl))
+ return 0;
+ return 1;
}
/*
@@ -1060,14 +1060,14 @@ GLOBALDEF int FtpCDUp(netbuf *nControl)
*/
GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl)
{
- char buf[256];
+ char buf[256];
- if ((strlen(path) + 6) > sizeof(buf))
- return 0;
- sprintf(buf,"RMD %s",path);
- if (!FtpSendCmd(buf,'2',nControl))
- return 0;
- return 1;
+ if ((strlen(path) + 6) > sizeof(buf))
+ return 0;
+ sprintf(buf,"RMD %s",path);
+ if (!FtpSendCmd(buf,'2',nControl))
+ return 0;
+ return 1;
}
/*
@@ -1077,19 +1077,19 @@ GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl)
*/
GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl)
{
- int l = max;
- char *b = path;
- char *s;
- if (!FtpSendCmd("PWD",'2',nControl))
- return 0;
- s = strchr(nControl->response, '"');
- if (s == NULL)
- return 0;
- s++;
- while ((--l) && (*s) && (*s != '"'))
- *b++ = *s++;
- *b++ = '\0';
- return 1;
+ int l = max;
+ char *b = path;
+ char *s;
+ if (!FtpSendCmd("PWD",'2',nControl))
+ return 0;
+ s = strchr(nControl->response, '"');
+ if (s == NULL)
+ return 0;
+ s++;
+ while ((--l) && (*s) && (*s != '"'))
+ *b++ = *s++;
+ *b++ = '\0';
+ return 1;
}
/*
@@ -1098,60 +1098,60 @@ GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl)
* return 1 if successful, 0 otherwise
*/
static int FtpXfer(const char *localfile, const char *path,
- netbuf *nControl, int typ, int mode)
+ netbuf *nControl, int typ, int mode)
{
- int l,c;
- char *dbuf;
- FILE *local = NULL;
- netbuf *nData;
- int rv=1;
+ int l,c;
+ char *dbuf;
+ FILE *local = NULL;
+ netbuf *nData;
+ int rv=1;
- if (localfile != NULL)
- {
- char ac[4] = "a";
- if (typ == FTPLIB_FILE_WRITE)
- ac[0] = 'r';
- if (mode == FTPLIB_IMAGE)
- ac[1] = 'b';
- local = fopen(localfile, ac);
+ if (localfile != NULL)
+ {
+ char ac[4] = "a";
+ if (typ == FTPLIB_FILE_WRITE)
+ ac[0] = 'r';
+ if (mode == FTPLIB_IMAGE)
+ ac[1] = 'b';
+ local = fopen(localfile, ac);
+ if (local == NULL)
+ {
+ strncpy(nControl->response, strerror(errno),
+ sizeof(nControl->response));
+ return 0;
+ }
+ }
if (local == NULL)
+ local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
+ if (!FtpAccess(path, typ, mode, nControl, &nData))
+ return 0;
+ dbuf = malloc(FTPLIB_BUFSIZ);
+ if (typ == FTPLIB_FILE_WRITE)
{
- strncpy(nControl->response, strerror(errno),
- sizeof(nControl->response));
- return 0;
+ while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
+ if ((c = FtpWrite(dbuf, l, nData)) < l)
+ {
+ printf("short write: passed %d, wrote %d\n", l, c);
+ rv = 0;
+ break;
+ }
}
- }
- if (local == NULL)
- local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
- if (!FtpAccess(path, typ, mode, nControl, &nData))
- return 0;
- dbuf = malloc(FTPLIB_BUFSIZ);
- if (typ == FTPLIB_FILE_WRITE)
- {
- while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
- if ((c = FtpWrite(dbuf, l, nData)) < l)
- {
- printf("short write: passed %d, wrote %d\n", l, c);
- rv = 0;
- break;
- }
- }
- else
- {
- while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
- if (fwrite(dbuf, 1, l, local) <= 0)
- {
- perror("localfile write");
- rv = 0;
- break;
- }
- }
- free(dbuf);
- fflush(local);
- if (localfile != NULL)
- fclose(local);
- FtpClose(nData);
- return rv;
+ else
+ {
+ while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
+ if (fwrite(dbuf, 1, l, local) <= 0)
+ {
+ perror("localfile write");
+ rv = 0;
+ break;
+ }
+ }
+ free(dbuf);
+ fflush(local);
+ if (localfile != NULL)
+ fclose(local);
+ FtpClose(nData);
+ return rv;
}
/*
@@ -1160,9 +1160,9 @@ static int FtpXfer(const char *localfile, const char *path,
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpNlst(const char *outputfile, const char *path,
- netbuf *nControl)
+ netbuf *nControl)
{
- return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII);
+ return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII);
}
/*
@@ -1172,7 +1172,7 @@ GLOBALDEF int FtpNlst(const char *outputfile, const char *path,
*/
GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl)
{
- return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII);
+ return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII);
}
/*
@@ -1182,25 +1182,25 @@ GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl)
*/
GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
{
- char cmd[256];
- int resp,sz,rv=1;
+ char cmd[256];
+ int resp,sz,rv=1;
- if ((strlen(path) + 7) > sizeof(cmd))
- return 0;
- sprintf(cmd, "TYPE %c", mode);
- if (!FtpSendCmd(cmd, '2', nControl))
- return 0;
- sprintf(cmd,"SIZE %s",path);
- if (!FtpSendCmd(cmd,'2',nControl))
- rv = 0;
- else
- {
- if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2)
- *size = sz;
+ if ((strlen(path) + 7) > sizeof(cmd))
+ return 0;
+ sprintf(cmd, "TYPE %c", mode);
+ if (!FtpSendCmd(cmd, '2', nControl))
+ return 0;
+ sprintf(cmd,"SIZE %s",path);
+ if (!FtpSendCmd(cmd,'2',nControl))
+ rv = 0;
else
- rv = 0;
- }
- return rv;
+ {
+ if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2)
+ *size = sz;
+ else
+ rv = 0;
+ }
+ return rv;
}
/*
@@ -1210,13 +1210,13 @@ GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
*/
GLOBALDEF int FtpRestart(int offset, netbuf *nControl)
{
- char cmd[256];
- int rv=1;
+ char cmd[256];
+ int rv=1;
- sprintf(cmd,"REST %d",offset);
- if (!FtpSendCmd(cmd,'3',nControl))
- rv = 0;
- return rv;
+ sprintf(cmd,"REST %d",offset);
+ if (!FtpSendCmd(cmd,'3',nControl))
+ rv = 0;
+ return rv;
}
/*
@@ -1226,17 +1226,17 @@ GLOBALDEF int FtpRestart(int offset, netbuf *nControl)
*/
GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl)
{
- char buf[256];
- int rv = 1;
+ char buf[256];
+ int rv = 1;
- if ((strlen(path) + 7) > sizeof(buf))
- return 0;
- sprintf(buf,"MDTM %s",path);
- if (!FtpSendCmd(buf,'2',nControl))
- rv = 0;
- else
- strncpy(dt, &nControl->response[4], max);
- return rv;
+ if ((strlen(path) + 7) > sizeof(buf))
+ return 0;
+ sprintf(buf,"MDTM %s",path);
+ if (!FtpSendCmd(buf,'2',nControl))
+ rv = 0;
+ else
+ strncpy(dt, &nControl->response[4], max);
+ return rv;
}
/*
@@ -1245,9 +1245,9 @@ GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl)
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpGet(const char *outputfile, const char *path,
- char mode, netbuf *nControl)
+ char mode, netbuf *nControl)
{
- return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode);
+ return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode);
}
/*
@@ -1256,9 +1256,9 @@ GLOBALDEF int FtpGet(const char *outputfile, const char *path,
* return 1 if successful, 0 otherwise
*/
GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode,
- netbuf *nControl)
+ netbuf *nControl)
{
- return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode);
+ return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode);
}
/*
@@ -1268,18 +1268,18 @@ GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode,
*/
GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl)
{
- char cmd[256];
+ char cmd[256];
- if (((strlen(src) + 7) > sizeof(cmd)) ||
- ((strlen(dst) + 7) > sizeof(cmd)))
- return 0;
- sprintf(cmd,"RNFR %s",src);
- if (!FtpSendCmd(cmd,'3',nControl))
- return 0;
- sprintf(cmd,"RNTO %s",dst);
- if (!FtpSendCmd(cmd,'2',nControl))
- return 0;
- return 1;
+ if (((strlen(src) + 7) > sizeof(cmd)) ||
+ ((strlen(dst) + 7) > sizeof(cmd)))
+ return 0;
+ sprintf(cmd,"RNFR %s",src);
+ if (!FtpSendCmd(cmd,'3',nControl))
+ return 0;
+ sprintf(cmd,"RNTO %s",dst);
+ if (!FtpSendCmd(cmd,'2',nControl))
+ return 0;
+ return 1;
}
/*
@@ -1289,14 +1289,14 @@ GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl)
*/
GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
{
- char cmd[256];
+ char cmd[256];
- if ((strlen(fnm) + 7) > sizeof(cmd))
- return 0;
- sprintf(cmd,"DELE %s",fnm);
- if (!FtpSendCmd(cmd,'2', nControl))
- return 0;
- return 1;
+ if ((strlen(fnm) + 7) > sizeof(cmd))
+ return 0;
+ sprintf(cmd,"DELE %s",fnm);
+ if (!FtpSendCmd(cmd,'2', nControl))
+ return 0;
+ return 1;
}
/*
@@ -1306,12 +1306,12 @@ GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
*/
GLOBALDEF void FtpQuit(netbuf *nControl)
{
- if (nControl->dir != FTPLIB_CONTROL)
- return;
- FtpSendCmd("QUIT",'2',nControl);
- net_close(nControl->handle);
- free(nControl->buf);
- free(nControl);
+ if (nControl->dir != FTPLIB_CONTROL)
+ return;
+ FtpSendCmd("QUIT",'2',nControl);
+ net_close(nControl->handle);
+ free(nControl->buf);
+ free(nControl);
}
/*
@@ -1321,92 +1321,92 @@ GLOBALDEF void FtpQuit(netbuf *nControl)
*/
GLOBALREF int HttpConnect(const char *host, netbuf **nControl)
{
- int sControl;
- struct sockaddr_in sin;
- struct hostent *phe;
- struct servent *pse;
- int on=1;
- netbuf *ctrl;
- char *lhost;
- char *pnum;
+ int sControl;
+ struct sockaddr_in sin;
+ struct hostent *phe;
+ struct servent *pse;
+ int on=1;
+ netbuf *ctrl;
+ char *lhost;
+ char *pnum;
- memset(&sin,0,sizeof(sin));
- sin.sin_family = AF_INET;
- lhost = strdup(host);
- pnum = strchr(lhost,':');
- if (pnum == NULL)
- {
+ memset(&sin,0,sizeof(sin));
+ sin.sin_family = AF_INET;
+ lhost = strdup(host);
+ pnum = strchr(lhost,':');
+ if (pnum == NULL)
+ {
#if defined(VMS)
- sin.sin_port = htons(21);
+ sin.sin_port = htons(21);
#else
- if ((pse = getservbyname("http","tcp")) == NULL)
- {
- perror("getservbyname");
- return 0;
- }
- sin.sin_port = pse->s_port;
+ if ((pse = getservbyname("http","tcp")) == NULL)
+ {
+ perror("getservbyname");
+ return 0;
+ }
+ sin.sin_port = pse->s_port;
#endif
- }
- else
- {
- *pnum++ = '\0';
- if (isdigit(*pnum))
- sin.sin_port = htons(atoi(pnum));
+ }
else
{
- pse = getservbyname(pnum,"tcp");
- sin.sin_port = pse->s_port;
+ *pnum++ = '\0';
+ if (isdigit(*pnum))
+ sin.sin_port = htons(atoi(pnum));
+ else
+ {
+ pse = getservbyname(pnum,"tcp");
+ sin.sin_port = pse->s_port;
+ }
+ }
+ if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
+ {
+ if ((phe = gethostbyname(lhost)) == NULL)
+ {
+ perror("gethostbyname");
+ return 0;
+ }
+ memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
}
- }
- if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
- {
- if ((phe = gethostbyname(lhost)) == NULL)
- {
- perror("gethostbyname");
- return 0;
- }
- memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
- }
- free(lhost);
- sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sControl == -1)
- {
- perror("socket");
- return 0;
- }
- if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
- SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
- {
- perror("setsockopt");
- net_close(sControl);
- return 0;
- }
- if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1)
- {
- perror("connect");
- net_close(sControl);
- return 0;
- }
- ctrl = calloc(1,sizeof(netbuf));
- if (ctrl == NULL)
- {
- perror("calloc");
- net_close(sControl);
- return 0;
- }
- ctrl->buf = NULL;
- ctrl->handle = sControl;
- ctrl->dir = FTPLIB_CONTROL;
- ctrl->ctrl = NULL;
- ctrl->cmode = FTPLIB_DEFMODE;
- ctrl->idlecb = NULL;
- ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
- ctrl->idlearg = NULL;
- ctrl->xfered = 0;
- ctrl->xfered1 = 0;
- ctrl->cbbytes = 0;
- *nControl = ctrl;
- return 1;
+ free(lhost);
+ sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (sControl == -1)
+ {
+ perror("socket");
+ return 0;
+ }
+ if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
+ SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
+ {
+ perror("setsockopt");
+ net_close(sControl);
+ return 0;
+ }
+ if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+ {
+ perror("connect");
+ net_close(sControl);
+ return 0;
+ }
+ ctrl = calloc(1,sizeof(netbuf));
+ if (ctrl == NULL)
+ {
+ perror("calloc");
+ net_close(sControl);
+ return 0;
+ }
+ ctrl->buf = NULL;
+ ctrl->handle = sControl;
+ ctrl->dir = FTPLIB_CONTROL;
+ ctrl->ctrl = NULL;
+ ctrl->cmode = FTPLIB_DEFMODE;
+ ctrl->idlecb = NULL;
+ ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
+ ctrl->idlearg = NULL;
+ ctrl->xfered = 0;
+ ctrl->xfered1 = 0;
+ ctrl->cbbytes = 0;
+ *nControl = ctrl;
+ return 1;
}
/*
@@ -1416,31 +1416,31 @@ GLOBALREF int HttpConnect(const char *host, netbuf **nControl)
*/
static int HttpSendCmd(const char *cmd, char expresp, netbuf *nControl)
{
- int ret = 0;
- char *buf = nControl->response;
- if (nControl->dir != FTPLIB_CONTROL)
- return 0;
- if (ftplib_debug > 2)
- fprintf(stderr,"%s\n",cmd);
- if (net_write(nControl->handle,cmd,strlen(cmd)) <= 0)
- {
- perror("write");
+ int ret = 0;
+ char *buf = nControl->response;
+ if (nControl->dir != FTPLIB_CONTROL)
+ return 0;
+ if (ftplib_debug > 2)
+ fprintf(stderr,"%s\n",cmd);
+ if (net_write(nControl->handle,cmd,strlen(cmd)) <= 0)
+ {
+ perror("write");
+ return 0;
+ }
+ while (ret < 256) {
+ if (socket_wait(nControl) != 1)
+ return 0;
+ if (net_read(nControl->handle,buf,1) != 1)
+ break;
+ ret++;
+ if (*buf == '\r') continue;
+ if (*buf == '\n') break;
+ buf++;
+ }
+ *buf = 0;
+ if (nControl->response[9] == expresp)
+ return 1;
return 0;
- }
- while (ret < 256) {
- if (socket_wait(nControl) != 1)
- return 0;
- if (net_read(nControl->handle,buf,1) != 1)
- break;
- ret++;
- if (*buf == '\r') continue;
- if (*buf == '\n') break;
- buf++;
- }
- *buf = 0;
- if (nControl->response[9] == expresp)
- return 1;
- return 0;
}
/*
@@ -1449,58 +1449,58 @@ static int HttpSendCmd(const char *cmd, char expresp, netbuf *nControl)
* return 1 if successful, 0 otherwise
*/
static int HttpXfer(const char *localfile, const char *path,
- netbuf *nControl, int typ, int mode)
+ netbuf *nControl, int typ, int mode)
{
- int l,c;
- char *dbuf;
- FILE *local = NULL;
- int rv=1;
+ int l,c;
+ char *dbuf;
+ FILE *local = NULL;
+ int rv=1;
- if (localfile != NULL)
- {
- char ac[4] = "a";
- if (typ == FTPLIB_FILE_WRITE)
- ac[0] = 'r';
- if (mode == FTPLIB_IMAGE)
- ac[1] = 'b';
- local = fopen(localfile, ac);
+ if (localfile != NULL)
+ {
+ char ac[4] = "a";
+ if (typ == FTPLIB_FILE_WRITE)
+ ac[0] = 'r';
+ if (mode == FTPLIB_IMAGE)
+ ac[1] = 'b';
+ local = fopen(localfile, ac);
+ if (local == NULL)
+ {
+ strncpy(nControl->response, strerror(errno),
+ sizeof(nControl->response));
+ return 0;
+ }
+ }
if (local == NULL)
+ local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
+ dbuf = malloc(FTPLIB_BUFSIZ);
+ if (typ == FTPLIB_FILE_WRITE)
{
- strncpy(nControl->response, strerror(errno),
- sizeof(nControl->response));
- return 0;
+ while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
+ if ((c = FtpWrite(dbuf, l, nControl)) < l)
+ {
+ printf("short write: passed %d, wrote %d\n", l, c);
+ rv = 0;
+ break;
+ }
}
- }
- if (local == NULL)
- local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
- dbuf = malloc(FTPLIB_BUFSIZ);
- if (typ == FTPLIB_FILE_WRITE)
- {
- while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
- if ((c = FtpWrite(dbuf, l, nControl)) < l)
- {
- printf("short write: passed %d, wrote %d\n", l, c);
- rv = 0;
- break;
- }
- }
- else
- {
- nControl->dir = FTPLIB_READ;
- while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nControl)) > 0)
- if (fwrite(dbuf, 1, l, local) <= 0)
- {
- perror("localfile write");
- rv = 0;
- break;
- }
- }
- free(dbuf);
- fflush(local);
- if (localfile != NULL)
- fclose(local);
- free(nControl->data);
- return rv;
+ else
+ {
+ nControl->dir = FTPLIB_READ;
+ while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nControl)) > 0)
+ if (fwrite(dbuf, 1, l, local) <= 0)
+ {
+ perror("localfile write");
+ rv = 0;
+ break;
+ }
+ }
+ free(dbuf);
+ fflush(local);
+ if (localfile != NULL)
+ fclose(local);
+ free(nControl->data);
+ return rv;
}
/*
@@ -1509,40 +1509,40 @@ static int HttpXfer(const char *localfile, const char *path,
* return 1 if successful, 0 otherwise
*/
GLOBALREF int HttpGet(const char *outputfile, const char *path, int *size,
- netbuf *nControl)
+ netbuf *nControl)
{
- char buf[256];
+ char buf[256];
- sprintf(buf, "GET %s HTTP/1.0\r\n\r\n\r\n", path);
- if(!HttpSendCmd(buf,'2',nControl))
- {
- if (nControl->response[9] == '3')
- printf("redirection not supported\n");
- return 0;
- }
+ sprintf(buf, "GET %s HTTP/1.0\r\n\r\n\r\n", path);
+ if(!HttpSendCmd(buf,'2',nControl))
+ {
+ if (nControl->response[9] == '3')
+ printf("redirection not supported\n");
+ return 0;
+ }
- while (1)
- {
- int ret = 0;
- char *buf = nControl->response;
- while (ret < 256) {
- if (socket_wait(nControl) != 1)
- return 0;
- if (net_read(nControl->handle,buf,1) != 1)
- break;
- ret++;
- if (*buf == '\r') continue;
- if (*buf == '\n') break;
- buf++;
- }
- *buf = 0;
- if (strstr(nControl->response,"Content-Length"))
- sscanf(nControl->response,"Content-Length: %d",size);
- if (strlen(nControl->response) == 0)
- break;
- }
+ while (1)
+ {
+ int ret = 0;
+ char *buf = nControl->response;
+ while (ret < 256) {
+ if (socket_wait(nControl) != 1)
+ return 0;
+ if (net_read(nControl->handle,buf,1) != 1)
+ break;
+ ret++;
+ if (*buf == '\r') continue;
+ if (*buf == '\n') break;
+ buf++;
+ }
+ *buf = 0;
+ if (strstr(nControl->response,"Content-Length"))
+ sscanf(nControl->response,"Content-Length: %d",size);
+ if (strlen(nControl->response) == 0)
+ break;
+ }
- return HttpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, FTPLIB_IMAGE);
+ return HttpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, FTPLIB_IMAGE);
}
/*
@@ -1552,6 +1552,6 @@ GLOBALREF int HttpGet(const char *outputfile, const char *path, int *size,
*/
GLOBALREF void HttpQuit(netbuf *nControl)
{
- net_close(nControl->handle);
- free(nControl);
+ net_close(nControl->handle);
+ free(nControl);
}
diff --git a/scripts/gensync b/scripts/gensync
index 27d20fc5..5c563562 100755
--- a/scripts/gensync
+++ b/scripts/gensync
@@ -20,7 +20,7 @@
# USA.
#
-myver='2.7.1'
+myver='2.7.2'
usage() {
echo "gensync $myver"
diff --git a/scripts/makepkg b/scripts/makepkg
index 977efdeb..393e00c5 100755
--- a/scripts/makepkg
+++ b/scripts/makepkg
@@ -20,7 +20,7 @@
# USA.
#
-myver='2.7.1'
+myver='2.7.2'
startdir=`pwd`
USE_COLOR="n"
@@ -178,6 +178,7 @@ usage() {
echo " -c, --clean Clean up work files after build"
echo " -C, --cleancache Clean up source files from the cache"
echo " -d, --nodeps Skip all dependency checks"
+ echo " -e, --noextract Do not extract source files (use existing src/ dir)"
echo " -f, --force Overwrite existing package"
echo " -g, --genmd5 Generate MD5sums for source files"
echo " -h, --help This help"
@@ -204,6 +205,7 @@ DEP_BIN=0
DEP_SRC=0
NODEPS=0
FORCE=0
+NOEXTRACT=0
NOSTRIP=0
RMDEPS=0
PKGDEST=$startdir
@@ -218,6 +220,7 @@ while [ "$#" -ne "0" ]; do
--syncdeps) DEP_BIN=1 ;;
--builddeps) DEP_SRC=1 ;;
--nodeps) NODEPS=1 ;;
+ --noextract) NOEXTRACT=1 ;;
--install) INSTALL=1 ;;
--force) FORCE=1 ;;
--nostrip) NOSTRIP=1 ;;
@@ -233,13 +236,14 @@ while [ "$#" -ne "0" ]; do
exit 1
;;
-*)
- while getopts "cCsbdhifgmnrp:w:-" opt; do
+ while getopts "cCsbdehifgmnrp:w:-" opt; do
case $opt in
c) CLEANUP=1 ;;
C) CLEANCACHE=1 ;;
s) DEP_BIN=1 ;;
b) DEP_SRC=1 ;;
d) NODEPS=1 ;;
+ e) NOEXTRACT=1 ;;
i) INSTALL=1 ;;
g) GENMD5=1 ;;
f) FORCE=1 ;;
@@ -414,52 +418,55 @@ for netfile in ${source[@]}; do
done
if [ "$GENMD5" = "0" ]; then
-# MD5 validation
- if [ ${#md5sums[@]} -ne ${#source[@]} ]; then
- warning "MD5sums are missing or incomplete. Cannot verify source integrity."
- #sleep 1
- elif [ `type -p md5sum` ]; then
- msg "Validating source files with MD5sums"
- errors=0
- idx=0
+ if [ "$NOEXTRACT" = "1" ]; then
+ warning "Skipping source extraction -- using existing src/ tree"
+ else
+ # MD5 validation
+ if [ ${#md5sums[@]} -ne ${#source[@]} ]; then
+ warning "MD5sums are missing or incomplete. Cannot verify source integrity."
+ #sleep 1
+ elif [ `type -p md5sum` ]; then
+ msg "Validating source files with MD5sums"
+ errors=0
+ idx=0
+ for netfile in ${source[@]}; do
+ file=`strip_url $netfile`
+ echo -n " $file ... " >&2
+ echo "${md5sums[$idx]} $file" | md5sum -c - >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "FAILED" >&2
+ errors=1
+ else
+ echo "Passed" >&2
+ fi
+ idx=$(($idx+1))
+ done
+ if [ $errors -gt 0 ]; then
+ error "One or more files did not pass the validity check!"
+ exit 1
+ fi
+ else
+ warning "The md5sum program is missing. Cannot verify source files!"
+ sleep 1
+ fi
+ # extract sources
+ msg "Extracting Sources..."
for netfile in ${source[@]}; do
file=`strip_url $netfile`
- echo -n " $file ... " >&2
- echo "${md5sums[$idx]} $file" | md5sum -c - >/dev/null 2>&1
- if [ $? -ne 0 ]; then
- echo "FAILED" >&2
- errors=1
- else
- echo "Passed" >&2
- fi
- idx=$(($idx+1))
- done
- if [ $errors -gt 0 ]; then
- error "One or more files did not pass the validity check!"
- exit 1
- fi
- else
- warning "The md5sum program is missing. Cannot verify source files!"
- sleep 1
- fi
-# extract sources
- msg "Extracting Sources..."
- for netfile in ${source[@]}; do
- file=`strip_url $netfile`
unset cmd
case $file in
*.tar.gz|*.tar.Z|*.tgz)
- cmd="tar --use-compress-program=gzip -xf $file" ;;
+ cmd="tar --use-compress-program=gzip -xf $file" ;;
*.tar.bz2)
- cmd="tar --use-compress-program=bzip2 -xf $file" ;;
+ cmd="tar --use-compress-program=bzip2 -xf $file" ;;
*.tar)
- cmd="tar -xf $file" ;;
+ cmd="tar -xf $file" ;;
*.zip)
- cmd="unzip -qqo $file" ;;
+ cmd="unzip -qqo $file" ;;
*.gz)
- cmd="gunzip $file" ;;
+ cmd="gunzip $file" ;;
*.bz2)
- cmd="bunzip2 $file" ;;
+ cmd="bunzip2 $file" ;;
esac
if [ "$cmd" != "" ]; then
msg " $cmd"
@@ -470,7 +477,8 @@ if [ "$GENMD5" = "0" ]; then
exit 1
fi
fi
- done
+ done
+ fi
else
# generate md5 hashes
if [ ! `type -p md5sum` ]; then
@@ -518,7 +526,7 @@ fi
# check for existing pkg directory
if [ -d $startdir/pkg ]; then
- msg "Removing existing pkg directory..."
+ msg "Removing existing pkg/ directory..."
rm -rf $startdir/pkg
fi
mkdir -p $startdir/pkg
@@ -573,9 +581,9 @@ cd $startdir
# strip binaries
if [ "$NOSTRIP" = "0" ]; then
msg "Stripping debugging symbols from libraries..."
- find pkg/{,usr,usr/local,opt/*}/lib -type f -exec /usr/bin/strip --strip-debug '{}' \; 2>&1
+ find pkg/{,usr,usr/local,opt/*}/lib -type f -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 | grep -v "No such file"
msg "Stripping symbols from binaries..."
- find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -exec /usr/bin/strip '{}' \; 2>&1
+ find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -exec /usr/bin/strip '{}' \; 2>&1 | grep -v "No such file"
fi
# get some package meta info
diff --git a/scripts/makeworld b/scripts/makeworld
index e1d5ed9d..49f25549 100755
--- a/scripts/makeworld
+++ b/scripts/makeworld
@@ -21,7 +21,7 @@
#
toplevel=`pwd`
-version="2.7.1"
+version="2.7.2"
usage() {
echo "makeworld version $version"
diff --git a/src/pacman.c b/src/pacman.c
index 5faab248..14e81a12 100644
--- a/src/pacman.c
+++ b/src/pacman.c
@@ -912,14 +912,14 @@ int pacman_sync(pacdb_t *db, PMList *targets)
/* no cache directory.... try creating it */
snprintf(parent, PATH_MAX, "%svar/cache/pacman", pmo_root);
- logaction(stderr, "warning: no %s cache exists. creating...\n", ldir);
+ logaction(stderr, "warning: no %s cache exists. creating...", ldir);
oldmask = umask(0000);
mkdir(parent, 0755);
if(mkdir(ldir, 0755)) {
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink
* the package afterwards.
*/
- logaction(stderr, "warning: couldn't create package cache, using /tmp instead\n");
+ logaction(stderr, "warning: couldn't create package cache, using /tmp instead");
snprintf(ldir, PATH_MAX, "/tmp");
varcache = 0;
}
@@ -1382,7 +1382,7 @@ int pacman_add(pacdb_t *db, PMList *targets)
temp = strdup("/tmp/pacman_XXXXXX");
mkstemp(temp);
if(tar_extract_file(tar, temp)) {
- logaction(stderr, "could not extract %s: %s\n", pathname, strerror(errno));
+ logaction(stderr, "could not extract %s: %s", pathname, strerror(errno));
errors++;
continue;
}
@@ -1419,13 +1419,13 @@ int pacman_add(pacdb_t *db, PMList *targets)
char newpath[PATH_MAX];
snprintf(newpath, PATH_MAX, "%s.pacorig", expath);
if(rename(expath, newpath)) {
- logaction(stderr, "error: could not rename %s: %s\n", expath, strerror(errno));
+ logaction(stderr, "error: could not rename %s: %s", expath, strerror(errno));
}
if(copyfile(temp, expath)) {
- logaction(stderr, "error: could not copy %s to %s: %s\n", temp, expath, strerror(errno));
+ logaction(stderr, "error: could not copy %s to %s: %s", temp, expath, strerror(errno));
errors++;
} else {
- logaction(stderr, "warning: %s saved as %s\n", expath, newpath);
+ logaction(stderr, "warning: %s saved as %s", expath, newpath);
}
}
} else if(md5_orig) {
@@ -1452,9 +1452,9 @@ int pacman_add(pacdb_t *db, PMList *targets)
installnew = 1;
snprintf(newpath, PATH_MAX, "%s.pacsave", expath);
if(rename(expath, newpath)) {
- logaction(stderr, "error: could not rename %s: %s\n", expath, strerror(errno));
+ logaction(stderr, "error: could not rename %s: %s", expath, strerror(errno));
} else {
- logaction(stderr, "warning: %s saved as %s\n", expath, newpath);
+ logaction(stderr, "warning: %s saved as %s", expath, newpath);
}
}
@@ -1478,11 +1478,11 @@ int pacman_add(pacdb_t *db, PMList *targets)
} else {
vprint("%s is in NoUpgrade - skipping\n", pathname);
strncat(expath, ".pacnew", PATH_MAX);
- logaction(stderr, "warning: extracting %s%s as %s\n", pmo_root, pathname, expath);
+ logaction(stderr, "warning: extracting %s%s as %s", pmo_root, pathname, expath);
/*tar_skip_regfile(tar);*/
}
if(tar_extract_file(tar, expath)) {
- logaction(stderr, "could not extract %s: %s\n", pathname, strerror(errno));
+ logaction(stderr, "could not extract %s: %s", pathname, strerror(errno));
errors++;
}
/* calculate an md5 hash if this is in info->backup */
@@ -1506,7 +1506,7 @@ int pacman_add(pacdb_t *db, PMList *targets)
tar_close(tar);
if(errors) {
ret = 1;
- logaction(stderr, "errors occurred while %s %s\n",
+ logaction(stderr, "errors occurred while %s %s",
(pmo_upgrade ? "upgrading" : "installing"), info->name);
/* XXX: this "else" is disabled so the db_write() ALWAYS occurs. If it doesn't
@@ -1541,7 +1541,7 @@ int pacman_add(pacdb_t *db, PMList *targets)
/* make an install date (in UTC) */
strncpy(info->installdate, asctime(gmtime(&t)), sizeof(info->installdate));
if(db_write(db, info)) {
- logaction(stderr, "error updating database for %s!\n", info->name);
+ logaction(stderr, "error updating database for %s!", info->name);
return(1);
}
vprint("done.\n");
@@ -1755,7 +1755,7 @@ int pacman_remove(pacdb_t *db, PMList *targets)
newpath = (char*)realloc(newpath, strlen(line)+strlen(".pacsave")+1);
sprintf(newpath, "%s.pacsave", line);
rename(line, newpath);
- logaction(stderr, "warning: %s saved as %s\n", line, newpath);
+ logaction(stderr, "warning: %s saved as %s", line, newpath);
} else {
/*vprint(" unlinking %s\n", line);*/
if(unlink(line)) {
@@ -1838,7 +1838,7 @@ int pacman_remove(pacdb_t *db, PMList *targets)
}
if(!pmo_upgrade) {
printf("done.\n");
- logaction(NULL, "removed %s (%s)\n", info->name, info->version);
+ logaction(NULL, "removed %s (%s)", info->name, info->version);
}
}
@@ -2427,7 +2427,7 @@ PMList* checkdeps(pacdb_t *db, unsigned short op, PMList *targets)
for(j = tp->depends; j; j = j->next) {
/* split into name/version pairs */
if(splitdep((char*)j->data, &depend)) {
- logaction(stderr, "warning: invalid dependency in %s\n", (char*)tp->name);
+ logaction(stderr, "warning: invalid dependency in %s", (char*)tp->name);
continue;
}
found = 0;
@@ -3019,7 +3019,8 @@ void logaction(FILE *fp, char *fmt, ...)
vsnprintf(msg, 1024, fmt, args);
va_end(args);
if(fp) {
- fprintf(fp, "%s", msg);
+ fprintf(fp, "%s\n", msg);
+ fflush(fp);
}
if(pmo_usesyslog) {
syslog(LOG_WARNING, "%s", msg);
@@ -3031,7 +3032,7 @@ void logaction(FILE *fp, char *fmt, ...)
tm = localtime(&t);
fprintf(logfd, "[%02d/%02d/%02d %02d:%02d] %s\n", tm->tm_mon+1, tm->tm_mday,
- tm->tm_year-100, tm->tm_hour, tm->tm_min, msg);
+ tm->tm_year-100, tm->tm_hour, tm->tm_min, msg);
}
}
@@ -3083,7 +3084,7 @@ void cleanup(int signum)
PMList *lp;
if(pm_access == READ_WRITE && lckrm(lckfile)) {
- logaction(stderr, "warning: could not remove lock file %s\n", lckfile);
+ logaction(stderr, "warning: could not remove lock file %s", lckfile);
}
if(workfile) {
/* remove the current file being downloaded (as it's not complete) */
diff --git a/src/pacman.h b/src/pacman.h
index 004339a5..727f0fc7 100644
--- a/src/pacman.h
+++ b/src/pacman.h
@@ -22,7 +22,7 @@
#define _PAC_PACMAN_H
#ifndef PACVER
-#define PACVER "2.7.1"
+#define PACVER "2.7.2"
#endif
#ifndef PKGDIR
diff --git a/src/pacsync.c b/src/pacsync.c
index a3d7a734..6903a19f 100644
--- a/src/pacsync.c
+++ b/src/pacsync.c
@@ -142,7 +142,7 @@ int downloadfiles(PMList *servers, char *localpath, PMList *files)
}
}
- /* set up our progress bar's callback */
+ /* set up our progress bar's callback (and idle timeout) */
if(strcmp(server->protocol, "file")) {
FtpOptions(FTPLIB_CALLBACK, (long)log_progress, control);
FtpOptions(FTPLIB_IDLETIME, (long)1000, control);