summaryrefslogtreecommitdiff
path: root/url.c
diff options
context:
space:
mode:
authorepochqwert <epoch@hacking.allowed.org>2016-05-28 09:40:08 +0000
committerepochqwert <epoch@hacking.allowed.org>2016-05-28 09:40:08 +0000
commit6bfda18041dffeac373ad799b22b0aceaaf6039d (patch)
tree118dfbec6ea6187c3e07d7e154ac0e2f16022696 /url.c
parent88579ab91621abc3a9a6f31c132de50510aca777 (diff)
downloaduritools-6bfda18041dffeac373ad799b22b0aceaaf6039d.tar.gz
uritools-6bfda18041dffeac373ad799b22b0aceaaf6039d.zip
fuck if I know. I'm tired. moved the magic stuff to url.c.
Diffstat (limited to 'url.c')
-rw-r--r--url.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/url.c b/url.c
index ecb9e5d..0c918bc 100644
--- a/url.c
+++ b/url.c
@@ -1,3 +1,4 @@
+#include <netdb.h>
#include <string.h>
/*
@@ -127,3 +128,20 @@ void urlfromline(struct url *u,char *line) {
u->password=0;
}
}
+
+#define AorB(a,b) ((a)?(a):(b))
+
+void magic_and_defaults(struct url *u) {
+ struct servent *serv;
+ char sport[10];
+ u->scheme=AorB(u->scheme,AorB(getenv("URL_SCHEME"),"DEFAULT"));
+ u->username=AorB(u->username,AorB(getenv("URL_USERNAME"),"DEFAULT"));
+ u->password=AorB(u->password,AorB(getenv("URL_PASSWORD"),"DEFAULT"));
+ u->domain=AorB(u->domain,AorB(getenv("URL_DOMAIN"),"DEFAULT"));
+ 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));
+ u->port=AorB(u->port,AorB(getenv("URL_PORT"),(serv?sport:"DEFAULT")));
+ u->path=AorB(u->path,AorB(getenv("URL_PATH"),"DEFAULT"));
+ u->query_string=AorB(u->query_string,AorB(getenv("URL_QUERY_STRING"),"DEFAULT"));
+ u->fragment_id=AorB(u->fragment_id,AorB(getenv("URL_FRAGMENT_ID"),"DEFAULT"));
+}