summaryrefslogtreecommitdiffstats
path: root/lib/libfetch
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1998-08-17 09:30:19 +0000
committerdes <des@FreeBSD.org>1998-08-17 09:30:19 +0000
commitb31588089070ef6d8f786c0bd15e56303eedd7d8 (patch)
tree97e93e4e1d1747208148ebef971d2118462d48f9 /lib/libfetch
parent277f8e55a3a42d8efbc3bd38b2ce29003597bc62 (diff)
downloadFreeBSD-src-b31588089070ef6d8f786c0bd15e56303eedd7d8.zip
FreeBSD-src-b31588089070ef6d8f786c0bd15e56303eedd7d8.tar.gz
Commit a bunch of patches that have been accumulating:
- Fix the README to reflect the new status of the ftp code. - Change tons of 'if (xxx < 0)' to 'if (xxx == -1)' - Add two new interface functions - Fix the Makefile so it actually works (yay!) Now the manpage is lagging even further behind... :( Next on the todo list is to clean up the http code.
Diffstat (limited to 'lib/libfetch')
-rw-r--r--lib/libfetch/Makefile12
-rw-r--r--lib/libfetch/README2
-rw-r--r--lib/libfetch/fetch.c61
-rw-r--r--lib/libfetch/fetch.h4
-rw-r--r--lib/libfetch/ftp.c25
-rw-r--r--lib/libfetch/http.c6
6 files changed, 62 insertions, 48 deletions
diff --git a/lib/libfetch/Makefile b/lib/libfetch/Makefile
index ec41775..91bbe1d 100644
--- a/lib/libfetch/Makefile
+++ b/lib/libfetch/Makefile
@@ -1,5 +1,5 @@
LIB= fetch
-CFLAGS+= -I${.CURDIR} -Wall
+CFLAGS+= -I${.CURDIR} -Wall -pedantic -DNDEBUG
SRCS= fetch.c ftp.c http.c file.c
MAN3= fetch.3
CLEANFILES+= ftperr.c httperr.c
@@ -11,8 +11,9 @@ beforeinstall:
${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/fetch.h \
${DESTDIR}/usr/include
-ftperr.c: ftp.errors
- @echo "struct ftperr {" \ >> ${.TARGET}
+ftp.c: ftperr.c
+ftperr.c: ftp.errors
+ @echo "struct ftperr {" \ > ${.TARGET}
@echo " const int num;" \ >> ${.TARGET}
@echo " const char *string;" \ >> ${.TARGET}
@echo "};" \ >> ${.TARGET}
@@ -26,8 +27,9 @@ ftperr.c: ftp.errors
@echo " { -1, \"Unknown FTP error\" }" >> ${.TARGET}
@echo "};" >> ${.TARGET}
-httperr.c: http.errors
- @echo "struct httperr {" \ >> ${.TARGET}
+http.c: httperr.c
+httperr.c: http.errors
+ @echo "struct httperr {" \ > ${.TARGET}
@echo " const int num;" \ >> ${.TARGET}
@echo " const char *string;" \ >> ${.TARGET}
@echo "};" \ >> ${.TARGET}
diff --git a/lib/libfetch/README b/lib/libfetch/README
index 30ddeae..ce50f56 100644
--- a/lib/libfetch/README
+++ b/lib/libfetch/README
@@ -8,8 +8,6 @@ items:
* The man page needs work. Really. I mean it. Now.
- * ftp.c is not even half-written.
-
* HTTP authentication doesn't work. I'm not sure if I bungled http.c
or fubared base64.c (which was ripped from MIT fetch(1)).
diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c
index 8f53247..54421a2 100644
--- a/lib/libfetch/fetch.c
+++ b/lib/libfetch/fetch.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: fetch.c,v 1.1.1.1 1998/07/09 16:52:42 des Exp $
+ * $Id: fetch.c,v 1.3 1998/07/11 21:29:07 des Exp $
*/
#include <sys/param.h>
@@ -51,26 +51,43 @@
int fetchLastErrCode;
const char *fetchLastErrText;
+FILE *
+fetchGet(url_t *URL, char *flags)
+{
+ if (strcasecmp(URL->scheme, "file") == 0)
+ return fetchGetFile(URL, flags);
+ else if (strcasecmp(URL->scheme, "http") == 0)
+ return fetchGetHTTP(URL, flags);
+ else if (strcasecmp(URL->scheme, "ftp") == 0)
+ return fetchGetFTP(URL, flags);
+ else return NULL;
+
+}
+
+FILE *
+fetchPut(url_t *URL, char *flags)
+{
+ if (strcasecmp(URL->scheme, "file") == 0)
+ return fetchPutFile(URL, flags);
+ else if (strcasecmp(URL->scheme, "http") == 0)
+ return fetchPutHTTP(URL, flags);
+ else if (strcasecmp(URL->scheme, "ftp") == 0)
+ return fetchPutFTP(URL, flags);
+ else return NULL;
+}
+
/* get URL */
FILE *
fetchGetURL(char *URL, char *flags)
{
url_t *u;
FILE *f;
-
- /* parse URL */
+
if ((u = fetchParseURL(URL)) == NULL)
return NULL;
- /* select appropriate function */
- if (strcasecmp(u->scheme, "file") == 0)
- f = fetchGetFile(u, flags);
- else if (strcasecmp(u->scheme, "http") == 0)
- f = fetchGetHTTP(u, flags);
- else if (strcasecmp(u->scheme, "ftp") == 0)
- f = fetchGetFTP(u, flags);
- else f = NULL;
-
+ f = fetchGet(u, flags);
+
fetchFreeURL(u);
return f;
}
@@ -83,19 +100,11 @@ fetchPutURL(char *URL, char *flags)
url_t *u;
FILE *f;
- /* parse URL */
if ((u = fetchParseURL(URL)) == NULL)
return NULL;
- /* select appropriate function */
- if (strcasecmp(u->scheme, "file") == 0)
- f = fetchPutFile(u, flags);
- else if (strcasecmp(u->scheme, "http") == 0)
- f = fetchPutHTTP(u, flags);
- else if (strcasecmp(u->scheme, "ftp") == 0)
- f = fetchPutFTP(u, flags);
- else f = NULL;
-
+ f = fetchPut(u, flags);
+
fetchFreeURL(u);
return f;
}
@@ -202,6 +211,10 @@ fetchConnect(char *host, int port)
struct hostent *he;
int sd;
+#ifndef NDEBUG
+ fprintf(stderr, "\033[1m---> %s:%d\033[m\n", host, port);
+#endif
+
/* look up host name */
if ((he = gethostbyname(host)) == NULL)
return -1;
@@ -213,9 +226,9 @@ fetchConnect(char *host, int port)
sin.sin_port = htons(port);
/* try to connect */
- if ((sd = socket(sin.sin_family, SOCK_STREAM, IPPROTO_TCP)) < 0)
+ if ((sd = socket(sin.sin_family, SOCK_STREAM, IPPROTO_TCP)) == -1)
return -1;
- if (connect(sd, (struct sockaddr *)&sin, sizeof sin) < 0) {
+ if (connect(sd, (struct sockaddr *)&sin, sizeof sin) == -1) {
close(sd);
return -1;
}
diff --git a/lib/libfetch/fetch.h b/lib/libfetch/fetch.h
index 1a57056..377edad 100644
--- a/lib/libfetch/fetch.h
+++ b/lib/libfetch/fetch.h
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: fetch.h,v 1.1.1.1 1998/07/09 16:52:41 des Exp $
+ * $Id: fetch.h,v 1.3 1998/07/11 21:29:08 des Exp $
*/
#ifndef _FETCH_H_INCLUDED
@@ -70,6 +70,8 @@ url_t *fetchParseURL(char *);
void fetchFreeURL(url_t *);
FILE *fetchGetURL(char *, char *);
FILE *fetchPutURL(char *, char *);
+FILE *fetchGet(url_t *, char *);
+FILE *fetchPut(url_t *, char *);
/* Error code and string */
extern int fetchLastErrCode;
diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c
index b38a4e7..d66b7c3 100644
--- a/lib/libfetch/ftp.c
+++ b/lib/libfetch/ftp.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: ftp.c,v 1.3 1998/07/11 21:29:08 des Exp $
+ * $Id: ftp.c,v 1.4 1998/07/12 22:34:39 des Exp $
*/
/*
@@ -216,7 +216,7 @@ _ftp_transfer(FILE *cf, char *oper, char *file, char *mode, int pasv)
/* s now points to file name */
/* open data socket */
- if ((sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ if ((sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
_ftp_syserr();
return NULL;
}
@@ -242,13 +242,13 @@ _ftp_transfer(FILE *cf, char *oper, char *file, char *mode, int pasv)
/* construct sockaddr for data socket */
l = sizeof(sin);
- if (getpeername(fileno(cf), (struct sockaddr *)&sin, &l) < 0)
+ if (getpeername(fileno(cf), (struct sockaddr *)&sin, &l) == -1)
goto sysouch;
bcopy(addr, (char *)&sin.sin_addr, 4);
bcopy(addr + 4, (char *)&sin.sin_port, 2);
/* connect to data port */
- if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
+ if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1)
goto sysouch;
/* make the server initiate the transfer */
@@ -262,16 +262,16 @@ _ftp_transfer(FILE *cf, char *oper, char *file, char *mode, int pasv)
/* find our own address, bind, and listen */
l = sizeof(sin);
- if (getsockname(fileno(cf), (struct sockaddr *)&sin, &l) < 0)
+ if (getsockname(fileno(cf), (struct sockaddr *)&sin, &l) == -1)
goto sysouch;
sin.sin_port = 0;
- if (bind(sd, (struct sockaddr *)&sin, l) < 0)
+ if (bind(sd, (struct sockaddr *)&sin, l) == -1)
goto sysouch;
- if (listen(sd, 1) < 0)
+ if (listen(sd, 1) == -1)
goto sysouch;
/* find what port we're on and tell the server */
- if (getsockname(sd, (struct sockaddr *)&sin, &l) < 0)
+ if (getsockname(sd, (struct sockaddr *)&sin, &l) == -1)
goto sysouch;
a = ntohl(sin.sin_addr.s_addr);
p = ntohs(sin.sin_port);
@@ -285,7 +285,7 @@ _ftp_transfer(FILE *cf, char *oper, char *file, char *mode, int pasv)
goto ouch;
/* accept the incoming connection and go to town */
- if ((d = accept(sd, NULL, NULL)) < 0)
+ if ((d = accept(sd, NULL, NULL)) == -1)
goto sysouch;
close(sd);
sd = d;
@@ -329,7 +329,7 @@ _ftp_connect(char *host, int port, char *user, char *pwd)
}
/* check connection */
- if (sd < 0) {
+ if (sd == -1) {
_ftp_syserr();
return NULL;
}
@@ -341,7 +341,7 @@ _ftp_connect(char *host, int port, char *user, char *pwd)
}
/* expect welcome message */
- if (_ftp_chkerr(f, NULL) < 0)
+ if (_ftp_chkerr(f, NULL) == -1)
goto fouch;
/* send user name and password */
@@ -420,9 +420,8 @@ fetchXxxFTP(url_t *url, char *oper, char *mode, char *flags)
if (!url->port)
url->port = FTP_DEFAULT_PORT;
- /* try to use previously cached connection */
+ /* try to use previously cached connection; there should be a 226 waiting */
if (_ftp_isconnected(url)) {
- fprintf(cached_socket, "PWD" ENDL);
_ftp_chkerr(cached_socket, &e);
if (e > 0)
cf = cached_socket;
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 68b3525..9ce86a9 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: http.c,v 1.3 1998/07/11 21:29:08 des Exp $
+ * $Id: http.c,v 1.4 1998/07/12 22:34:40 des Exp $
*/
/*
@@ -357,8 +357,8 @@ fetchGetHTTP(url_t *URL, char *flags)
}
/* if no proxy is configured or could be contacted, try direct */
- if (sd < 0) {
- if ((sd = fetchConnect(URL->host, URL->port)) < 0)
+ if (sd == -1) {
+ if ((sd = fetchConnect(URL->host, URL->port)) == -1)
goto ouch;
}
OpenPOWER on IntegriCloud