From 2e17f8b4117fdbefd1c1b6452c7a39c1dab03207 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 23 Apr 2014 11:51:38 +0200 Subject: [PATCH] Fix URL with leading http:// not working PAZ-933 --- src/getaddrinfo.c | 19 ++++++++++++++++--- src/host.c | 8 +++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/getaddrinfo.c b/src/getaddrinfo.c index 2222562..656b9e1 100644 --- a/src/getaddrinfo.c +++ b/src/getaddrinfo.c @@ -69,7 +69,7 @@ static void perform_getaddrinfo(struct work *w) { struct addrinfo hints, *res; char host[512], *cp; - char *port = 0; + char *port = "210"; int error; hints.ai_flags = 0; @@ -81,14 +81,27 @@ static void perform_getaddrinfo(struct work *w) hints.ai_canonname = NULL; hints.ai_next = NULL; - strncpy(host, w->hostport, sizeof(host)-1); + if (!strncmp(w->hostport, "http://", 7)) + { + port = "80"; + strncpy(host, w->hostport + 7, sizeof(host)-1); + } + else if (!strncmp(w->hostport, "https://", 8)) + { + port = "443"; + strncpy(host, w->hostport + 8, sizeof(host)-1); + } + else + { + strncpy(host, w->hostport, sizeof(host)-1); + } host[sizeof(host)-1] = 0; if ((cp = strrchr(host, ':'))) { *cp = '\0'; port = cp + 1; } - error = getaddrinfo(host, port ? port : "210", &hints, &res); + error = getaddrinfo(host, port, &hints, &res); if (error) { yaz_log(YLOG_WARN, "Failed to resolve %s: %s", diff --git a/src/host.c b/src/host.c index 82b94ba..cece235 100644 --- a/src/host.c +++ b/src/host.c @@ -88,7 +88,13 @@ struct host *find_host(database_hosts_t hosts, const char *url, tproxy = xmalloc (strlen(url) + 10); /* so we can add :port */ strcpy(tproxy, url); - for (cp = tproxy; *cp; cp++) + if (!strncmp(tproxy, "http://", 7)) + cp = tproxy + 7; + else if (!strncmp(tproxy, "https://", 8)) + cp = tproxy + 8; + else + cp = tproxy; + for (; *cp; cp++) if (strchr("/?#~", *cp)) { *cp = '\0'; -- 1.7.10.4