repo: uritools action: commit revision: path_from: revision_from: cf033ab1401cc58d2085105283277901da9f5215: path_to: revision_to:
commit cf033ab1401cc58d2085105283277901da9f5215 Author: epochDate: Mon Aug 14 22:29:06 2023 +0000 some breaking changes. paths will now not start with / if the / is being used to separate the path from the domain. good luck. diff --git a/uri.h b/uri.h
--- a/uri.h
+++ b/uri.h
@@ -120,6 +120,7 @@ unsigned int uricmp(struct uri *a,struct uri *b) {
char *linefromuri(struct uri *u) {
char *line=malloc(2048);//fuck if I know
+ // maybe loop over all the input parts and add up the lengths then add a bit of extra for separators
strcpy(line,"");
if(u->scheme) {
strcat(line,u->scheme);
@@ -127,6 +128,9 @@ char *linefromuri(struct uri *u) {
if(u->scheme && u->domain) {
strcat(line,"://");
}
+ if(!u->scheme && u->domain) {
+ strcat(line,"//");
+ }
if(u->scheme && !u->domain) {
strcat(line,":");
}
@@ -141,7 +145,9 @@ char *linefromuri(struct uri *u) {
strcat(line,"@");
}
if(u->domain) {
+ if(strchr(u->domain,':')) strcat(line,"[");
strcat(line,u->domain);
+ if(strchr(u->domain,':')) strcat(line,"]");
}
if(u->port && u->domain) { //port only makes sense if there's a domain
strcat(line,":");
@@ -150,12 +156,9 @@ char *linefromuri(struct uri *u) {
if(u->path && u->scheme && !u->domain) {
strcat(line,u->path);
}
- if(u->path && u->scheme && u->domain) {
- if(*u->path != '/') {
- strcat(line,"/");
- }
+ if(u->path && u->domain) { // scheme isn't required for path and domain separator to be added
+ strcat(line,"/");
strcat(line,u->path);
- //path must start with / if we have domain.
}
if(u->query_string) {
strcat(line,"?");
@@ -253,13 +256,12 @@ int urifromline(struct uri *u,char *line) {
if(*line == '/' && line[1] == '/') {//we have an authority section.
//let's left-shift this shit over until the third /
- for(t=line+1;*(t+1) && *(t+1) != '/';t++) {
- *t=*(t+1);
+ if((u->path=strchr(line+2,'/'))) {
+ *u->path=0;
+ u->path++;
}
- *t=0;
- u->path=t+1;//if there was a /, path points at it and the stuff after.
//if there wasn't a /, it points at a null byte. so "empty"
- u->username=line+1;
+ u->username=line+2;// +2 because we want to skip the // at the start
} else {
//we're an authority section without a // I guess.
//or we're a path
@@ -284,6 +286,10 @@ int urifromline(struct uri *u,char *line) {
}
}
if(u->domain) {
+ if(!u->path && (u->path=strchr(u->domain,'/'))) {
+ *u->path=0;
+ u->path++;
+ }
if((u->port=strchr(u->domain,']')) && *u->domain == '[') {//this is an IPv6 host
*u->port=0;
u->port++;
@@ -291,6 +297,8 @@ int urifromline(struct uri *u,char *line) {
if(*u->port == ':') {
*u->port=0;
u->port++;//if it ends up being empty, whatever. that's a URI like: http://host:/path
+ } else {
+ u->port=0;//a port isn't actually in the URI!
}
} else { //we're safe to split port off at :
if((u->port=strchr(u->domain,':'))) {
-----END OF PAGE-----