aboutsummaryrefslogtreecommitdiff
path: root/lib/libfetch
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2012-11-04 02:52:03 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2012-11-04 02:52:03 +0000
commit23090366f729c56cab62de74c7a51792357e98a9 (patch)
treec511c885796e28ec571b5267e8f11f3b103d35e9 /lib/libfetch
parent7750ad47a9a7dbc83f87158464170c8640723293 (diff)
parent22ff74b2f44234d31540b1f7fd6c91489c37cad3 (diff)
downloadsrc-23090366f729c56cab62de74c7a51792357e98a9.tar.gz
src-23090366f729c56cab62de74c7a51792357e98a9.zip
Sync from head
Notes
Notes: svn path=/projects/bmake/; revision=242545
Diffstat (limited to 'lib/libfetch')
-rw-r--r--lib/libfetch/Makefile4
-rw-r--r--lib/libfetch/common.h2
-rw-r--r--lib/libfetch/file.c10
-rw-r--r--lib/libfetch/http.c28
-rw-r--r--lib/libfetch/http.errors1
5 files changed, 37 insertions, 8 deletions
diff --git a/lib/libfetch/Makefile b/lib/libfetch/Makefile
index 7b29aa2df5e5..085aba2c6cb4 100644
--- a/lib/libfetch/Makefile
+++ b/lib/libfetch/Makefile
@@ -16,8 +16,8 @@ CFLAGS+= -DINET6
.if ${MK_OPENSSL} != "no"
CFLAGS+= -DWITH_SSL
-DPADD= ${LIBSSL} ${LIBCRYPTO} ${LIBMD}
-LDADD= -lssl -lcrypto -lmd
+DPADD= ${LIBSSL} ${LIBCRYPTO}
+LDADD= -lssl -lcrypto
.else
DPADD= ${LIBMD}
LDADD= -lmd
diff --git a/lib/libfetch/common.h b/lib/libfetch/common.h
index 241dbbf8b465..fe591d3ea0df 100644
--- a/lib/libfetch/common.h
+++ b/lib/libfetch/common.h
@@ -63,7 +63,7 @@ struct fetchconn {
SSL *ssl; /* SSL handle */
SSL_CTX *ssl_ctx; /* SSL context */
X509 *ssl_cert; /* server certificate */
- SSL_METHOD *ssl_meth; /* SSL method */
+ const SSL_METHOD *ssl_meth; /* SSL method */
#endif
int ref; /* reference count */
};
diff --git a/lib/libfetch/file.c b/lib/libfetch/file.c
index 8569ff3ebd56..8c1d4042dcc6 100644
--- a/lib/libfetch/file.c
+++ b/lib/libfetch/file.c
@@ -50,12 +50,15 @@ fetchXGetFile(struct url *u, struct url_stat *us, const char *flags)
f = fopen(u->doc, "r");
- if (f == NULL)
+ if (f == NULL) {
fetch_syserr();
+ return (NULL);
+ }
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
fclose(f);
fetch_syserr();
+ return (NULL);
}
fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
@@ -78,12 +81,15 @@ fetchPutFile(struct url *u, const char *flags)
else
f = fopen(u->doc, "w+");
- if (f == NULL)
+ if (f == NULL) {
fetch_syserr();
+ return (NULL);
+ }
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
fclose(f);
fetch_syserr();
+ return (NULL);
}
fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index f6e063aa7121..00dd887cfce1 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -76,7 +76,15 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <time.h>
#include <unistd.h>
+
+#ifdef WITH_SSL
+#include <openssl/md5.h>
+#define MD5Init(c) MD5_Init(c)
+#define MD5Update(c, data, len) MD5_Update(c, data, len)
+#define MD5Final(md, c) MD5_Final(md, c)
+#else
#include <md5.h>
+#endif
#include <netinet/in.h>
#include <netinet/tcp.h>
@@ -86,7 +94,7 @@ __FBSDID("$FreeBSD$");
#include "httperr.h"
/* Maximum number of redirects to follow */
-#define MAX_REDIRECT 5
+#define MAX_REDIRECT 20
/* Symbolic names for reply codes we care about */
#define HTTP_OK 200
@@ -95,7 +103,9 @@ __FBSDID("$FreeBSD$");
#define HTTP_MOVED_TEMP 302
#define HTTP_SEE_OTHER 303
#define HTTP_NOT_MODIFIED 304
+#define HTTP_USE_PROXY 305
#define HTTP_TEMP_REDIRECT 307
+#define HTTP_PERM_REDIRECT 308
#define HTTP_NEED_AUTH 401
#define HTTP_NEED_PROXY_AUTH 407
#define HTTP_BAD_RANGE 416
@@ -104,6 +114,7 @@ __FBSDID("$FreeBSD$");
#define HTTP_REDIRECT(xyz) ((xyz) == HTTP_MOVED_PERM \
|| (xyz) == HTTP_MOVED_TEMP \
|| (xyz) == HTTP_TEMP_REDIRECT \
+ || (xyz) == HTTP_USE_PROXY \
|| (xyz) == HTTP_SEE_OTHER)
#define HTTP_ERROR(xyz) ((xyz) > 400 && (xyz) < 599)
@@ -1516,8 +1527,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
/* try the provided URL first */
url = URL;
- /* if the A flag is set, we only get one try */
- n = noredirect ? 1 : MAX_REDIRECT;
+ n = MAX_REDIRECT;
i = 0;
e = HTTP_PROTOCOL_ERROR;
@@ -1689,6 +1699,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
case HTTP_MOVED_PERM:
case HTTP_MOVED_TEMP:
case HTTP_SEE_OTHER:
+ case HTTP_USE_PROXY:
/*
* Not so fine, but we still have to read the
* headers to get the new location.
@@ -1764,6 +1775,17 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
case hdr_location:
if (!HTTP_REDIRECT(conn->err))
break;
+ /*
+ * if the A flag is set, we don't follow
+ * temporary redirects.
+ */
+ if (noredirect &&
+ conn->err != HTTP_MOVED_PERM &&
+ conn->err != HTTP_PERM_REDIRECT &&
+ conn->err != HTTP_USE_PROXY) {
+ n = 1;
+ break;
+ }
if (new)
free(new);
if (verbose)
diff --git a/lib/libfetch/http.errors b/lib/libfetch/http.errors
index 1f38574d463a..e5389fefcc56 100644
--- a/lib/libfetch/http.errors
+++ b/lib/libfetch/http.errors
@@ -18,6 +18,7 @@
304 OK Not Modified
305 INFO Use Proxy
307 MOVED Temporary Redirect
+308 MOVED Permanent Redirect
400 PROTO Bad Request
401 AUTH Unauthorized
402 AUTH Payment Required