summaryrefslogtreecommitdiff
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
parent88579ab91621abc3a9a6f31c132de50510aca777 (diff)
downloaduritools-6bfda18041dffeac373ad799b22b0aceaaf6039d.tar.gz
uritools-6bfda18041dffeac373ad799b22b0aceaaf6039d.zip
fuck if I know. I'm tired. moved the magic stuff to url.c.
-rw-r--r--Makefile2
-rw-r--r--cuturl.c5
-rw-r--r--matchurl.c22
-rw-r--r--url.c18
-rw-r--r--url.h4
5 files changed, 37 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 8c8e858..c652062 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,6 @@ clean:
rm -f matchurl
rm -f cuturl
-install:
+install: all
cp -f matchurl $(PREFIX)/bin/matchurl
cp -f cuturl $(PREFIX)/bin/cuturl
diff --git a/cuturl.c b/cuturl.c
index b2e7f84..1fd20b2 100644
--- a/cuturl.c
+++ b/cuturl.c
@@ -39,9 +39,7 @@ char *short_opts[]={"s","u","k","d","P","p","q","f"};
int main(int argc,char *argv[]) {
char *name[2];
char *line=0;
- char sport[10];
char args[256];
- struct servent *serv;
int i,j,c=0;
int size=1024;
int status;
@@ -126,6 +124,8 @@ int main(int argc,char *argv[]) {
//let's set them to what'll get printed now...
#ifdef MAGIC
+ magic_and_defaults(&u);
+/*
u.scheme=AorB(u.scheme,AorB(getenv("CUTURL_SCHEME"),"DEFAULT"));
u.username=AorB(u.username,AorB(getenv("CUTURL_USERNAME"),"DEFAULT"));
u.password=AorB(u.password,AorB(getenv("CUTURL_PASSWORD"),"DEFAULT"));
@@ -136,6 +136,7 @@ int main(int argc,char *argv[]) {
u.path=AorB(u.path,AorB(getenv("CUTURL_PATH"),"DEFAULT"));
u.query_string=AorB(u.query_string,AorB(getenv("CUTURL_QUERY_STRING"),"DEFAULT"));
u.fragment_id=AorB(u.fragment_id,AorB(getenv("CUTURL_FRAGMENT_ID"),"DEFAULT"));
+*/
#endif
if((name[0]=getenv("CUTURL__"))) {
diff --git a/matchurl.c b/matchurl.c
index 396f829..9be390f 100644
--- a/matchurl.c
+++ b/matchurl.c
@@ -7,6 +7,7 @@
int main(int argc,char *argv[]) {
int i;
+ int ret=1;
struct url u;
char *line=malloc(LINE_LENGTH);
char copy[LINE_LENGTH];
@@ -28,24 +29,25 @@ int main(int argc,char *argv[]) {
for(i=1;i<argc;i+=2) {
if(argv[i][0] == '-') argv[i]++;
switch(argv[i][0]) {
- case 's': if(u.scheme && !strcmp(u.scheme,argv[i+1])) printf("%s\n",copy); break;
- case 'u': if(u.username && !strcmp(u.username,argv[i+1])) printf("%s\n",copy); break;
- case 'k': if(u.password && !strcmp(u.password,argv[i+1])) printf("%s\n",copy); break;
- case 'd': if(u.domain && !strcmp(u.domain,argv[i+1])) printf("%s\n",copy); break;
- case 'P': if(u.port && !strcmp(u.port,argv[i+1])) printf("%s\n",copy); break;
- case 'p': if(u.path && !strcmp(u.path,argv[i+1])) printf("%s\n",copy); break;
- case 'q': if(u.query_string && !strcmp(u.query_string,argv[i+1])) printf("%s\n",copy); break;
- case 'f': if(u.fragment_id && !strcmp(u.fragment_id,argv[i+1])) printf("%s\n",copy); break;
+ case 's': if(u.scheme && !strcmp(u.scheme,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
+ case 'u': if(u.username && !strcmp(u.username,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
+ case 'k': if(u.password && !strcmp(u.password,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
+ case 'd': if(u.domain && !strcmp(u.domain,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
+ case 'P': if(u.port && !strcmp(u.port,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
+ case 'p': if(u.path && !strcmp(u.path,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
+ case 'q': if(u.query_string && !strcmp(u.query_string,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
+ case 'f': if(u.fragment_id && !strcmp(u.fragment_id,argv[i+1])) {printf("%s\n",copy); ret=0;} break;
case 'D':
if(u.domain && strlen(u.domain) >= strlen(argv[i+1]) && !strncmp(u.domain+strlen(u.domain)-strlen(argv[i+1]),argv[i+1],strlen(argv[i+1])))
printf("%s\n",copy);
+ ret=0;
break;
default:
printf("unknown url part letter! '%c'\n",argv[i][0]);
- return 0;
+ return ret;
}
}
}
- return 0;
+ return ret;
}
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"));
+}
diff --git a/url.h b/url.h
index 5e9bea8..625f0b1 100644
--- a/url.h
+++ b/url.h
@@ -1,5 +1,6 @@
#ifndef URL_H
#define URL_H
+
struct url {
char *scheme;
char *username;
@@ -11,5 +12,6 @@ struct url {
char *fragment_id;
};
-void urlfromline(struct url *u,char *line);
+void urlfromline(struct url *,char *);
+void magic_and_defaults(struct url *);
#endif