diff options
author | epoch <epoch@hacking.allowed.org> | 2019-04-22 23:32:23 -0500 |
---|---|---|
committer | epoch <epoch@hacking.allowed.org> | 2019-04-22 23:32:23 -0500 |
commit | 75fa9480f82b0fab52c00c35e1641da265041dfa (patch) | |
tree | 3728ca86b6d30e399d7e7acc31d3f0d90feed70a /uri.h | |
parent | 76a789b0ca2845f1fa529093edfe62871686060e (diff) | |
download | uritools-75fa9480f82b0fab52c00c35e1641da265041dfa.tar.gz uritools-75fa9480f82b0fab52c00c35e1641da265041dfa.zip |
wrote linefromuri to join a uri struct back into a string for urijoin tool
Diffstat (limited to 'uri.h')
-rw-r--r-- | uri.h | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -120,6 +120,56 @@ unsigned int uricmp(struct uri *a,struct uri *b) { return ret; } +char *linefromuri(struct uri *u) { + char *line=malloc(2048);//fuck if I know + strcpy(line,""); + if(u->scheme) { + strcat(line,u->scheme); + } + if(u->scheme && u->domain) { + strcat(line,"://"); + } + if(u->scheme && !u->domain) { + strcat(line,":"); + } + if(u->username && u->domain) { + strcat(line,u->username); + } + if(u->password && u->username && u->domain) {//we /should/ only have a password if there's a username AND domain + strcat(line,":"); + strcat(line,u->password); + } + if(u->username && u->domain) { + strcat(line,"@"); + } + if(u->domain) { + strcat(line,u->domain); + } + if(u->port && u->domain) { //port only makes sense if there's a domain + strcat(line,":"); + strcat(line,u->port); + } + if(u->path && u->scheme && !u->domain) { + strcat(line,u->path); + } + if(u->path && u->scheme && u->domain) { + if(*u->path != '/') { + strcat(line,"/"); + } + strcat(line,u->path); + //path must start with / if we have domain. + } + if(u->query_string) { + strcat(line,"?"); + strcat(line,u->query_string); + } + if(u->fragment_id) { + strcat(line,"#"); + strcat(line,u->fragment_id); + } + return line; +} + /* schemes are case sensitive but cononicals are lower case. domain is case insensitive. return it lowercased? |