From b31588089070ef6d8f786c0bd15e56303eedd7d8 Mon Sep 17 00:00:00 2001 From: des Date: Mon, 17 Aug 1998 09:30:19 +0000 Subject: 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. --- lib/libfetch/fetch.c | 61 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'lib/libfetch/fetch.c') 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 @@ -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; } -- cgit v1.1