summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/fetch.c
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/fetch.c
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/fetch.c')
-rw-r--r--lib/libfetch/fetch.c61
1 files changed, 37 insertions, 24 deletions
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;
}
OpenPOWER on IntegriCloud