ref: 3f33d868feb54cc5baa6c2b620f9dcfb6fe65c15
parent: 710b3ec0b624a032f18cd643ab2c65eb8469374c
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Oct 17 10:29:41 EDT 2024
audio/zuke: icy: use http 1.1, specify host, follow redirects
--- a/sys/src/cmd/audio/zuke/icy.c
+++ b/sys/src/cmd/audio/zuke/icy.c
@@ -73,11 +73,13 @@
icyget(Meta *m, int outfd, Channel **newtitle)
{
char *s, *e, *p, *path, *d;
- int f, r, n;
+ int f, r, n, loc;
Icyaux *aux;
Biobuf *b;
+ loc = 0;
path = strdup(m->path);
+nextloc:
s = strchr(path, ':')+3;
if((e = strchr(s, '/')) != nil)
*e++ = 0;
@@ -84,14 +86,16 @@
if((p = strchr(s, ':')) != nil)
*p = '!';
p = smprint("tcp!%s", s);
- free(path);
f = -1;
if((d = netmkaddr(p, "tcp", "80")) != nil)
f = dial(d, nil, nil, nil);
free(p);
- if(f < 0)
+ if(f < 0){
+ free(path);
return -1;
- fprint(f, "GET /%s HTTP/0.9\r\nIcy-MetaData: 1\r\n\r\n", e ? e : "");
+ }
+ fprint(f, "GET /%s HTTP/1.1\r\nHost: %s\r\nIcy-MetaData: 1\r\n\r\n", e ? e : "", s);
+ free(path);
b = Bfdopen(f, OREAD);
aux = mallocz(sizeof(*aux), 1);
aux->outfd = outfd;
@@ -106,7 +110,17 @@
break;
}
s[n-2] = 0;
- if(strncmp(s, "icy-name:", 9) == 0){
+ if(strncmp(s, "Location: ", 10) == 0){
+ if(++loc >= 10){
+ werrstr("too many links to follow");
+ r = -1;
+ break;
+ }
+ Bterm(b);
+ chanclose(aux->newtitle);
+ path = strdup(s+10);
+ goto nextloc;
+ }else if(strncmp(s, "icy-name:", 9) == 0){
s += 9;
if(newtitle != nil)
sendp(aux->newtitle, strdup(s));
@@ -123,6 +137,7 @@
if(r < 0 || outfd < 0){
Bterm(b);
b = nil;
+ chanclose(aux->newtitle);
free(aux);
}
if(b != nil){