Mercurial > audlegacy-plugins
comparison src/neon/neon.c @ 1742:4f4634573e41
- Free memory for ICY tags
- Add content-type parsing for metadata
author | Ralf Ertzinger <ralf@skytale.net> |
---|---|
date | Wed, 19 Sep 2007 14:36:37 +0200 |
parents | f86ddc8e543b |
children | d2e3eef90719 |
comparison
equal
deleted
inserted
replaced
1741:f86ddc8e543b | 1742:4f4634573e41 |
---|---|
66 h->icy_metaint = 0; | 66 h->icy_metaint = 0; |
67 h->icy_metaleft = 0; | 67 h->icy_metaleft = 0; |
68 h->icy_metadata.stream_name = NULL; | 68 h->icy_metadata.stream_name = NULL; |
69 h->icy_metadata.stream_title = NULL; | 69 h->icy_metadata.stream_title = NULL; |
70 h->icy_metadata.stream_url = NULL; | 70 h->icy_metadata.stream_url = NULL; |
71 h->icy_metadata.stream_contenttype = NULL; | |
71 h->reader = NULL; | 72 h->reader = NULL; |
72 h->reader_status.mutex = g_mutex_new(); | 73 h->reader_status.mutex = g_mutex_new(); |
73 h->reader_status.cond = g_cond_new(); | 74 h->reader_status.cond = g_cond_new(); |
74 h->reader_status.reading = FALSE; | 75 h->reader_status.reading = FALSE; |
75 h->reader_status.status = NEON_READER_INIT; | 76 h->reader_status.status = NEON_READER_INIT; |
86 | 87 |
87 _ENTER; | 88 _ENTER; |
88 | 89 |
89 ne_uri_free(h->purl); | 90 ne_uri_free(h->purl); |
90 destroy_rb(&h->rb); | 91 destroy_rb(&h->rb); |
92 if (NULL != h->icy_metadata.stream_name) { | |
93 free(h->icy_metadata.stream_name); | |
94 } | |
95 if (NULL != h->icy_metadata.stream_title) { | |
96 free(h->icy_metadata.stream_title); | |
97 } | |
98 if (NULL != h->icy_metadata.stream_url) { | |
99 free(h->icy_metadata.stream_url); | |
100 } | |
101 if (NULL != h->icy_metadata.stream_contenttype) { | |
102 free(h->icy_metadata.stream_contenttype); | |
103 } | |
91 free(h); | 104 free(h); |
92 | 105 |
93 _LEAVE; | 106 _LEAVE; |
94 } | 107 } |
95 | 108 |
159 | 172 |
160 /* | 173 /* |
161 * ----- | 174 * ----- |
162 */ | 175 */ |
163 | 176 |
164 #define TAGSIZE 4096 | |
165 | |
166 static void parse_icy(struct icy_metadata* m, gchar* metadata, int len) { | 177 static void parse_icy(struct icy_metadata* m, gchar* metadata, int len) { |
167 | 178 |
168 gchar* p; | 179 gchar* p; |
169 gchar* tstart; | 180 gchar* tstart; |
170 gchar* tend; | 181 gchar* tend; |
171 gchar name[TAGSIZE]; | 182 gchar name[4096]; |
172 gchar value[TAGSIZE]; | 183 gchar value[4096]; |
173 int state; | 184 int state; |
174 int pos; | 185 int pos; |
175 | 186 |
176 _ENTER; | 187 _ENTER; |
177 | 188 |
191 if ('=' == *p) { | 202 if ('=' == *p) { |
192 /* | 203 /* |
193 * End of tag name. | 204 * End of tag name. |
194 */ | 205 */ |
195 *p = '\0'; | 206 *p = '\0'; |
196 g_strlcpy(name, tstart, TAGSIZE); | 207 strcpy(name, tstart); |
197 _DEBUG("Found tag name: %s", name); | 208 _DEBUG("Found tag name: %s", name); |
198 state = 2; | 209 state = 2; |
199 } else { | 210 } else { |
200 tend = p; | 211 tend = p; |
201 }; | 212 }; |
220 if ('\'' == *p) { | 231 if ('\'' == *p) { |
221 /* | 232 /* |
222 * End of value | 233 * End of value |
223 */ | 234 */ |
224 *p = '\0'; | 235 *p = '\0'; |
225 g_strlcpy(value, tstart, TAGSIZE); | 236 strcpy(value, tstart); |
226 _DEBUG("Found tag value: %s", value); | 237 _DEBUG("Found tag value: %s", value); |
227 add_icy(m, name, value); | 238 add_icy(m, name, value); |
228 state = 4; | 239 state = 4; |
229 } else { | 240 } else { |
230 tend = p; | 241 tend = p; |
339 */ | 350 */ |
340 if (NULL != g_strrstr(value, "bytes")) { | 351 if (NULL != g_strrstr(value, "bytes")) { |
341 _DEBUG("server can_ranges"); | 352 _DEBUG("server can_ranges"); |
342 h->can_ranges = TRUE; | 353 h->can_ranges = TRUE; |
343 } | 354 } |
355 | |
356 continue; | |
344 } | 357 } |
345 | 358 |
346 if (0 == g_ascii_strncasecmp("content-length", name, 14)) { | 359 if (0 == g_ascii_strncasecmp("content-length", name, 14)) { |
347 /* | 360 /* |
348 * The server sent us the content length. Parse and store. | 361 * The server sent us the content length. Parse and store. |
355 _DEBUG("Content length as advertised by server: %ld", len); | 368 _DEBUG("Content length as advertised by server: %ld", len); |
356 h->content_length = len; | 369 h->content_length = len; |
357 } else { | 370 } else { |
358 _ERROR("Invalid content length header: %s", value); | 371 _ERROR("Invalid content length header: %s", value); |
359 } | 372 } |
373 | |
374 continue; | |
375 } | |
376 | |
377 if (0 == g_ascii_strncasecmp("content-type", name, 12)) { | |
378 /* | |
379 * The server sent us a content type. Save it for later | |
380 */ | |
381 _DEBUG("Content-Type: %s", value); | |
382 if (NULL != h->icy_metadata.stream_contenttype) { | |
383 free(h->icy_metadata.stream_contenttype); | |
384 } | |
385 h->icy_metadata.stream_contenttype = g_strdup(value); | |
386 | |
387 continue; | |
360 } | 388 } |
361 | 389 |
362 if (0 == g_ascii_strncasecmp("icy-metaint", name, 11)) { | 390 if (0 == g_ascii_strncasecmp("icy-metaint", name, 11)) { |
363 /* | 391 /* |
364 * The server sent us a ICY metaint header. Parse and store. | 392 * The server sent us a ICY metaint header. Parse and store. |
372 h->icy_metaint = len; | 400 h->icy_metaint = len; |
373 h->icy_metaleft = len; | 401 h->icy_metaleft = len; |
374 } else { | 402 } else { |
375 _ERROR("Invalid ICY MetaInt header: %s", value); | 403 _ERROR("Invalid ICY MetaInt header: %s", value); |
376 } | 404 } |
405 | |
406 continue; | |
377 } | 407 } |
378 | 408 |
379 if (0 == g_ascii_strncasecmp("icy-name", name, 8)) { | 409 if (0 == g_ascii_strncasecmp("icy-name", name, 8)) { |
380 /* | 410 /* |
381 * The server sent us a ICY name. Save it for later | 411 * The server sent us a ICY name. Save it for later |
384 if (NULL != h->icy_metadata.stream_name) { | 414 if (NULL != h->icy_metadata.stream_name) { |
385 free(h->icy_metadata.stream_name); | 415 free(h->icy_metadata.stream_name); |
386 } | 416 } |
387 h->icy_metadata.stream_name = g_strdup(value); | 417 h->icy_metadata.stream_name = g_strdup(value); |
388 } | 418 } |
419 | |
420 continue; | |
389 } | 421 } |
390 | 422 |
391 _LEAVE; | 423 _LEAVE; |
392 } | 424 } |
393 | 425 |
1143 | 1175 |
1144 if (0 == g_ascii_strncasecmp(field, "stream-name", 11)) { | 1176 if (0 == g_ascii_strncasecmp(field, "stream-name", 11)) { |
1145 _LEAVE g_strdup(h->icy_metadata.stream_name); | 1177 _LEAVE g_strdup(h->icy_metadata.stream_name); |
1146 } | 1178 } |
1147 | 1179 |
1180 if (0 == g_ascii_strncasecmp(field, "content-type", 12)) { | |
1181 _LEAVE g_strdup(h->icy_metadata.stream_contenttype); | |
1182 } | |
1183 | |
1148 _LEAVE NULL; | 1184 _LEAVE NULL; |
1149 } | 1185 } |
1150 | 1186 |
1151 /* | 1187 /* |
1152 * ----- | 1188 * ----- |