From 3c2d290d17b739f14774dfcdf48581c1fb212286 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Fri, 6 Feb 2015 02:32:04 -0600 Subject: some new tools. clump is useful. httpd got some better logging. cuturl got some bugfixes I think. todo is just a version of segfault's !todo but for shell. don't remember what I did to telnet-gateway.sh --- src/bin/cuturl.c | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'src/bin/cuturl.c') diff --git a/src/bin/cuturl.c b/src/bin/cuturl.c index 4a2f3f5..f8b02c7 100644 --- a/src/bin/cuturl.c +++ b/src/bin/cuturl.c @@ -1,4 +1,4 @@ - +#include #include #include #include @@ -33,14 +33,6 @@ #define AorB(a,b) ((a)?(a):(b)) -#define DEFAULT_SCHEME AorB(getenv("CUTURL_SCHEME"),"DEFAULT") -#define DEFAULT_USERNAME AorB(getenv("CUTURL_USERNAME"),"DEFAULT") -#define DEFAULT_PASSWORD AorB(getenv("CUTURL_PASSWORD"),"DEFAULT") -#define DEFAULT_PORT AorB(getenv("CUTURL_PORT"),"DEFAULT") -#define DEFAULT_PATH AorB(getenv("CUTURL_PATH"),"DEFAULT") -#define DEFAULT_QUERY_STRING AorB(getenv("CUTURL_QUERY_STRING"),"DEFAULT") -#define DEFAULT_FRAGMENT_ID AorB(getenv("CUTURL_FRAGMENT_ID"),"DEFAULT") - #define F_SCHEME 1<<0 #define F_USERNAME 1<<1 #define F_PASSWORD 1<<2 @@ -63,13 +55,15 @@ int main(int argc,char *argv[]) { char *path=0; char *query_string=0; char *fragment_id=0; + char sport[10]; + struct servent *serv; //exactly 8 parts! let's store that in a byte. unsigned char flags=0; int i; int size=1024; char using_stdin=1; char malloced=0; - if(argc > 0) { + if(argc > 1) { if(!strcmp(argv[1],"--help") || !strcmp(argv[1],"-h")) { printf("usage: echo urls | cuturl [options]\n"); printf("usage: cuturl [options] url [options] [url]\n\n"); @@ -82,11 +76,16 @@ int main(int argc,char *argv[]) { } } while(1) { - // - // todo: add argument parsing - // + scheme=0; + username=0; + password=0; + domain=0; + port=0; + path=0; + query_string=0; + fragment_id=0; if(!using_stdin) flags=0; - if(argc > 0) { + if(argc > 1) { for(argc--,argv++;argc>0;argc--,argv++) { for(i=0;long_opts[i];i++) { if(!strncmp(*argv,"--",2)) { @@ -111,7 +110,7 @@ int main(int argc,char *argv[]) { } } if(using_stdin) { - line=malloc(size); + line=malloc(size+1); malloced=1; if(!fgets(line,size,stdin)) { return 0; @@ -133,7 +132,6 @@ int main(int argc,char *argv[]) { break; } } - if(path) { if(strchr(path,'?')) { query_string=strchr(path,'?'); @@ -213,14 +211,19 @@ int main(int argc,char *argv[]) { // printf("scheme://username:password@domain:port/path?query_string#fragment_id\n\n"); //let's set them to what'll get printed now... - scheme=AorB(scheme,DEFAULT_SCHEME); - username=AorB(username,DEFAULT_USERNAME); - password=AorB(password,DEFAULT_PASSWORD); + scheme=AorB(scheme,AorB(getenv("CUTURL_SCHEME"),"DEFAULT")); + username=AorB(username,AorB(getenv("CUTURL_USERNAME"),"DEFAULT")); + password=AorB(password,AorB(getenv("CUTURL_PASSWORD"),"DEFAULT")); //domain=domain; doesn't change. heh. - port=AorB(port,DEFAULT_PORT); - path=AorB(path,DEFAULT_PATH); - query_string=AorB(query_string,DEFAULT_QUERY_STRING); - fragment_id=AorB(fragment_id,DEFAULT_FRAGMENT_ID); + serv=getservbyname(scheme,strcmp(scheme,"udp")?"tcp":"udp"); + if(serv) snprintf(sport,sizeof(sport)-1,"%d",ntohs(serv->s_port)); + port=AorB(port,AorB(getenv("CUTURL_PORT"),(serv?sport:"DEFAULT"))); + //port=AorB(port,AorB(getenv("CUTURL_PORT"),"DEFAULT")); + + + path=AorB(path,AorB(getenv("CUTURL_PATH"),"DEFAULT")); + query_string=AorB(query_string,AorB(getenv("CUTURL_QUERY_STRING"),"DEFAULT")); + fragment_id=AorB(fragment_id,AorB(getenv("CUTURL_FRAGMENT_ID"),"DEFAULT")); if(flags) { if(flags&F_SCHEME) printf("%s\n",scheme); -- cgit v1.2.3