Latest update.

This commit is contained in:
2020-04-15 18:45:34 +09:00
parent be29e7bcc6
commit 2015c00c43
573 changed files with 22943 additions and 6714 deletions
+66 -5
View File
@@ -11,6 +11,9 @@
#include <openssl/httperr.h>
#include <openssl/err.h>
#include <string.h>
#include "internal/cryptlib.h" /* for ossl_assert() */
#include "http_local.h"
/*
* Parse a URL and split it up into host, port and path components and
@@ -22,8 +25,11 @@ int OSSL_HTTP_parse_url(const char *url, char **phost, char **pport,
{
char *p, *buf;
char *host;
char *port = "80";
const char *port = OSSL_HTTP_PORT;
size_t https_len = strlen(OSSL_HTTPS_NAME);
if (!ossl_assert(https_len >= strlen(OSSL_HTTP_NAME)))
return 0;
if (url == NULL) {
HTTPerr(0, ERR_R_PASSED_NULL_PARAMETER);
return 0;
@@ -44,16 +50,16 @@ int OSSL_HTTP_parse_url(const char *url, char **phost, char **pport,
/* Check for initial colon */
p = strchr(buf, ':');
if (p == NULL || p - buf > 5 /* strlen("https") */) {
if (p == NULL || (size_t)(p - buf) > https_len) {
p = buf;
} else {
*(p++) = '\0';
if (strcmp(buf, "https") == 0) {
if (strcmp(buf, OSSL_HTTPS_NAME) == 0) {
if (pssl != NULL)
*pssl = 1;
port = "443";
} else if (strcmp(buf, "http") != 0) {
port = OSSL_HTTPS_PORT;
} else if (strcmp(buf, OSSL_HTTP_NAME) != 0) {
goto parse_err;
}
@@ -114,3 +120,58 @@ int OSSL_HTTP_parse_url(const char *url, char **phost, char **pport,
OPENSSL_free(buf);
return 0;
}
int http_use_proxy(const char *no_proxy, const char *server)
{
size_t sl;
const char *found = NULL;
if (!ossl_assert(server != NULL))
return 0;
sl = strlen(server);
/*
* using environment variable names, both lowercase and uppercase variants,
* compatible with other HTTP client implementations like wget, curl and git
*/
if (no_proxy == NULL)
no_proxy = getenv("no_proxy");
if (no_proxy == NULL)
no_proxy = getenv(OPENSSL_NO_PROXY);
if (no_proxy != NULL)
found = strstr(no_proxy, server);
while (found != NULL
&& ((found != no_proxy && found[-1] != ' ' && found[-1] != ',')
|| (found[sl] != '\0' && found[sl] != ' ' && found[sl] != ',')))
found = strstr(found + 1, server);
return found == NULL;
}
const char *http_adapt_proxy(const char *proxy, const char *no_proxy,
const char *server, int use_ssl)
{
const int http_len = strlen(OSSL_HTTP_PREFIX);
const int https_len = strlen(OSSL_HTTPS_PREFIX);
/*
* using environment variable names, both lowercase and uppercase variants,
* compatible with other HTTP client implementations like wget, curl and git
*/
if (proxy == NULL)
proxy = getenv(use_ssl ? "https_proxy" : "http_proxy");
if (proxy == NULL)
proxy = getenv(use_ssl ? OPENSSL_HTTP_PROXY :
OPENSSL_HTTPS_PROXY);
if (proxy == NULL)
return NULL;
/* skip any leading "http://" or "https://" */
if (strncmp(proxy, OSSL_HTTP_PREFIX, http_len) == 0)
proxy += http_len;
else if (strncmp(proxy, OSSL_HTTPS_PREFIX, https_len) == 0)
proxy += https_len;
if (*proxy == '\0' || !http_use_proxy(no_proxy, server))
return NULL;
return proxy;
}