diff options
author | epochqwert <epoch@hacking.allowed.org> | 2015-11-11 19:22:31 -0600 |
---|---|---|
committer | epochqwert <epoch@hacking.allowed.org> | 2015-11-11 19:22:31 -0600 |
commit | 4f05827c8b10d07cd9bc04424922a4dba4f728ab (patch) | |
tree | f12bc6c4b513082c2b86b9e585ed0d9f9e306e14 | |
parent | 5dfc7b3d38d4ce0061ffb8166e640498ffdb46e3 (diff) | |
download | uritools-4f05827c8b10d07cd9bc04424922a4dba4f728ab.tar.gz uritools-4f05827c8b10d07cd9bc04424922a4dba4f728ab.zip |
added D flag to matchurl and added an ifdef to cuturl
-rw-r--r-- | cuturl.c | 2 | ||||
-rw-r--r-- | matchurl.c | 13 | ||||
-rw-r--r-- | url.c | 2 |
3 files changed, 13 insertions, 4 deletions
@@ -123,6 +123,7 @@ 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... +#ifdef MAGIC 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")); @@ -133,6 +134,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__"))) { setenv("CUTURL__SCHEME",u.scheme,1); @@ -11,7 +11,11 @@ int main(int argc,char *argv[]) { char *line=malloc(LINE_LENGTH); char copy[LINE_LENGTH]; if(argc < 3) { - printf("usage: matchurl [s|u|k|d|P|p|q|f] [string]\n"); + printf("usage: matchurl [-][s|u|k|d|D|P|p|q|f] [string]\n"); + printf("scheme://username:password@domain:port/path?query_string#fragment_id\n"); + printf("s://u:k@d:P/p?q#f\n"); + printf("The D flag is special. it matches its argument against the last bytes of the input url's domain.\n"); + printf("This allows matching of subdomains, like `echo epoch.ano | matchurl -D ano` would match.\n"); return 1; } while(fgets(line,LINE_LENGTH-1,stdin)) { @@ -21,21 +25,26 @@ int main(int argc,char *argv[]) { urlfromline(&u,line); //use the character in argv[1] to match stdin against argv[2]. if match print whole line. 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); case 'u': if(u.username && !strcmp(u.username,argv[i+1])) printf("%s\n",copy); case 'k': if(u.password && !strcmp(u.password,argv[i+1])) printf("%s\n",copy); case 'd': if(u.domain && !strcmp(u.domain,argv[i+1])) printf("%s\n",copy); + 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); case 'P': if(u.port && !strcmp(u.port,argv[i+1])) printf("%s\n",copy); case 'p': if(u.path && !strcmp(u.path,argv[i+1])) printf("%s\n",copy); case 'q': if(u.query_string && !strcmp(u.query_string,argv[i+1])) printf("%s\n",copy); case 'f': if(u.fragment_id && !strcmp(u.fragment_id,argv[i+1])) printf("%s\n",copy); break; default: - printf("unknown url part letter! %c\n",argv[i][0]); + printf("unknown url part letter! '%c'\n",argv[i][0]); return 0; } } } return 0; } + @@ -1,6 +1,4 @@ -//#include <stdio.h> #include <string.h> -//#include <stdlib.h> /* schemes are case sensitive but cononicals are lower case. |