From 8b7632d0ae0834cd1de94364a759ab2b76423595 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Mon, 30 Apr 2018 06:58:27 +0000 Subject: added a hack to only ignore the first // when separating at the domain/path separation. fixed a dumb bug where uninitiallized string was being used as the value of the port. probably me testing something that I forgot about. --- url.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'url.h') diff --git a/url.h b/url.h index df0ef90..a3ddc3e 100644 --- a/url.h +++ b/url.h @@ -32,11 +32,16 @@ struct url { void urlfromline(struct url *u,char *line) { int i; + char hack=0;//we need to allow for // as host//path separator //split at first single / into line and path + //this fails to split scheme://host//path into: scheme, host, /path. needs to be first single / or second double-or-more-/ for(i=0;line[i];i++) { if(line[i] == '/' && line[i+1] == '/') { - i++; - continue; + if(!hack) {//only skip out on the first // because it is probably used in the scheme. + hack=1; + i++; + continue; + } } if(line[i] == '/') { line[i]=0; @@ -143,7 +148,7 @@ void magic_and_defaults(struct url *u) { serv=getservbyname(u->scheme,strcmp(u->scheme,"udp")?"tcp":"udp");//gets default port for the scheme. http -> 80 if(serv) snprintf(sport,sizeof(sport)-1,"%d",ntohs(serv->s_port)); // else snprintf(sport,sizeof(sport)-1,"%d",serv); - u->port=AorB(u->port,AorB(getenv("URL_PORT"),(serv||1?strdup(sport):"DEFAULT"))); + u->port=AorB(u->port,AorB(getenv("URL_PORT"),(serv?strdup(sport):"DEFAULT"))); // if(!strcmp(u->port,"DEFAULT")) { //this shouldn't happen most of the time. :/ -- cgit v1.2.3