summaryrefslogtreecommitdiff
path: root/matchurl.c
diff options
context:
space:
mode:
authorepochqwert <epoch@hacking.allowed.org>2015-08-22 03:36:15 -0500
committerepochqwert <epoch@hacking.allowed.org>2015-08-22 03:36:15 -0500
commitb7849c483393cf510cbe4bca137ce4520b636685 (patch)
tree28e6410126fac350d69c9f47a7588f7dfd639841 /matchurl.c
downloaduritools-b7849c483393cf510cbe4bca137ce4520b636685.tar.gz
uritools-b7849c483393cf510cbe4bca137ce4520b636685.zip
initial commit.
Diffstat (limited to 'matchurl.c')
-rw-r--r--matchurl.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/matchurl.c b/matchurl.c
new file mode 100644
index 0000000..aeb4aa4
--- /dev/null
+++ b/matchurl.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "url.h"
+
+#define LINE_LENGTH 1024
+
+int main(int argc,char *argv[]) {
+ int i;
+ struct url u;
+ 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");
+ return 1;
+ }
+ while(fgets(line,LINE_LENGTH-1,stdin)) {
+ if(strchr(line,'\r')) *strchr(line,'\r')=0;
+ if(strchr(line,'\n')) *strchr(line,'\n')=0;
+ strcpy(copy,line);
+ 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) {
+ 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 '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]);
+ return 0;
+ }
+ }
+ }
+ return 0;
+}