BB#106: add default_port argument to extract_http_url and rename it to extract_url

There is in fact nothing http-specific any more about this function, hence
the rename. The input has been stripped of the <proto>:// header anyways.

This in preparation of fixing bug BB#106: ssl fails with literal ipv6 addrs.

Signed-off-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Michael Adam 2013-11-16 15:09:48 +01:00
parent 69c348ce6d
commit 98f77ef8c7

View File

@ -186,10 +186,14 @@ static int strip_return_port (char *host)
}
/*
* Pull the information out of the URL line. This will handle both HTTP
* and FTP (proxied) URLs.
* Pull the information out of the URL line.
* This expects urls with the initial '<proto>://'
* part stripped and hence can handle http urls,
* (proxied) ftp:// urls and https-requests that
* come in without the proto:// part via CONNECT.
*/
static int extract_http_url (const char *url, struct request_s *request)
static int extract_url (const char *url, int default_port,
struct request_s *request)
{
char *p;
int port;
@ -216,7 +220,7 @@ static int extract_http_url (const char *url, struct request_s *request)
/* Find a proper port in www.site.com:8001 URLs */
port = strip_return_port (request->host);
request->port = (port != 0) ? port : HTTP_PORT;
request->port = (port != 0) ? port : default_port;
/* Remove any surrounding '[' and ']' from IPv6 literals */
p = strrchr (request->host, ']');
@ -413,7 +417,7 @@ BAD_REQUEST_ERROR:
{
char *skipped_type = strstr (url, "//") + 2;
if (extract_http_url (skipped_type, request) < 0) {
if (extract_url (skipped_type, HTTP_PORT, request) < 0) {
indicate_http_error (connptr, 400, "Bad Request",
"detail", "Could not parse URL",
"url", url, NULL);