From cf96b590cf27a4b58fc744a983839b31efc445ca Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 22 Apr 2019 23:34:14 -0500 Subject: rewrote urijoin.c --- urijoin.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 urijoin.c (limited to 'urijoin.c') diff --git a/urijoin.c b/urijoin.c new file mode 100644 index 0000000..569f575 --- /dev/null +++ b/urijoin.c @@ -0,0 +1,36 @@ +#define _XOPEN_SOURCE 500 +#include +#include +#include "uri.h" + +int main(int argc,char *argv[]) { + struct uri *u=malloc(sizeof(struct uri)); + int i; + char key[1024];//fuck if I know + char *value; + memset(u,0,sizeof(struct uri)); + char *parts[]={"scheme:","username:","password:","domain:","port:","path:","query_string:","fragment_id:"}; + while(fgets(key,sizeof(key),stdin)) { + if(strchr(key,'\n')) *strchr(key,'\n')=0; + if((value=strchr(key,' '))) { + *value=0; + value++; +// fprintf(stderr,"read: %s %s\n",key,value); + for(i=0;i<8;i++) { + if(!strcmp(key,parts[i])) { + if(u->A[i]) free(u->A[i]); + u->A[i]=strdup(value); + break; + } + } + if(i==8) { + fprintf(stderr,"urijoin: unknown uri portion: '%s'\n",key); + //return 1;//bail early instead of pretending it makes sense. + } + } else { + fprintf(stderr,"urijoin: malformed line. missing a space: '%s'\n",key); + } + } + printf("%s\n",linefromuri(u)); + return 0; +} -- cgit v1.2.3