summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/http.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1998-07-11 18:56:01 +0000
committerdes <des@FreeBSD.org>1998-07-11 18:56:01 +0000
commit5b74d7e9c7c1f6bdcbae4e658c76c41016cdbf6b (patch)
tree4c94334611bca07668a0219331f52a4629e64811 /lib/libfetch/http.c
parentc39856b85e73a59eb926c7f6cc6a6b4097c4947b (diff)
downloadFreeBSD-src-5b74d7e9c7c1f6bdcbae4e658c76c41016cdbf6b.zip
FreeBSD-src-5b74d7e9c7c1f6bdcbae4e658c76c41016cdbf6b.tar.gz
Too many changes to list. Basically, FTP is nearly there and error
reporting is kinda sorted out. Now HTTP needs to catch up...
Diffstat (limited to 'lib/libfetch/http.c')
-rw-r--r--lib/libfetch/http.c52
1 files changed, 19 insertions, 33 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 1cf9a9f..3178e2a 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$
+ * $Id: http.c,v 1.1.1.1 1998/07/09 16:52:41 des Exp $
*/
#include <sys/param.h>
@@ -71,32 +71,15 @@ struct cookie
unsigned b_len, chunksize;
};
-static int
-_http_connect(char *host, int port)
+static const char *
+_http_errstring(int e)
{
- struct sockaddr_in sin;
- struct hostent *he;
- int fd;
-
- /* look up host name */
- if ((he = gethostbyname(host)) == NULL)
- return -1;
+ struct httperr *p = _http_errlist;
- /* set up socket address structure */
- bzero(&sin, sizeof(sin));
- bcopy(he->h_addr, (char *)&sin.sin_addr, he->h_length);
- sin.sin_family = he->h_addrtype;
- sin.sin_port = htons(port);
-
- /* try to connect */
- if ((fd = socket(sin.sin_family, SOCK_STREAM, 0)) < 0)
- return -1;
- if (connect(fd, (struct sockaddr *)&sin, sizeof sin) < 0) {
- close(fd);
- return -1;
- }
-
- return fd;
+ while ((p->num != -1) && (p->num != e))
+ p++;
+
+ return p->string;
}
static char *
@@ -187,7 +170,7 @@ fetchContentType(FILE *f)
FILE *
fetchGetHTTP(url_t *URL, char *flags)
{
- int fd = -1, err, i, enc = ENC_NONE;
+ int sd = -1, err, i, enc = ENC_NONE;
struct cookie *c;
char *ln, *p, *q;
FILE *f, *cf;
@@ -222,17 +205,17 @@ fetchGetHTTP(url_t *URL, char *flags)
host[len] = 0;
/* connect */
- fd = _http_connect(host, port);
+ sd = fetchConnect(host, port);
}
/* if no proxy is configured or could be contacted, try direct */
- if (fd < 0) {
- if ((fd = _http_connect(URL->host, URL->port)) < 0)
+ if (sd < 0) {
+ if ((sd = fetchConnect(URL->host, URL->port)) < 0)
goto ouch;
}
/* reopen as stream */
- if ((f = fdopen(fd, "r+")) == NULL)
+ if ((f = fdopen(sd, "r+")) == NULL)
goto ouch;
c->real_f = f;
@@ -270,8 +253,11 @@ fetchGetHTTP(url_t *URL, char *flags)
DEBUG(fprintf(stderr, "code: [\033[1m%d\033[m]\n", err));
/* add code to handle redirects later */
- if (err != 200)
+ if (err != 200) {
+ fetchLastErrCode = err;
+ fetchLastErrText = _http_errstring(err);
goto fouch;
+ }
/* browse through header */
while (1) {
@@ -320,8 +306,8 @@ fetchGetHTTP(url_t *URL, char *flags)
return cf;
ouch:
- if (fd >= 0)
- close(fd);
+ if (sd >= 0)
+ close(sd);
free(c);
return NULL;
fouch:
OpenPOWER on IntegriCloud