~ft/zuke

283868a78a5ecaadebd697505034e9094322621b — Sigrid Haflínudóttir a month ago 3aea722
icy: make sure we have bytes to parse in the first place
1 files changed, 15 insertions(+), 14 deletions(-)

M icy.c
M icy.c => icy.c +15 -14
@@ 18,23 18,24 @@ icyfill(Meta *m)
		return -1;
	fprint(f, "GET /%s HTTP/0.9\r\nIcy-MetaData: 1\r\n\r\n", e ? e : "");
	s0 = malloc(4096);
	n = readn(f, s0, 4095);
	s0[n] = 0;
	for(s = s0; s = strchr(s, '\n');){
		s++;
		if(strncmp(s, "icy-name:", 9) == 0 && (e = strchr(s, '\r')) != nil){
			*e = 0;
			m->artist[0] = strdup(s+9);
			m->numartist = 1;
			s = e+1;
		}else if(strncmp(s, "icy-url:", 8) == 0 && (e = strchr(s, '\r')) != nil){
			*e = 0;
			m->title = strdup(s+8);
			s = e+1;
	if((n = readn(f, s0, 4095)) > 0){
		s0[n] = 0;
		for(s = s0; s = strchr(s, '\n');){
			s++;
			if(strncmp(s, "icy-name:", 9) == 0 && (e = strchr(s, '\r')) != nil){
				*e = 0;
				m->artist[0] = strdup(s+9);
				m->numartist = 1;
				s = e+1;
			}else if(strncmp(s, "icy-url:", 8) == 0 && (e = strchr(s, '\r')) != nil){
				*e = 0;
				m->title = strdup(s+8);
				s = e+1;
			}
		}
	}
	free(s0);
	close(f);

	return 0;
	return n > 0 ? 0 : -1;
}