summaryrefslogtreecommitdiff
path: root/urigetline.c
diff options
context:
space:
mode:
authorepoch <epoch@thebackupbox.net>2022-09-02 01:30:50 -0500
committerepoch <epoch@thebackupbox.net>2022-09-02 01:30:50 -0500
commit994e230b637fa0be9ee2f949737ac1754d985704 (patch)
tree7c17b267eca6177797a61c42c92bdb849a1a661e /urigetline.c
parent03762afa63c63f21c3e035aced349fb87d0352fb (diff)
downloaduritools-994e230b637fa0be9ee2f949737ac1754d985704.tar.gz
uritools-994e230b637fa0be9ee2f949737ac1754d985704.zip
urigetline now uses malloc()d space for its struct uri
Diffstat (limited to 'urigetline.c')
-rw-r--r--urigetline.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/urigetline.c b/urigetline.c
index 71d2149..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;
@@ -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;
}