summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/cuturl.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/bin/cuturl.c b/src/bin/cuturl.c
index f8b02c7..d706fd3 100644
--- a/src/bin/cuturl.c
+++ b/src/bin/cuturl.c
@@ -175,17 +175,25 @@ int main(int argc,char *argv[]) {
}
if(domain) {
- if(strchr(domain,']')) {
+ if(strchr(domain,']')) {//the end of an IPv6 address
if(strchr(strchr(domain,']'),':')) {
port=strchr(strchr(domain,']'),':');
- *port=0;
- port++;
+ if(port[1] == '?') {//for magnet links
+ port=0;
+ } else {
+ *port=0;
+ port++;
+ }
}
} else {
if(strchr(domain,':')) {
port=strchr(domain,':');
- *port=0;
- port++;
+ if(port[1] == '?') {//for magnet links
+ port=0;
+ } else {
+ *port=0;
+ port++;
+ }
}
}
}
@@ -198,23 +206,31 @@ int main(int argc,char *argv[]) {
}
}
- if(!scheme && username) {
+ if(strchr(domain,':') && !strchr(domain,']')) {//for scheme:?query_string
+ scheme=domain;
+ *strchr(scheme,':')=0;
+ domain=0;
+ }
+
+ if(!scheme && username) {//for mailto:
scheme=username;
username=password;
password=0;
}
- if(!domain) {
- fprintf(stderr,"how the fuck is this supposed to be a URL?\n");
- return 1;
- }
+// before deciding to also handle magnets
+// if(!domain) {
+// fprintf(stderr,"how the fuck is this supposed to be a URL?\n");
+// return 1;
+// }
+
// 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,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.
+ domain=AorB(domain,AorB(getenv("CURURL_DOMAIN"),"DEFAULT"));
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")));