summaryrefslogtreecommitdiff
path: root/urigetline.c
diff options
context:
space:
mode:
authorepoch <epoch@thebackupbox.net>2022-09-05 08:08:05 +0000
committerepoch <epoch@thebackupbox.net>2022-09-05 08:08:05 +0000
commitf14b89fb90175e659e5652da50b5fc4fb4ca47c3 (patch)
tree9b04792327e2ee5dca87d1561dd482da7d6f5c71 /urigetline.c
parentd085cb196811bf3529b403089bf509de17980a57 (diff)
parent994e230b637fa0be9ee2f949737ac1754d985704 (diff)
downloaduritools-f14b89fb90175e659e5652da50b5fc4fb4ca47c3.tar.gz
uritools-f14b89fb90175e659e5652da50b5fc4fb4ca47c3.zip
Merge branch 'master' of ssh://git.thebackupbox.net/uritools
Diffstat (limited to 'urigetline.c')
-rw-r--r--urigetline.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/urigetline.c b/urigetline.c
index 4c5c7b4..4963a84 100644
--- a/urigetline.c
+++ b/urigetline.c
@@ -35,7 +35,7 @@ int match(signed char rule,char *part,char *arg) {
int main(int argc,char *argv[]) {//argument needs to be the URI
int j;
int ret=1;
- struct uri u;
+ struct uri *u = malloc(sizeof(struct uri));
char matches;
signed char rule=MATCH_PATTERN;
char *line=malloc(LINE_LENGTH);
@@ -57,9 +57,10 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
}
if(argc < 2) {
fprintf(stderr,"usage: urigetline [-a] uri < uristart.conf\n");
+ free(u);
return 1;
}
- urifromline(&u,argv[1]);//only argv[1] is a URI?
+ urifromline(u,argv[1]);//only argv[1] is a URI?
for(;fgets(line,LINE_LENGTH-1,stdin);) {//each line comes from the config. we need to split it on spaces.
if(strchr(line,'\r')) *strchr(line,'\r')=0;
if(strchr(line,'\n')) *strchr(line,'\n')=0;
@@ -76,7 +77,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
}
a=line;
matches=1;
- for(;a;) {
+ for(;a && *a;) {
rule=MATCH_PATTERN;
j=0;
switch(a[0]) {
@@ -90,6 +91,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
if(rule != MATCH_UNEXIST) {
if(!(b=strchr(a,' '))) {
fprintf(stderr,"argument '%s' wants a value in the next argument and didn't get it. throwing a fit. (pass -v to urigetline to help debug)\n",a);
+ free(u);
return 2;
}
*b=0; b++;
@@ -102,17 +104,18 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
}
}
switch(a[j]) {
- case 's': if(!match(rule,u.scheme,b)) { matches=0;} break;
- case 'u': if(!match(rule,u.username,b)) { matches=0;} break;
- case 'k': if(!match(rule,u.password,b)) { matches=0;} break;
- case 'd': if(!match(rule,u.domain,b)) { matches=0;} break;
- case 'P': if(!match(rule,u.port,b)) { matches=0;} break;
- case 'p': if(!match(rule,u.path,b)) { matches=0;} break;
- case 'q': if(!match(rule,u.query_string,b)) { matches=0;} break;
- case 'f': if(!match(rule,u.fragment_id,b)) { matches=0;} break;
+ case 's': if(!match(rule,u->scheme,b)) { matches=0;} break;
+ case 'u': if(!match(rule,u->username,b)) { matches=0;} break;
+ case 'k': if(!match(rule,u->password,b)) { matches=0;} break;
+ case 'd': if(!match(rule,u->domain,b)) { matches=0;} break;
+ case 'P': if(!match(rule,u->port,b)) { matches=0;} break;
+ case 'p': if(!match(rule,u->path,b)) { matches=0;} break;
+ case 'q': if(!match(rule,u->query_string,b)) { matches=0;} break;
+ case 'f': if(!match(rule,u->fragment_id,b)) { matches=0;} break;
break;
default:
fprintf(stderr,"unknown url part letter! %s\n",a);
+ free(u);
return 3;
}
//if(b) printf("two: %s %s\n",a,b);
@@ -122,8 +125,12 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
if(matches) {
//printf("comm: %s\n",command);
printf("%s\n",command);
- if(!all) return ret;//bail early if we only need first match
+ if(!all) {
+ free(u);
+ return ret;//bail early if we only need first match
+ }
}
}
+ free(u);
return ret;
}